Browse Source

test

Signed-off-by: marinofaggiana <marino.faggiana@nextcloud.com>
marinofaggiana 2 years ago
parent
commit
4b6b4b3ba3

+ 71 - 27
DashboardWidget/DashBoardList.swift

@@ -9,50 +9,94 @@
 import SwiftUI
 import WidgetKit
 
-struct DashBoardList: View {
-    var data: [DashboardData]
+/*
+ @Environment(\.colorScheme) var colorScheme
+
+     var entry: Provider.Entry
+
+     var bgColor: some View {
+         colorScheme == .dark ? Color.red : Color.orange
+     }
+
+     var body: some View {
+         ZStack {
+             bgColor
+             Text(entry.date, style: .time)
+         }
+     }
+ */
+
+struct ListWidgetEntryView: View {
+    var entry: DashboardListEntry
     var body: some View {
+        switch entry.dashboardDatas.isEmpty {
+        case true:
+            emptyDasboardView
+        case false:
+            bodyDasboardView
+        }
+    }
+
+    var emptyDasboardView: some View {
         VStack(alignment: .center) {
             Text("Good morning")
                 .font(.title)
                 .bold()
             VStack {
-                ForEach(data, id: \.id) { element in
-                    DashboardElement(element: element)
+                ForEach(1...5, id: \.self) { _ in
+                    HStack {
+                        Image(systemName: "")
+                            .font(.system(size: 40.0))
+                            .foregroundColor(.red)
+                        VStack(alignment: .leading) {
+                            Text("")
+                                .font(.headline)
+                            Text("")
+                                .font(.subheadline)
+                                .foregroundColor(.accentColor)
+                        }
+                        Spacer()
+                    }
+                    .padding(5)
                 }
             }
         }.padding()
     }
-}
 
-struct DashboardElement: View {
-    var element: DashboardData
-    var body: some View {
-        Link(destination: element.url) {
-            HStack {
-                Image(element.image)
-                    .resizable()
-                    .aspectRatio(contentMode: .fit)
-                    .frame(width: 40, height: 40)
-                    .clipShape(Circle())
-                VStack(alignment: .leading) {
-                    Text(element.title)
-                        .font(.headline)
-                    Text(element.subTitle)
-                        .font(.subheadline)
-                        .foregroundColor(.accentColor)
+    var bodyDasboardView: some View {
+        VStack(alignment: .center) {
+            Text("Good morning")
+                .font(.title)
+                .bold()
+            VStack {
+                ForEach(entry.dashboardDatas, id: \.id) { element in
+                    Link(destination: element.url) {
+                        HStack {
+                            Image(element.image)
+                                .resizable()
+                                .aspectRatio(contentMode: .fit)
+                                .frame(width: 40, height: 40)
+                                .clipShape(Circle())
+                            VStack(alignment: .leading) {
+                                Text(element.title)
+                                    .font(.headline)
+                                Text(element.subTitle)
+                                    .font(.subheadline)
+                                    .foregroundColor(.accentColor)
+                            }
+                            Spacer()
+                        }
+                        .padding(5)
+                    }
                 }
-                Spacer()
             }
-            .padding(5)
-        }
+        }.padding()
     }
 }
 
 struct NCElementDashboard_Previews: PreviewProvider {
     static var previews: some View {
-        Group {
-            DashBoardList(data: dataDashboardPreview).previewContext(WidgetPreviewContext(family: .systemLarge))
-        }
+        let entry = DashboardListEntry(date: Date(), dashboardDatas: [])
+        ListWidgetEntryView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }

+ 0 - 25
DashboardWidget/DashboardData.swift

@@ -1,25 +0,0 @@
-//
-//  DashboardData.swift
-//  DashboardWidgetExtension
-//
-//  Created by Marino Faggiana on 20/08/22.
-//  Copyright © 2022 Marino Faggiana. All rights reserved.
-//
-
-import Foundation
-
-struct DashboardData: Identifiable, Codable, Hashable {
-    var id: Int
-    var image: String
-    var title: String
-    var subTitle: String
-    var url: URL
-}
-
-let dataDashboardPreview: [DashboardData] = [
-    .init(id: 1, image: "nextcloud", title: "The Weeknd", subTitle: "theweeknd-after-hours", url: URL(string: "https://nextcloud.com/1")!),
-    .init(id: 2, image: "nextcloud", title: "Lil Uzi", subTitle: "eternalatake-liluzivert", url: URL(string: "https://nextcloud.com/2")!),
-    .init(id: 3, image: "nextcloud", title: "Dua Lipa", subTitle: "dualipa-bReAK mY heART", url: URL(string: "https://nextcloud.com/3")!),
-    .init(id: 4, image: "nextcloud", title: "Kanye West", subTitle: "kaynewest-jesusisking", url: URL(string: "https://nextcloud.com/4")!),
-    .init(id: 5, image: "nextcloud", title: "Kanye West", subTitle: "kaynewest-jesusisking", url: URL(string: "https://nextcloud.com/5")!)
-]

+ 22 - 27
DashboardWidget/DashboardWidget.swift

@@ -11,33 +11,27 @@ import SwiftUI
 
 struct Provider: TimelineProvider {
 
-    func placeholder(in context: Context) -> SimpleEntry {
-        SimpleEntry(date: Date())
-    }
+    typealias Entry = DashboardListEntry
 
-    func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
-        let entry = SimpleEntry(date: Date())
-        completion(entry)
+    func placeholder(in context: Context) -> Entry {
+        return Entry(date: Date(), dashboardDatas: dataPreview)
     }
 
-    func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
-        var entries: [SimpleEntry] = []
-
-        // Generate a timeline consisting of five entries an hour apart, starting from the current date.
-        let currentDate = Date()
-        for hourOffset in 0 ..< 5 {
-            let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
-            let entry = SimpleEntry(date: entryDate)
-            entries.append(entry)
-        }
-
-        let timeline = Timeline(entries: entries, policy: .atEnd)
-        completion(timeline)
+    func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {
+        let datas = dataPreview
+        completion(Entry(date: Date(), dashboardDatas: datas))
+//        if context.isPreview {
+//        } else {
+//        }
     }
-}
 
-struct SimpleEntry: TimelineEntry {
-    let date: Date
+    func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
+        let components = DateComponents(minute: 10)
+        let futureDate = Calendar.current.date(byAdding: components, to: Date())!
+        let datas = dataPreview
+        let timeLine = Timeline(entries: [Entry(date: Date(), dashboardDatas: datas)], policy: .after(futureDate))
+        completion(timeLine)
+    }
 }
 
 @main
@@ -45,18 +39,19 @@ struct DashboardWidget: Widget {
     let kind: String = "DashboardWidget"
 
     var body: some WidgetConfiguration {
-        StaticConfiguration(kind: kind, provider: Provider()) { _ in
-            DashBoardList(data: dataDashboardPreview)
+        StaticConfiguration(kind: kind, provider: Provider()) { entry in
+            ListWidgetEntryView(entry: entry)
         }
         .supportedFamilies([.systemLarge])
-        .configurationDisplayName("Nextcloud Dashboard Widget")
-        .description("Nextcloud Dashboard Widget.")
+        .configurationDisplayName("Nextcloud Dashboard")
+        .description("subtitle.")
     }
 }
 
 struct DashboardWidget_Previews: PreviewProvider {
 
     static var previews: some View {
-        DashBoardList(data: dataDashboardPreview).previewContext(WidgetPreviewContext(family: .systemLarge))
+        let entry = DashboardListEntry(date: Date(), dashboardDatas: dataPreview)
+        ListWidgetEntryView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }

+ 25 - 0
DashboardWidget/Entries/DashboardData.swift

@@ -0,0 +1,25 @@
+//
+//  DashboardData.swift
+//  DashboardWidgetExtension
+//
+//  Created by Marino Faggiana on 20/08/22.
+//  Copyright © 2022 Marino Faggiana. All rights reserved.
+//
+
+import Foundation
+
+struct DashboardData: Identifiable, Codable, Hashable {
+    var id: Int
+    var image: String
+    var title: String
+    var subTitle: String
+    var url: URL
+}
+
+let dataPreview: [DashboardData] = [
+    .init(id: 0, image: "circle_fill", title: "-", subTitle: "-", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: 0, image: "circle_fill", title: "-", subTitle: "-", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: 0, image: "circle_fill", title: "-", subTitle: "-", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: 0, image: "circle_fill", title: "-", subTitle: "-", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: 0, image: "circle_fill", title: "-", subTitle: "-", url: URL(string: "https://nextcloud.com/")!)
+]

+ 14 - 0
DashboardWidget/Entries/DashboardListEntry.swift

@@ -0,0 +1,14 @@
+//
+//  DashboardListEntry.swift
+//  DashboardWidgetExtension
+//
+//  Created by Marino Faggiana on 22/08/22.
+//  Copyright © 2022 Marino Faggiana. All rights reserved.
+//
+
+import WidgetKit
+
+struct DashboardListEntry: TimelineEntry {
+    let date: Date
+    let dashboardDatas: [DashboardData]
+}

+ 13 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -192,6 +192,7 @@
 		F73D5E49246DE09200DF6467 /* NCElementsJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73D5E46246DE09200DF6467 /* NCElementsJSON.swift */; };
 		F73D5E4A246DE09200DF6467 /* NCElementsJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73D5E46246DE09200DF6467 /* NCElementsJSON.swift */; };
 		F73F537F1E929C8500F8678D /* NCMore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73F537E1E929C8500F8678D /* NCMore.swift */; };
+		F741F3B428B3BC950045394D /* DashboardListEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = F741F3B328B3BC950045394D /* DashboardListEntry.swift */; };
 		F7434B3420E23FD700417916 /* NCDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB41ED5A87C00B7EAD4 /* NCDatabase.swift */; };
 		F7434B3620E23FE000417916 /* NCManageDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB51ED5A87C00B7EAD4 /* NCManageDatabase.swift */; };
 		F7434B3820E2400600417916 /* NCBrand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76B3CCD1EAE01BD00921AC9 /* NCBrand.swift */; };
