NextcloudWidgetView.swift 6.9 KB

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