Procházet zdrojové kódy

#2216

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana před 2 roky
rodič
revize
7390c863a1

+ 7 - 6
Widget/Dashboard/DashboardData.swift

@@ -32,6 +32,7 @@ struct DashboardDataEntry: TimelineEntry {
     let dashboard: tableDashboardWidget?
     let buttons: [tableDashboardWidgetButton]?
     let isPlaceholder: Bool
+    let isEmpty: Bool
     let titleImage: UIImage
     let title: String
     let footerImage: String
@@ -85,11 +86,11 @@ func getDashboardDataEntry(intent: Applications?, isPreview: Bool, displaySize:
     let datasPlaceholder = Array(dashboardDatasTest[0...dashboardItems - 1])
 
     if isPreview {
-        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, dashboard: nil, buttons: nil, isPlaceholder: true, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
+        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, dashboard: nil, buttons: nil, isPlaceholder: true, isEmpty: false, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
     }
 
     guard let account = NCManageDatabase.shared.getActiveAccount() else {
-        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, dashboard: nil, buttons: nil, isPlaceholder: true, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", comment: "")))
+        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, dashboard: nil, buttons: nil, isPlaceholder: true, isEmpty: false, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", comment: "")))
     }
 
     // Default widget
@@ -98,7 +99,7 @@ func getDashboardDataEntry(intent: Applications?, isPreview: Bool, displaySize:
 
     let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
     guard serverVersionMajor >= NCGlobal.shared.nextcloudVersion25 else {
-        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, dashboard: nil, buttons: nil, isPlaceholder: true, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "xmark.icloud", footerText: NSLocalizedString("_widget_available_nc25_", comment: "")))
+        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, dashboard: nil, buttons: nil, isPlaceholder: true, isEmpty: false, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "xmark.icloud", footerText: NSLocalizedString("_widget_available_nc25_", comment: "")))
     }
         
     // NETWORKING
