NextcloudWidgetView.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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("nextcloud")
  32. .resizable()
  33. .scaledToFit()
  34. .frame(width: 18, height: 18)
  35. .cornerRadius(4)
  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.4745))
  60. Divider()
  61. }
  62. Spacer()
  63. }
  64. .padding(.leading, 10)
  65. }
  66. }
  67. }
  68. Spacer()
  69. .frame(width: geo.size.width, height: 16.0)
  70. /*
  71. HStack(spacing: 5) {
  72. Image(systemName: "arrow.triangle.2.circlepath")
  73. .foregroundColor(Color(NCBrandColor.shared.brand))
  74. Text("Uploading")
  75. .font(.system(size: 12))
  76. .textCase(.uppercase)
  77. }
  78. .padding(.leading, 10)
  79. HStack(spacing: spacingImageUpload) {
  80. }
  81. .frame(width: geo.size.width, alignment: .center)
  82. */
  83. }
  84. .padding(.top, 45)
  85. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  86. HStack {
  87. Image(systemName: entry.footerImage)
  88. .resizable()
  89. .scaledToFit()
  90. .frame(width: 15, height: 15)
  91. .foregroundColor(Color(NCBrandColor.shared.brand))
  92. Text(entry.footerText)
  93. .font(.caption2)
  94. .padding(.trailing, 10.0)
  95. }
  96. .frame(maxWidth: geo.size.width, maxHeight: geo.size.height, alignment: .bottomTrailing)
  97. }
  98. }
  99. }
  100. }
  101. struct NextcloudWidget_Previews: PreviewProvider {
  102. static var previews: some View {
  103. let entry = NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: false, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " widget")
  104. NextcloudWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  105. }
  106. }