DashboardWidgetView.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // DashboardWidgetView.swift
  3. // Widget
  4. //
  5. // Created by Marino Faggiana on 20/08/22.
  6. // Copyright © 2022 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import SwiftUI
  24. import WidgetKit
  25. struct DashboardWidgetView: View {
  26. var entry: DashboardDataEntry
  27. var body: some View {
  28. ZStack(alignment: .top) {
  29. VStack {
  30. Text(entry.title)
  31. .font(.title3)
  32. .bold()
  33. .fixedSize(horizontal: false, vertical: true)
  34. VStack(spacing: 5) {
  35. ForEach(entry.datas, id: \.id) { element in
  36. Link(destination: element.url) {
  37. HStack {
  38. Image(uiImage: element.image)
  39. .resizable()
  40. .aspectRatio(contentMode: .fit)
  41. .frame(width: 40, height: 40)
  42. .clipShape(Circle())
  43. VStack(alignment: .leading) {
  44. Text(element.title)
  45. .font(.headline)
  46. Text(element.subTitle)
  47. .font(.subheadline)
  48. .foregroundColor(Color(white: 0.4745))
  49. }
  50. Spacer()
  51. }
  52. .padding(5)
  53. }
  54. }
  55. }
  56. }.padding(5)
  57. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  58. Text(entry.footerText)
  59. .font(.caption2)
  60. .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)
  61. .padding(.trailing, 10.0)
  62. .padding(.bottom, 5.0)
  63. }
  64. }
  65. }
  66. struct DashboardWidget_Previews: PreviewProvider {
  67. static var previews: some View {
  68. let datas = Array(dashboardDatasTest[0...3])
  69. let title = "Dashboard"
  70. let titleImage = UIImage(named: "nextcloud")!
  71. let entry = DashboardDataEntry(date: Date(), datas: datas, isPlaceholder: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: "Nextcloud widget")
  72. DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  73. }
  74. }