@@ -223,11 +224,11 @@ func getDashboardDataEntry(intent: Applications?, isPreview: Bool, displaySize:
             }
 
             if error != .success {
-                completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, dashboard: tableDashboard, buttons: buttons, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "xmark.icloud", footerText: error.errorDescription))
+                completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, dashboard: tableDashboard, buttons: buttons, isPlaceholder: true, isEmpty: false, titleImage: titleImage, title: title, footerImage: "xmark.icloud", footerText: error.errorDescription))
             } else if datas.isEmpty {
-                completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, dashboard: tableDashboard, buttons: buttons, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NSLocalizedString("_no_data_available_", comment: "")))
+                completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, dashboard: tableDashboard, buttons: buttons, isPlaceholder: false, isEmpty: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NSLocalizedString("_no_data_available_", comment: "")))
             } else {
-                completion(DashboardDataEntry(date: Date(), datas: datas, dashboard: tableDashboard, buttons: buttons, isPlaceholder: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
+                completion(DashboardDataEntry(date: Date(), datas: datas, dashboard: tableDashboard, buttons: buttons, isPlaceholder: false, isEmpty: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
             }
         }
     }

+ 1 - 1
Widget/Dashboard/DashboardWidgetProvider.swift

@@ -35,7 +35,7 @@ struct DashboardWidgetProvider: IntentTimelineProvider {
         let datasPlaceholder = Array(dashboardDatasTest[0...dashboardItems])
         let title = "Dashboard"
         let titleImage = UIImage(named: "widget")!
-        return Entry(date: Date(), datas: datasPlaceholder, dashboard: nil, buttons: nil, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " widget")
+        return Entry(date: Date(), datas: datasPlaceholder, dashboard: nil, buttons: nil, isPlaceholder: true, isEmpty: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " widget")
     }
 
     func getSnapshot(for configuration: DashboardIntent, in context: Context, completion: @escaping (DashboardDataEntry) -> Void) {

+ 87 - 69
Widget/Dashboard/DashboardWidgetView.swift

@@ -32,10 +32,25 @@ struct DashboardWidgetView: View {
         
         GeometryReader { geo in
 
+            if entry.isEmpty {
+                VStack(alignment: .center) {
+                    Image(systemName: "checkmark")
+                        .resizable()
+                        .scaledToFit()
+                        .frame(width: 50, height: 50)
+                    Text(NSLocalizedString("_no_items_", comment: ""))
+                        .font(.system(size: 25))
+                        .padding()
+                    Text(NSLocalizedString("_check_back_late_", comment: ""))
+                        .font(.system(size: 15))
+                }
+                .frame(width: geo.size.width, height: geo.size.height)
+            }
+
             ZStack(alignment: .topLeading) {
 
                 HStack() {
-                    
+
                     Image(uiImage: entry.titleImage)
                         .renderingMode(.template)
                         .resizable()
@@ -51,88 +66,91 @@ struct DashboardWidgetView: View {
                 }
                 .frame(width: geo.size.width - 20)
                 .padding([.top, .leading, .trailing], 10)
-                
-                VStack(alignment: .leading) {
-                    
-                    VStack(spacing: 0) {
-                                                
-                        ForEach(entry.datas, id: \.id) { element in
-                            
-                            Link(destination: element.link) {
-                                
-                                HStack {
-                                    
-                                    let subTitleColor = Color(white: 0.5)
-
-                                    if entry.isPlaceholder {
-                                        Circle()
-                                            .fill(Color(.systemGray4))
-                                            .frame(width: 35, height: 35)
-                                    } else if let color = element.imageColor {
-                                        Image(uiImage: element.icon)
-                                            .renderingMode(.template)
-                                            .resizable()
-                                            .frame(width: 20, height: 20)
-                                            .foregroundColor(Color(color))
-                                    } else if element.template {
-                                        if entry.dashboard?.itemIconsRound ?? false {
+
+                if !entry.isEmpty {
+
+                    VStack(alignment: .leading) {
+
+                        VStack(spacing: 0) {
+
+                            ForEach(entry.datas, id: \.id) { element in
+
+                                Link(destination: element.link) {
+
+                                    HStack {
+
+                                        let subTitleColor = Color(white: 0.5)
+
+                                        if entry.isPlaceholder {
+                                            Circle()
+                                                .fill(Color(.systemGray4))
+                                                .frame(width: 35, height: 35)
+                                        } else if let color = element.imageColor {
                                             Image(uiImage: element.icon)
                                                 .renderingMode(.template)
                                                 .resizable()
-                                                .scaledToFill()
                                                 .frame(width: 20, height: 20)
-                                                .foregroundColor(.white)
-                                                .padding(8)
-                                                .background(Color(.systemGray4))
-                                                .clipShape(Circle())
-                                        } else {
-                                            Image(uiImage: element.icon)
-                                                .renderingMode(.template)
-                                                .resizable()
-                                                .scaledToFill()
-                                                .frame(width: 25, height: 25)
-                                                .clipped()
-                                                .cornerRadius(5)
-                                        }
-                                    } else {
-                                        if entry.dashboard?.itemIconsRound ?? false || element.avatar {
-                                            Image(uiImage: element.icon)
-                                                .resizable()
-                                                .scaledToFill()
-                                                .frame(width: 35, height: 35)
-                                                .clipShape(Circle())
+                                                .foregroundColor(Color(color))
+                                        } else if element.template {
+                                            if entry.dashboard?.itemIconsRound ?? false {
+                                                Image(uiImage: element.icon)
+                                                    .renderingMode(.template)
+                                                    .resizable()
+                                                    .scaledToFill()
+                                                    .frame(width: 20, height: 20)
+                                                    .foregroundColor(.white)
+                                                    .padding(8)
+                                                    .background(Color(.systemGray4))
+                                                    .clipShape(Circle())
+                                            } else {
+                                                Image(uiImage: element.icon)
+                                                    .renderingMode(.template)
+                                                    .resizable()
+                                                    .scaledToFill()
+                                                    .frame(width: 25, height: 25)
+                                                    .clipped()
+                                                    .cornerRadius(5)
+                                            }
                                         } else {
-                                            Image(uiImage: element.icon)
-                                                .resizable()
-                                                .scaledToFill()
-                                                .frame(width: 35, height: 35)
-                                                .clipped()
-                                                .cornerRadius(5)
+                                            if entry.dashboard?.itemIconsRound ?? false || element.avatar {
+                                                Image(uiImage: element.icon)
+                                                    .resizable()
+                                                    .scaledToFill()
+                                                    .frame(width: 35, height: 35)
+                                                    .clipShape(Circle())
+                                            } else {
+                                                Image(uiImage: element.icon)
+                                                    .resizable()
+                                                    .scaledToFill()
+                                                    .frame(width: 35, height: 35)
+                                                    .clipped()
+                                                    .cornerRadius(5)
+                                            }
                                         }
-                                    }
 
-                                    VStack(alignment: .leading, spacing: 2) {
+                                        VStack(alignment: .leading, spacing: 2) {
 
-                                        Text(element.title)
-                                            .font(.system(size: 12))
-                                            .fontWeight(.regular)
+                                            Text(element.title)
+                                                .font(.system(size: 12))
+                                                .fontWeight(.regular)
 
-                                        Text(element.subTitle)
-                                            .font(.system(size: CGFloat(10)))
-                                            .foregroundColor(subTitleColor)
+                                            Text(element.subTitle)
+                                                .font(.system(size: CGFloat(10)))
+                                                .foregroundColor(subTitleColor)
+                                        }
+                                        Spacer()
                                     }
-                                    Spacer()
+                                    .padding(.leading, 10)
+                                    .frame(height: 50)
                                 }
-                                .padding(.leading, 10)
-                                .frame(height: 50)
+                                Divider()
+                                    .padding(.leading, 54)
                             }
-                            Divider()
-                                .padding(.leading, 54)
                         }
                     }
+                    .padding(.top, 35)
+                    .redacted(reason: entry.isPlaceholder ? .placeholder : [])
                 }
-                .padding(.top, 35)
-                .redacted(reason: entry.isPlaceholder ? .placeholder : [])
 
                 if let buttons = entry.buttons, !buttons.isEmpty, !entry.isPlaceholder {
 
@@ -181,7 +199,7 @@ struct DashboardWidget_Previews: PreviewProvider {
         let datas = Array(dashboardDatasTest[0...4])
         let title = "Dashboard"
         let titleImage = UIImage(named: "widget")!
-        let entry = DashboardDataEntry(date: Date(), datas: datas, dashboard: nil, buttons: nil, isPlaceholder: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: "Nextcloud widget")
+        let entry = DashboardDataEntry(date: Date(), datas: datas, dashboard: nil, buttons: nil, isPlaceholder: false, isEmpty: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: "Nextcloud widget")
         DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }

+ 2 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -894,6 +894,8 @@
 "_recent_activity_"         = "Recent activity";
 "_title_lockscreenwidget_"  = "Status";
 "_description_lockscreenwidget_" = "Keep an eye on available space and recent activity";
+"_no_items_"                = "No items";
+"_check_back_late_"         = "Check back late";
 
 // Video
 "_select_trace_"            = "Select the trace";