FilesWidgetView.swift 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // FilesWidgetView.swift
  3. // Widget
  4. //
  5. // Created by Marino Faggiana on 25/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 FilesWidgetView: View {
  26. var entry: FilesDataEntry
  27. var body: some View {
  28. GeometryReader { geo in
  29. ZStack(alignment: .topLeading) {
  30. HStack() {
  31. Text(entry.tile)
  32. .font(.system(size: 12))
  33. .fontWeight(.bold)
  34. .multilineTextAlignment(.center)
  35. .textCase(.uppercase)
  36. .lineLimit(1)
  37. }
  38. .frame(width: geo.size.width - 20)
  39. .padding([.top, .leading, .trailing], 10)
  40. VStack(alignment: .leading) {
  41. VStack(spacing: 0) {
  42. ForEach(entry.datas, id: \.id) { element in
  43. Link(destination: element.url) {
  44. HStack {
  45. let subTitleColor = Color(white: 0.5)
  46. let imageSize:CGFloat = 35
  47. Image(uiImage: element.image)
  48. .resizable()
  49. .scaledToFill()
  50. .frame(width: imageSize, height: imageSize)
  51. .clipped()
  52. .cornerRadius(5)
  53. VStack(alignment: .leading, spacing: 2) {
  54. Text(element.title)
  55. .font(.system(size: 12))
  56. .fontWeight(.regular)
  57. Text(element.subTitle)
  58. .font(.system(size: CGFloat(10)))
  59. .foregroundColor(subTitleColor)
  60. }
  61. Spacer()
  62. }
  63. .padding(.leading, 10)
  64. .frame(height: 50)
  65. }
  66. Divider()
  67. .padding(.leading, 54)
  68. }
  69. }
  70. }
  71. .padding(.top, 30)
  72. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  73. HStack(spacing: 0) {
  74. let sizeButton: CGFloat = 40
  75. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionUploadAsset, label: {
  76. Image("addImage")
  77. .resizable()
  78. .renderingMode(.template)
  79. .foregroundColor(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brandText))
  80. .padding(11)
  81. .background(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brand))
  82. .clipShape(Circle())
  83. .scaledToFit()
  84. .frame(width: geo.size.width / 4, height: sizeButton)
  85. })
  86. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionScanDocument, label: {
  87. Image("scan")
  88. .resizable()
  89. .renderingMode(.template)
  90. .foregroundColor(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brandText))
  91. .padding(11)
  92. .background(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brand))
  93. .clipShape(Circle())
  94. .scaledToFit()
  95. .frame(width: geo.size.width / 4, height: sizeButton)
  96. })
  97. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionTextDocument, label: {
  98. Image("note.text")
  99. .resizable()
  100. .renderingMode(.template)
  101. .foregroundColor(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brandText))
  102. .padding(11)
  103. .background(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brand))
  104. .clipShape(Circle())
  105. .scaledToFit()
  106. .frame(width: geo.size.width / 4, height: sizeButton)
  107. })
  108. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionVoiceMemo, label: {
  109. Image("microphone")
  110. .resizable()
  111. .renderingMode(.template)
  112. .foregroundColor(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brandText))
  113. .padding(11)
  114. .background(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brand))
  115. .clipShape(Circle())
  116. .scaledToFit()
  117. .frame(width: geo.size.width / 4, height: sizeButton)
  118. })
  119. }
  120. .frame(width: geo.size.width, height: geo.size.height - 25, alignment: .bottomTrailing)
  121. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  122. HStack {
  123. Image(systemName: entry.footerImage)
  124. .resizable()
  125. .scaledToFit()
  126. .frame(width: 15, height: 15)
  127. .foregroundColor(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brand))
  128. Text(entry.footerText)
  129. .font(.caption2)
  130. .padding(.trailing, 13.0)
  131. .foregroundColor(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brand))
  132. }
  133. .frame(maxWidth: geo.size.width - 5, maxHeight: geo.size.height - 2, alignment: .bottomTrailing)
  134. }
  135. }
  136. }
  137. }
  138. struct FilesWidget_Previews: PreviewProvider {
  139. static var previews: some View {
  140. let datas = Array(filesDatasTest[0...4])
  141. let entry = FilesDataEntry(date: Date(), datas: datas, isPlaceholder: false, tile: "Good afternoon, Marino Faggiana", footerImage: "checkmark.icloud", footerText: "Nextcloud files")
  142. FilesWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  143. }
  144. }