NextcloudWidgetView.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. HStack(spacing: 5) {
  71. Image(systemName: "arrow.triangle.2.circlepath")
  72. .foregroundColor(Color(NCBrandColor.shared.brand))
  73. Text("Uploading")
  74. .font(.system(size: 12))
  75. .textCase(.uppercase)
  76. }
  77. .padding(.leading, 10)
  78. HStack(spacing: spacingImageUpload) {
  79. }
  80. .frame(width: geo.size.width, alignment: .center)
  81. }
  82. .padding(.top, 45)
  83. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  84. Text(entry.footerText)
  85. .font(.caption2)
  86. .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)
  87. .padding(.trailing, 10.0)
  88. .padding(.bottom, 5.0)
  89. }
  90. }
  91. }
  92. }
  93. struct NextcloudWidget_Previews: PreviewProvider {
  94. static var previews: some View {
  95. let entry = NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: false, footerText: NCBrandOptions.shared.brand + " widget")
  96. NextcloudWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  97. }
  98. }