Browse Source

first test

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
d007ca2874

+ 9 - 26
Widget/Dashboard/DashboardData.swift

@@ -30,6 +30,7 @@ struct DashboardDataEntry: TimelineEntry {
     let date: Date
     let datas: [DashboardData]
     let isPlaceholder: Bool
+    let titleImage: UIImage
     let title: String
     let footerImage: String
     let footerText: String
@@ -52,36 +53,18 @@ let dashboardDatasTest: [DashboardData] = [
     .init(id: "6", image: UIImage(named: "nextcloud")!, title: "title6", subTitle: "subTitle-description6", url: URL(string: "https://nextcloud.com/")!)
 ]
 
-func getTitleDashboard() -> String {
-
-    let hour = Calendar.current.component(.hour, from: Date())
-    var good = ""
-
-    switch hour {
-    case 6..<12: good = NSLocalizedString("_good_morning_", value: "Good morning", comment: "")
-    case 12: good = NSLocalizedString("_good_noon_", value: "Good noon", comment: "")
-    case 13..<17: good = NSLocalizedString("_good_afternoon_", value: "Good afternoon", comment: "")
-    case 17..<22: good = NSLocalizedString("_good_evening_", value: "Good evening", comment: "")
-    default: good = NSLocalizedString("_good_night_", value: "Good night", comment: "")
-    }
-
-    if let account = NCManageDatabase.shared.getActiveAccount() {
-        return good + ", " + account.displayName
-    } else {
-        return good
-    }
-}
-
 func getDashboardDataEntry(isPreview: Bool, displaySize: CGSize, completion: @escaping (_ entry: DashboardDataEntry) -> Void) {
 
     let datasPlaceholder = Array(dashboardDatasTest[0...dashboaardItems - 1])
+    let title = "Dashboard"
+    let titleImage = UIImage(named: "nextcloud")!
     
     if isPreview {
-        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, title: getTitleDashboard(), footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
+        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
     }
 
     guard let account = NCManageDatabase.shared.getActiveAccount() else {
-        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, title: getTitleDashboard(), footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
+        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
     }
     
     // NETWORKING
@@ -111,7 +94,7 @@ func getDashboardDataEntry(isPreview: Bool, displaySize: CGSize, completion: @es
         NKCommon.shared.writeLog("Start \(NCBrandOptions.shared.brand) dashboard widget session with level \(levelLog) " + versionNextcloudiOS)
     }
     
-    NextcloudKit.shared.getDashboard { account, dashboardResults, json, error in
+    NextcloudKit.shared.getDashboard(widgets: "recommendations") { account, dashboardResults, json, error in
         
         var datas = [DashboardData]()
         
@@ -127,11 +110,11 @@ func getDashboardDataEntry(isPreview: Bool, displaySize: CGSize, completion: @es
         }
         
         if error != .success {
-            completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, title: getTitleDashboard(), footerImage: "xmark.icloud", footerText: error.errorDescription))
+            completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "xmark.icloud", footerText: error.errorDescription))
         } else if datas.isEmpty {
-            completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, title: getTitleDashboard(), footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
+            completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
         } else {
-            completion(DashboardDataEntry(date: Date(), datas: datas, isPlaceholder: false, title: getTitleDashboard(), footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
+            completion(DashboardDataEntry(date: Date(), datas: datas, isPlaceholder: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
         }
     }
 }

+ 3 - 1
Widget/Dashboard/DashboardWidgetProvider.swift

@@ -30,7 +30,9 @@ struct DashboardWidgetProvider: TimelineProvider {
 
     func placeholder(in context: Context) -> Entry {
         let datasPlaceholder = Array(dashboardDatasTest[0...nextcloudItems - 1])
-        return Entry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, title: getTitleDashboard(), footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " widget")
+        let title = "Dashboard"
+        let titleImage = UIImage(named: "nextcloud")!
+        return Entry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " widget")
     }
 
     func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {

+ 3 - 1
Widget/Dashboard/DashboardWidgetView.swift

@@ -69,7 +69,9 @@ struct DashboardWidgetView: View {
 struct DashboardWidget_Previews: PreviewProvider {
     static var previews: some View {
         let datas = Array(dashboardDatasTest[0...3])
-        let entry = DashboardDataEntry(date: Date(), datas: datas, isPlaceholder: false, title: "Dashboard", footerImage: "checkmark.icloud", footerText: "Nextcloud widget")
+        let title = "Dashboard"
+        let titleImage = UIImage(named: "nextcloud")!
+        let entry = DashboardDataEntry(date: Date(), datas: datas, isPlaceholder: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: "Nextcloud widget")
         DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }

+ 4 - 13
iOSClient/Networking/NCService.swift

@@ -251,19 +251,10 @@ class NCService: NSObject {
             //TODO: Test DASHBOARD
             /*
             if #available(iOS 15.0, *) {
-                NextcloudKit.shared.getDashboard { request in
-                } completion: { dashboardResults, json, errorCode, errorDescription in
-                    if let dashboardResults = dashboardResults {
-                        for result in dashboardResults {
-                            for entry in result.dashboardEntries ?? [] {
-                                if let url = URL(string: entry.iconUrl) {
-                                    NextcloudKit.shared.getPreview(url: url) { account, data, errorCode, errorDescription in
-
-                                    }
-                                }
-                            }
-                        }
-                    }
+                let widgets = "recommendations"
+                //let options = NKRequestOptions(endpoint: "https://e2e.kaminsky.me/ocs/v2.php/apps/dashboard/api/v1/widget-items?widgets%5B%5D=recommendations")
+                NextcloudKit.shared.getDashboard(widgets: widgets) { account, dashboardResults, json, error in
+                    print("")
                 }
             }
             */