Explorar o código

coding

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana %!s(int64=2) %!d(string=hai) anos
pai
achega
d576f1023a

+ 1 - 3
Widget/Dashboard/DashboardData.swift

@@ -237,10 +237,8 @@ func getDashboardDataEntry(configuration: DashboardIntent?, isPreview: Bool, dis
 
             if error != .success {
                 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: false, isEmpty: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: footerText))
             } else {
-                completion(DashboardDataEntry(date: Date(), datas: datas, dashboard: tableDashboard, buttons: buttons, isPlaceholder: false, isEmpty: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: footerText))
+                completion(DashboardDataEntry(date: Date(), datas: datas, dashboard: tableDashboard, buttons: buttons, isPlaceholder: false, isEmpty: datas.isEmpty, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: footerText))
             }
         }
     }

+ 5 - 11
Widget/Files/FilesData.swift

@@ -29,6 +29,7 @@ struct FilesDataEntry: TimelineEntry {
     let date: Date
     let datas: [FilesData]
     let isPlaceholder: Bool
+    let isEmpty: Bool
     let userId: String
     let url: String
     let tile: String
@@ -90,7 +91,7 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi
     var account: tableAccount?
 
     if isPreview {
-        return completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, userId: "", url: "", tile: getTitleFilesWidget(account: nil), footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " files"))
+        return completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, isEmpty: false, userId: "", url: "", tile: getTitleFilesWidget(account: nil), footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " files"))
     }
 
     let accountIdentifier: String = configuration?.accounts?.identifier ?? "active"
@@ -101,7 +102,7 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi
     }
 
     guard let account = account else {
-        return completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, userId: "", url: "", tile: getTitleFilesWidget(account: nil), footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
+        return completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, isEmpty: false, userId: "", url: "", tile: getTitleFilesWidget(account: nil), footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
     }
 
     @Sendable func isLive(file: NKFile, files: [NKFile]) -> Bool {
@@ -258,16 +259,9 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi
             let footerText = "Files " + NSLocalizedString("_of_", comment: "") +  " " + account.displayName + alias
 
             if error != .success {
-                completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, userId: account.userId, url: account.urlBase, tile: title, footerImage: "xmark.icloud", footerText: error.errorDescription))
-            } else if datas.isEmpty {
-                var footerText = NSLocalizedString("_no_data_available_", comment: "")
-                let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
-                if serverVersionMajor < NCGlobal.shared.nextcloudVersion25 {
-                    footerText = NSLocalizedString("_widget_available_nc25_", comment: "")
-                }
-                completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, userId: account.userId, url: account.urlBase, tile: title, footerImage: "checkmark.icloud", footerText: footerText))
+                completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, isEmpty: false, userId: account.userId, url: account.urlBase, tile: title, footerImage: "xmark.icloud", footerText: error.errorDescription))
             } else {
-                completion(FilesDataEntry(date: Date(), datas: datas, isPlaceholder: false, userId: account.userId, url: account.urlBase, tile: title, footerImage: "checkmark.icloud", footerText: footerText))
+                completion(FilesDataEntry(date: Date(), datas: datas, isPlaceholder: false, isEmpty: datas.isEmpty, userId: account.userId, url: account.urlBase, tile: title, footerImage: "checkmark.icloud", footerText: footerText))
             }
         }
     }

+ 1 - 1
Widget/Files/FilesWidgetProvider.swift

@@ -34,7 +34,7 @@ struct FilesWidgetProvider: IntentTimelineProvider {
         let filesItems = getFilesItems(displaySize: context.displaySize)
         let datasPlaceholder = Array(filesDatasTest[0...filesItems - 1])
         let title = getTitleFilesWidget(account: nil)
-        return Entry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, userId: "", url: "", tile: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " files")
+        return Entry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, isEmpty: false, userId: "", url: "", tile: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " files")
     }
 
     func getSnapshot(for configuration: AccountIntent, in context: Context, completion: @escaping (Entry) -> Void) {

+ 53 - 36
Widget/Files/FilesWidgetView.swift

@@ -38,7 +38,22 @@ struct FilesWidgetView: View {
         let linkActionVoiceMemo: URL = URL(string: NCGlobal.shared.widgetActionVoiceMemo + parameterLink) != nil ? URL(string: NCGlobal.shared.widgetActionVoiceMemo + parameterLink)! : URL(string: NCGlobal.shared.widgetActionVoiceMemo)!
 
         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() {
@@ -52,46 +67,48 @@ struct FilesWidgetView: 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.url) {
-                                
-                                HStack {
-
-                                    Image(uiImage: element.image)
-                                        .resizable()
-                                        .scaledToFill()
-                                        .frame(width: 35, height: 35)
-                                        .clipped()
-                                        .cornerRadius(5)
-                                    
-                                    VStack(alignment: .leading, spacing: 2) {
-                                        
-                                        Text(element.title)
-                                            .font(.system(size: 12))
-                                            .fontWeight(.regular)
-                                        
-                                        Text(element.subTitle)
-                                            .font(.system(size: CGFloat(10)))
-                                            .foregroundColor(Color(.systemGray))
+
+                if !entry.isEmpty {
+                    VStack(alignment: .leading) {
+
+                        VStack(spacing: 0) {
+
+                            ForEach(entry.datas, id: \.id) { element in
+
+                                Link(destination: element.url) {
+
+                                    HStack {
+
+                                        Image(uiImage: element.image)
+                                            .resizable()
+                                            .scaledToFill()
+                                            .frame(width: 35, height: 35)
+                                            .clipped()
+                                            .cornerRadius(5)
+
+                                        VStack(alignment: .leading, spacing: 2) {
+
+                                            Text(element.title)
+                                                .font(.system(size: 12))
+                                                .fontWeight(.regular)
+
+                                            Text(element.subTitle)
+                                                .font(.system(size: CGFloat(10)))
+                                                .foregroundColor(Color(.systemGray))
+                                        }
+                                        Spacer()
                                     }
-                                    Spacer()
+                                    .padding(.leading, 10)
+                                    .frame(height: 50)
                                 }
-                                .padding(.leading, 10)
-                                .frame(height: 50)
+                                Divider()
+                                    .padding(.leading, 54)
                             }
-                            Divider()
-                                .padding(.leading, 54)
                         }
                     }
+                    .padding(.top, 30)
+                    .redacted(reason: entry.isPlaceholder ? .placeholder : [])
                 }
-                .padding(.top, 30)
-                .redacted(reason: entry.isPlaceholder ? .placeholder : [])
 
                 HStack(spacing: 0) {
 
@@ -170,7 +187,7 @@ struct FilesWidgetView: View {
 struct FilesWidget_Previews: PreviewProvider {
     static var previews: some View {
         let datas = Array(filesDatasTest[0...4])
-        let entry = FilesDataEntry(date: Date(), datas: datas, isPlaceholder: false, userId: "", url: "", tile: "Good afternoon, Marino Faggiana", footerImage: "checkmark.icloud", footerText: "Nextcloud files")
+        let entry = FilesDataEntry(date: Date(), datas: datas, isPlaceholder: false, isEmpty: true, userId: "", url: "", tile: "Good afternoon, Marino Faggiana", footerImage: "checkmark.icloud", footerText: "Nextcloud files")
         FilesWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }