Jelajahi Sumber

widget fix

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 tahun lalu
induk
melakukan
2b7f16cbb0

+ 3 - 3
Widget/Dashboard/DashboardData.swift

@@ -29,7 +29,7 @@ struct DashboardDataEntry: TimelineEntry {
     let date: Date
     let datas: [DashboardData]
     let tableDashboard: tableDashboardWidget?
-    let tableButton: Results<tableDashboardWidgetButton>?
+    let tableButton: [tableDashboardWidgetButton]?
     let isPlaceholder: Bool
     let titleImage: UIImage
     let title: String
@@ -172,8 +172,8 @@ func getDashboardDataEntry(intent: Applications?, isPreview: Bool, displaySize:
 
                                 if let item = CCUtility.value(forKey: "fileId", fromQueryItems: queryItems) {
                                     iconFileName = item
-                                } else if pathComponents[1] == "avatar" {
-                                    iconFileName = pathComponents[2]
+                                } else if pathComponents.contains("avatar") {
+                                    iconFileName = pathComponents[pathComponents.count-2]
                                     avatar = true
                                 } else {
                                     iconFileName = ((path.lastPathComponent) as NSString).deletingPathExtension

+ 6 - 4
iOSClient/Data/NCManageDatabase+DashboardWidget.swift

@@ -27,7 +27,7 @@ import NextcloudKit
 
 extension NCManageDatabase {
 
-    func getDashboardWidget(account: String, id: String) -> (tableDashboardWidget?, Results<tableDashboardWidgetButton>?) {
+    func getDashboardWidget(account: String, id: String) -> (tableDashboardWidget?, [tableDashboardWidgetButton]?) {
      
         let realm = try! Realm()
         guard let resultDashboard = realm.objects(tableDashboardWidget.self).filter("account == %@ AND id == %@", account, id).first else {
@@ -35,13 +35,15 @@ extension NCManageDatabase {
         }
         let resultsButton = realm.objects(tableDashboardWidgetButton.self).filter("account == %@ AND id == %@", account, id).sorted(byKeyPath: "type", ascending: true)
         
-        return (resultDashboard, resultsButton)
+        return (tableDashboardWidget.init(value: resultDashboard), Array(resultsButton.map { tableDashboardWidgetButton.init(value: $0) }))
     }
 
-    func getDashboardWidgetApplications(account: String) -> Results<tableDashboardWidget> {
+    func getDashboardWidgetApplications(account: String) -> [tableDashboardWidget] {
 
         let realm = try! Realm()
-        return realm.objects(tableDashboardWidget.self).filter("account == %@", account).sorted(byKeyPath: "title", ascending: true)
+        let results = realm.objects(tableDashboardWidget.self).filter("account == %@", account).sorted(byKeyPath: "title", ascending: true)
+
+        return Array(results.map { tableDashboardWidget.init(value: $0) })
     }
     
     func addDashboardWidget(account: String, dashboardWidgets: [NCCDashboardWidget]) {