DashboardWidgetView.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // DashboardWidgetView.swift
  3. // Widget
  4. //
  5. // Created by Marino Faggiana on 20/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. /*
  26. @Environment(\.colorScheme) var colorScheme
  27. var entry: Provider.Entry
  28. var bgColor: some View {
  29. colorScheme == .dark ? Color.red : Color.orange
  30. }
  31. var body: some View {
  32. ZStack {
  33. bgColor
  34. Text(entry.date, style: .time)
  35. }
  36. }
  37. */
  38. struct DashboardWidgetView: View {
  39. var entry: DashboardDataEntry
  40. var placeholderColor = Color(red: 0.9, green: 0.9, blue: 0.92)
  41. let date = Date().formatted()
  42. var body: some View {
  43. switch entry.dashboardDatas.isEmpty {
  44. case true:
  45. emptyDasboardView
  46. case false:
  47. bodyDasboardView
  48. }
  49. }
  50. var emptyDasboardView: some View {
  51. VStack(alignment: .center) {
  52. Text("")
  53. .frame(maxWidth: 280, minHeight: 20)
  54. .background(placeholderColor)
  55. .padding(5)
  56. VStack {
  57. ForEach(1...5, id: \.self) { _ in
  58. HStack {
  59. Image(systemName: "circle.fill")
  60. .font(.system(size: 40.0))
  61. .foregroundColor(placeholderColor)
  62. VStack(alignment: .leading, spacing: 5) {
  63. Text("")
  64. .frame(maxWidth: .infinity)
  65. .background(placeholderColor)
  66. Text("")
  67. .frame(maxWidth: .infinity)
  68. .background(placeholderColor)
  69. }
  70. Spacer()
  71. }
  72. .padding(5)
  73. }
  74. }
  75. }.padding(5)
  76. }
  77. var bodyDasboardView: some View {
  78. VStack(alignment: .center) {
  79. Text("\(date)")
  80. .font(.title)
  81. .bold()
  82. VStack {
  83. ForEach(entry.dashboardDatas, id: \.id) { element in
  84. Link(destination: element.url) {
  85. HStack {
  86. Image(element.image)
  87. .resizable()
  88. .aspectRatio(contentMode: .fit)
  89. .frame(width: 40, height: 40)
  90. .clipShape(Circle())
  91. VStack(alignment: .leading) {
  92. Text(element.title)
  93. .font(.headline)
  94. Text(element.subTitle)
  95. .font(.subheadline)
  96. .foregroundColor(Color(white: 0.4745))
  97. }
  98. Spacer()
  99. }
  100. .padding(5)
  101. }
  102. }
  103. }
  104. }.padding(5)
  105. }
  106. }
  107. struct NCElementDashboard_Previews: PreviewProvider {
  108. static var previews: some View {
  109. let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest) // dashboardDatasTest
  110. DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  111. }
  112. }