@@ -708,6 +709,7 @@
 		F73D11F9253C5F4800DF9BEC /* NCViewerNextcloudText.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCViewerNextcloudText.storyboard; sourceTree = "<group>"; };
 		F73D5E46246DE09200DF6467 /* NCElementsJSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCElementsJSON.swift; sourceTree = "<group>"; };
 		F73F537E1E929C8500F8678D /* NCMore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCMore.swift; sourceTree = "<group>"; };
+		F741F3B328B3BC950045394D /* DashboardListEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardListEntry.swift; sourceTree = "<group>"; };
 		F7421EAE2294044B00C4B7C1 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
 		F7434B5F20E2440600417916 /* FileProviderExtension-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FileProviderExtension-Bridging-Header.h"; sourceTree = "<group>"; };
 		F745B250222D871800346520 /* QRCodeReader.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QRCodeReader.framework; path = Carthage/Build/iOS/QRCodeReader.framework; sourceTree = "<group>"; };
@@ -1301,9 +1303,9 @@
 		F7346E1428B0EF5B006CE2D2 /* DashboardWidget */ = {
 			isa = PBXGroup;
 			children = (
+				F741F3B028B3BBB70045394D /* Entries */,
 				F7346E2228B0FEBA006CE2D2 /* Assets.xcassets */,
 				F72A17D728B221E300F3F159 /* DashBoardList.swift */,
-				F7E0710028B13BB00001B882 /* DashboardData.swift */,
 				F7346E1528B0EF5C006CE2D2 /* DashboardWidget.swift */,
 				F7346E2028B0FA3A006CE2D2 /* DashboardWidget-Brinding-header.h */,
 			);
@@ -1337,6 +1339,15 @@
 			path = Diagnostics;
 			sourceTree = "<group>";
 		};
+		F741F3B028B3BBB70045394D /* Entries */ = {
+			isa = PBXGroup;
+			children = (
+				F7E0710028B13BB00001B882 /* DashboardData.swift */,
+				F741F3B328B3BC950045394D /* DashboardListEntry.swift */,
+			);
+			path = Entries;
+			sourceTree = "<group>";
+		};
 		F74D3DB81BAC1941000BAE4B /* Networking */ = {
 			isa = PBXGroup;
 			children = (
@@ -2582,6 +2593,7 @@
 			buildActionMask = 2147483647;
 			files = (
 				F7E0710128B13BB00001B882 /* DashboardData.swift in Sources */,
+				F741F3B428B3BC950045394D /* DashboardListEntry.swift in Sources */,
 				F7346E1628B0EF5C006CE2D2 /* DashboardWidget.swift in Sources */,
 				F72A17D828B221E300F3F159 /* DashBoardList.swift in Sources */,
 			);