NextcloudWidgetView.swift 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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, spacing: 5) {
  42. VStack(spacing: 10) {
  43. ForEach(entry.nextcloudDatas, id: \.id) { element in
  44. Link(destination: element.url) {
  45. HStack {
  46. Image(uiImage: (UIImage(contentsOfFile: element.image) ?? UIImage(named: "file"))!)
  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. Text(element.subTitle)
  56. .font(.system(size: CGFloat(10)))
  57. .foregroundColor(Color(white: 0.4745))
  58. Divider()
  59. }
  60. Spacer()
  61. }
  62. .padding(.leading, 5)
  63. }
  64. }
  65. }
  66. }
  67. .padding(.top, 50)
  68. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  69. Text(entry.footerText)
  70. .font(.caption2)
  71. .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)
  72. .padding(.trailing, 10.0)
  73. .padding(.bottom, 5.0)
  74. }
  75. }
  76. }
  77. struct NextcloudWidget_Previews: PreviewProvider {
  78. static var previews: some View {
  79. let entry = NextcloudDataEntry(date: Date(), nextcloudDatas: nextcloudDatasTest, isPlaceholder: false, footerText: NCBrandOptions.shared.brand + " widget")
  80. NextcloudWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  81. }
  82. }