NextcloudWidgetView.swift 7.1 KB

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