NextcloudWidgetView.swift 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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(spacing: 5) {
  31. Text(NCBrandOptions.shared.brand)
  32. .font(.system(size: 13))
  33. .fontWeight(.bold)
  34. .textCase(.uppercase)
  35. }
  36. .padding(.leading, 10)
  37. .padding(.top, 10)
  38. VStack(alignment: .leading) {
  39. VStack(spacing: 0) {
  40. ForEach(entry.recentDatas, id: \.id) { element in
  41. Link(destination: element.url) {
  42. HStack {
  43. Image(uiImage: element.image)
  44. .resizable()
  45. .scaledToFill()
  46. .frame(width: imageSize, height: imageSize)
  47. .clipped()
  48. .cornerRadius(4)
  49. VStack(alignment: .leading) {
  50. Text(element.title)
  51. .font(.system(size: 12))
  52. .fontWeight(.regular)
  53. Text(element.subTitle)
  54. .font(.system(size: CGFloat(10)))
  55. .foregroundColor(Color(white: 0.5))
  56. Divider()
  57. }
  58. .padding(.top, 6.0)
  59. Spacer()
  60. }
  61. .padding(.leading, 10)
  62. .frame(height: (geo.size.height-110)/CGFloat(entry.recentDatas.count))
  63. }
  64. }
  65. }
  66. }
  67. .padding(.top, 35)
  68. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  69. HStack(spacing: 0) {
  70. Link(destination: URL(string: "nextcloud://open-action?action=upload-asset")!, label: {
  71. Image("buttonAddImage")
  72. .resizable()
  73. .renderingMode(.template)
  74. .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
  75. .padding(10)
  76. .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
  77. .clipShape(Circle())
  78. .scaledToFit()
  79. .frame(width: geo.size.width/4, height: 45)
  80. })
  81. Link(destination: URL(string: "nextcloud://open-action?action=add-scan-document")!, label: {
  82. Image("buttonAddScan")
  83. .resizable()
  84. .renderingMode(.template)
  85. .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
  86. .padding(10)
  87. .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
  88. .clipShape(Circle())
  89. .scaledToFit()
  90. .frame(width: geo.size.width/4, height: 45)
  91. })
  92. Link(destination: URL(string: "nextcloud://open-action?action=create-text-document")!, label: {
  93. Image("note.text")
  94. .resizable()
  95. .renderingMode(.template)
  96. .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
  97. .padding(10)
  98. .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
  99. .clipShape(Circle())
  100. .scaledToFit()
  101. .frame(width: geo.size.width/4, height: 45)
  102. })
  103. Link(destination: URL(string: "nextcloud://open-action?action=create-voice-memo")!, label: {
  104. Image("microphone")
  105. .resizable()
  106. .renderingMode(.template)
  107. .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
  108. .padding(10)
  109. .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
  110. .clipShape(Circle())
  111. .scaledToFit()
  112. .frame(width: geo.size.width/4, height: 45)
  113. })
  114. }
  115. .frame(width: geo.size.width, height: geo.size.height-25, alignment: .bottomTrailing)
  116. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  117. HStack {
  118. Image(systemName: entry.footerImage)
  119. .resizable()
  120. .scaledToFit()
  121. .frame(width: 15, height: 15)
  122. .foregroundColor(entry.isPlaceholder ? Color(white: 0.2) : Color(NCBrandColor.shared.brand))
  123. Text(entry.footerText)
  124. .font(.caption2)
  125. .padding(.trailing, 13.0)
  126. }
  127. .frame(maxWidth: geo.size.width, maxHeight: geo.size.height-4, alignment: .bottomTrailing)
  128. }
  129. }
  130. }
  131. }
  132. struct NextcloudWidget_Previews: PreviewProvider {
  133. static var previews: some View {
  134. let recentDatas = Array(recentDatasTest[0...2])
  135. let entry = NextcloudDataEntry(date: Date(), recentDatas: recentDatas, isPlaceholder: false, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " widget")
  136. NextcloudWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  137. }
  138. }