DashboardWidgetView.swift 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. let date = Date().formatted()
  41. var body: some View {
  42. VStack {
  43. Text(entry.title)
  44. .font(.title3)
  45. .bold()
  46. .fixedSize(horizontal: false, vertical: true)
  47. VStack(spacing: 5) {
  48. ForEach(entry.dashboardDatas, id: \.id) { element in
  49. Link(destination: element.url) {
  50. HStack {
  51. Image(element.image)
  52. .resizable()
  53. .aspectRatio(contentMode: .fit)
  54. .frame(width: 40, height: 40)
  55. .clipShape(Circle())
  56. VStack(alignment: .leading) {
  57. Text(element.title)
  58. .font(.headline)
  59. Text(element.subTitle)
  60. .font(.subheadline)
  61. .foregroundColor(Color(white: 0.4745))
  62. }
  63. Spacer()
  64. }
  65. .padding(5)
  66. }
  67. }
  68. }
  69. Text("\(date)")
  70. .font(.caption2)
  71. .padding(.trailing)
  72. .frame(maxWidth: .infinity, alignment: .trailing)
  73. }.padding(5)
  74. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  75. }
  76. }
  77. struct NCElementDashboard_Previews: PreviewProvider {
  78. static var previews: some View {
  79. let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest, isPlaceholder: false, title: getTitle(account: nil))
  80. DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  81. }
  82. }