Explorar el Código

Improved Dashboard

Signed-off-by: marinofaggiana <marino.faggiana@nextcloud.com>
marinofaggiana hace 2 años
padre
commit
7f69cbbf63

+ 1 - 1
Widget/DashboardData.swift

@@ -36,7 +36,7 @@ struct DashboardDataEntry: TimelineEntry {
     let dashboardDatas: [DashboardData]
     let isPlaceholder: Bool
     let title: String
-    let items: Int
+    let footerText: String
 }
 
 func getTitle(account: tableAccount?) -> String {

+ 3 - 3
Widget/DashboardNetworking.swift

@@ -32,10 +32,10 @@ let dashboardDatasTest: [DashboardData] = [
     .init(id: 4, image: "nextcloud", title: "title 5", subTitle: "subTitle - description 5", url: URL(string: "https://nextcloud.com/")!)
 ]
 
-func readDashboard(completion: @escaping (_ dashboardData: [DashboardData], _ isPlaceholder: Bool, _ title: String, _ items: Int) -> Void) {
+func readDashboard(completion: @escaping (_ dashboardData: [DashboardData], _ isPlaceholder: Bool, _ title: String, _ footerText: String) -> Void) {
 
     guard let account = NCManageDatabase.shared.getActiveAccount() else {
-        return completion(dashboardDatasTest, true, getTitle(account: nil), 0)
+        return completion(dashboardDatasTest, true, getTitle(account: nil), NSLocalizedString("_no_active_account_", value: "No account found", comment: ""))
     }
 
     // LOG
@@ -55,7 +55,7 @@ func readDashboard(completion: @escaping (_ dashboardData: [DashboardData], _ is
     NKCommon.shared.writeLog("Start Dashboard widget [Auto upload]")
 
     NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
-        completion(dashboardDatasTest, false, getTitle(account: account), items)
+        completion(dashboardDatasTest, false, getTitle(account: account), "Auto upoload: \(items), \(Date().formatted())")
         NKCommon.shared.writeLog("Completition Dashboard widget [Auto upload]")
     }
 }

+ 30 - 29
Widget/DashboardWidgetView.swift

@@ -43,47 +43,48 @@ import WidgetKit
 
 struct DashboardWidgetView: View {
     var entry: DashboardDataEntry
-    let date = Date().formatted()
     var body: some View {
-        VStack {
-            Text(entry.title)
-                .font(.title3)
-                .bold()
-                .fixedSize(horizontal: false, vertical: true)
-            VStack(spacing: 5) {
-                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(Color(white: 0.4745))
+        ZStack {
+            VStack {
+                Text(entry.title)
+                    .font(.title3)
+                    .bold()
+                    .fixedSize(horizontal: false, vertical: true)
+                VStack(spacing: 5) {
+                    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(Color(white: 0.4745))
+                                }
+                                Spacer()
                             }
-                            Spacer()
+                            .padding(5)
                         }
-                        .padding(5)
                     }
                 }
+            }.padding(5)
+                .redacted(reason: entry.isPlaceholder ? .placeholder : [])
             }
-            Text("Auto upoload: \(entry.items), \(date)")
+        Text(entry.footerText)
                 .font(.caption2)
-                .padding(.trailing)
-                .frame(maxWidth: .infinity, alignment: .trailing)
-        }.padding(5)
-            .redacted(reason: entry.isPlaceholder ? .placeholder : [])
+                .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)
+                .padding([.bottom, .trailing], 5.0)
     }
 }
 
 struct NCElementDashboard_Previews: PreviewProvider {
     static var previews: some View {
-        let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest, isPlaceholder: false, title: getTitle(account: nil), items: 0)
+        let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest, isPlaceholder: false, title: getTitle(account: nil), footerText: "Nextcloud Dashboard")
         DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }

+ 6 - 6
Widget/Widget.swift

@@ -29,18 +29,18 @@ struct Provider: TimelineProvider {
     typealias Entry = DashboardDataEntry
 
     func placeholder(in context: Context) -> Entry {
-        return Entry(date: Date(), dashboardDatas: [], isPlaceholder: true, title: getTitle(account: nil), items: 0)
+        return Entry(date: Date(), dashboardDatas: [], isPlaceholder: true, title: getTitle(account: nil), footerText: "Nextcloud Dashboard")
     }
 
     func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {
-        readDashboard { dashboardDatas, isPlaceholder, title, items in
-            completion(Entry(date: Date(), dashboardDatas: dashboardDatas, isPlaceholder: isPlaceholder, title: title, items: items))
+        readDashboard { dashboardDatas, isPlaceholder, title, footerText in
+            completion(Entry(date: Date(), dashboardDatas: dashboardDatas, isPlaceholder: isPlaceholder, title: title, footerText: footerText))
         }
     }
 
     func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
-        readDashboard { dashboardDatas, isPlaceholder, title, items in
-            let timeLine = Timeline(entries: [Entry(date: Date(), dashboardDatas: dashboardDatas, isPlaceholder: isPlaceholder, title: title, items: items)], policy: .atEnd)
+        readDashboard { dashboardDatas, isPlaceholder, title, footerText in
+            let timeLine = Timeline(entries: [Entry(date: Date(), dashboardDatas: dashboardDatas, isPlaceholder: isPlaceholder, title: title, footerText: footerText)], policy: .atEnd)
             completion(timeLine)
         }
     }
@@ -63,7 +63,7 @@ struct DashboardWidget: Widget {
 struct DashboardWidget_Previews: PreviewProvider {
 
     static var previews: some View {
-        let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest, isPlaceholder: false, title: getTitle(account: nil), items: 0)
+        let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest, isPlaceholder: false, title: getTitle(account: nil), footerText: "Nextcloud Dashboard")
         DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }