NextcloudWidgetView.swift 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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: .top) {
  29. HStack(spacing: 5) {
  30. Image("nextcloud")
  31. .resizable()
  32. .scaledToFit()
  33. .frame(width: 10, height: 10)
  34. .cornerRadius(3)
  35. Text(NCBrandOptions.shared.brand + "k")
  36. .font(.system(size: 12))
  37. .textCase(.uppercase)
  38. }
  39. .padding(.leading, 5)
  40. .padding(.bottom, 5)
  41. VStack(alignment: .leading, spacing: 5) {
  42. VStack(spacing: 5) {
  43. ForEach(entry.nextcloudDatas, id: \.id) { element in
  44. Link(destination: element.url) {
  45. HStack {
  46. Image(element.image)
  47. .resizable()
  48. .aspectRatio(contentMode: .fit)
  49. .frame(width: 40, height: 40)
  50. .clipShape(Circle())
  51. VStack(alignment: .leading) {
  52. Text(element.title)
  53. .font(.headline)
  54. Text(element.subTitle)
  55. .font(.subheadline)
  56. .foregroundColor(Color(white: 0.4745))
  57. }
  58. Spacer()
  59. }
  60. .padding(5)
  61. }
  62. }
  63. }
  64. }.padding(.top, 5)
  65. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  66. Text(entry.footerText)
  67. .font(.caption2)
  68. .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)
  69. .padding(.trailing, 10.0)
  70. .padding(.bottom, 5.0)
  71. }
  72. }
  73. }
  74. struct NextcloudWidget_Previews: PreviewProvider {
  75. static var previews: some View {
  76. let entry = NextcloudDataEntry(date: Date(), nextcloudDatas: nextcloudDatasTest, isPlaceholder: false, footerText: "Nextcloud widget")
  77. NextcloudWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  78. }
  79. }