NextcloudWidgetView.swift 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // NextcloudWidgetView.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 NextcloudWidgetView: View {
  26. var entry: NextcloudDataEntry
  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 = 45
  75. let placeholderColor = Color(white: 0.8)
  76. let brandColor = Color(NCBrandColor.shared.brand)
  77. let brandTextColor = Color(NCBrandColor.shared.brandText)
  78. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionUploadAsset, label: {
  79. Image("buttonAddImage")
  80. .resizable()
  81. .renderingMode(.template)
  82. .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
  83. .padding(10)
  84. .background(entry.isPlaceholder ? placeholderColor : brandColor)
  85. .clipShape(Circle())
  86. .scaledToFit()
  87. .frame(width: geo.size.width / 4, height: sizeButton)
  88. })
  89. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionScanDocument, label: {
  90. Image("buttonAddScan")
  91. .resizable()
  92. .renderingMode(.template)
  93. .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
  94. .padding(10)
  95. .background(entry.isPlaceholder ? placeholderColor : brandColor)
  96. .clipShape(Circle())
  97. .scaledToFit()
  98. .frame(width: geo.size.width / 4, height: sizeButton)
  99. })
  100. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionTextDocument, label: {
  101. Image("note.text")
  102. .resizable()
  103. .renderingMode(.template)
  104. .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
  105. .padding(10)
  106. .background(entry.isPlaceholder ? placeholderColor : brandColor)
  107. .clipShape(Circle())
  108. .scaledToFit()
  109. .frame(width: geo.size.width / 4, height: sizeButton)
  110. })
  111. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionVoiceMemo, label: {
  112. Image("microphone")
  113. .resizable()
  114. .renderingMode(.template)
  115. .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
  116. .padding(10)
  117. .background(entry.isPlaceholder ? placeholderColor : brandColor)
  118. .clipShape(Circle())
  119. .scaledToFit()
  120. .frame(width: geo.size.width / 4, height: sizeButton)
  121. })
  122. }
  123. .frame(width: geo.size.width, height: geo.size.height - 25, alignment: .bottomTrailing)
  124. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  125. HStack {
  126. let placeholderColor = Color(white: 0.2)
  127. let brandColor = Color(NCBrandColor.shared.brand)
  128. Image(systemName: entry.footerImage)
  129. .resizable()
  130. .scaledToFit()
  131. .frame(width: 15, height: 15)
  132. .foregroundColor(entry.isPlaceholder ? placeholderColor : brandColor)
  133. Text(entry.footerText)
  134. .font(.caption2)
  135. .padding(.trailing, 13.0)
  136. .foregroundColor(entry.isPlaceholder ? placeholderColor : brandColor)
  137. }
  138. .frame(maxWidth: geo.size.width - 5, maxHeight: geo.size.height - 2, alignment: .bottomTrailing)
  139. }
  140. }
  141. }
  142. }
  143. struct NextcloudWidget_Previews: PreviewProvider {
  144. static var previews: some View {
  145. let datas = Array(recentDatasTest[0...nextcloudItems-1])
  146. let entry = NextcloudDataEntry(date: Date(), datas: datas, isPlaceholder: false, tile: "Good afternoon, Marino Faggiana", footerImage: "checkmark.icloud", footerText: "Nextcloud widget")
  147. NextcloudWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  148. }
  149. }