NextcloudWidgetView.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. ZStack(alignment: .topLeading) {
  29. HStack(spacing: 5) {
  30. Image("nextcloud")
  31. .resizable()
  32. .scaledToFit()
  33. .frame(width: 18, height: 18)
  34. .cornerRadius(4)
  35. Text(NCBrandOptions.shared.brand + "")
  36. .font(.system(size: 12))
  37. .textCase(.uppercase)
  38. }
  39. .padding(.leading, 10)
  40. .padding(.top, 10)
  41. VStack(alignment: .leading) {
  42. VStack(spacing: 6) {
  43. ForEach(entry.recentDatas, id: \.id) { element in
  44. Link(destination: element.url) {
  45. HStack {
  46. Image(uiImage: element.image)
  47. .resizable()
  48. .scaledToFill()
  49. .frame(width: 30, height: 30)
  50. .clipped()
  51. .cornerRadius(4)
  52. VStack(alignment: .leading) {
  53. Text(element.title)
  54. .font(.system(size: 12))
  55. .fontWeight(.bold)
  56. Text(element.subTitle)
  57. .font(.system(size: CGFloat(10)))
  58. .foregroundColor(Color(white: 0.4745))
  59. Divider()
  60. }
  61. Spacer()
  62. }
  63. .padding(.leading, 10)
  64. }
  65. }
  66. }
  67. Spacer()
  68. .frame(width: .infinity, height: 15.0)
  69. Text("File in upload ...")
  70. .font(.system(size: 12))
  71. .frame(maxWidth: .infinity, alignment: .center)
  72. HStack(spacing: 10) {
  73. ForEach(entry.uploadDatas, id: \.id) { element in
  74. Image(uiImage: element.image)
  75. .resizable()
  76. .scaledToFill()
  77. .frame(width: 30, height: 30)
  78. .clipped()
  79. .cornerRadius(4)
  80. }
  81. }
  82. .frame(maxWidth: .infinity, alignment: .trailing)
  83. .padding(.trailing, 10)
  84. }
  85. .padding(.top, 45)
  86. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  87. Text(entry.footerText)
  88. .font(.caption2)
  89. .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)
  90. .padding(.trailing, 10.0)
  91. .padding(.bottom, 5.0)
  92. }
  93. }
  94. }
  95. struct NextcloudWidget_Previews: PreviewProvider {
  96. static var previews: some View {
  97. let entry = NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, uploadDatas: uploadDatasTest, isPlaceholder: false, footerText: NCBrandOptions.shared.brand + " widget")
  98. NextcloudWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  99. }
  100. }