Browse Source

Revert "change obj db"

This reverts commit a5252d88b17d3444762eef0a6b3d82e0b0dc896f.
Marino Faggiana 2 years ago
parent
commit
93fa521fe9

+ 2 - 2
Widget/Dashboard/DashboardData.swift

@@ -125,7 +125,7 @@ func getDashboardDataEntry(configuration: DashboardIntent?, isPreview: Bool, dis
     }
 
     // Default widget
-    let result = tableDashboardWidget().getDashboardWidgetApplications(account: account.account).first
+    let result = NCManageDatabase.shared.getDashboardWidgetApplications(account: account.account).first
     let id: String = configuration?.applications?.identifier ?? (result?.id ?? "recommendations")
 
     let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
@@ -160,7 +160,7 @@ func getDashboardDataEntry(configuration: DashboardIntent?, isPreview: Bool, dis
         NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Start \(NCBrandOptions.shared.brand) dashboard widget session with level \(levelLog) " + versionNextcloudiOS)
     }
     
-    let (tableDashboard, tableButton) = tableDashboardWidget().getDashboardWidget(account: account.account, id: id)
+    let (tableDashboard, tableButton) = NCManageDatabase.shared.getDashboardWidget(account: account.account, id: id)
     let existsButton = (tableButton?.isEmpty ?? true) ? false : true
     let title = tableDashboard?.title ?? id
 

+ 2 - 2
WidgetDashboardIntentHandler/IntentHandler.swift

@@ -65,7 +65,7 @@ class IntentHandler: INExtension, DashboardIntentHandling, AccountIntentHandling
             return completion(nil, nil)
         }
 
-        let results = tableDashboardWidget().getDashboardWidgetApplications(account: account.account)
+        let results = NCManageDatabase.shared.getDashboardWidgetApplications(account: account.account)
         for result in results {
             let application = Applications(identifier: result.id, display: result.title)
             applications.append(application)
@@ -79,7 +79,7 @@ class IntentHandler: INExtension, DashboardIntentHandling, AccountIntentHandling
         guard let account = NCManageDatabase.shared.getActiveAccount() else {
             return nil
         }
-        if let result = tableDashboardWidget().getDashboardWidgetApplications(account: account.account).first {
+        if let result = NCManageDatabase.shared.getDashboardWidgetApplications(account: account.account).first {
             return Applications(identifier: result.id, display: result.title)
         }
         return nil

+ 13 - 10
iOSClient/Data/NCManageDatabase+DashboardWidget.swift

@@ -25,16 +25,6 @@ import Foundation
 import RealmSwift
 import NextcloudKit
 
-class tableDashboardWidgetButton: Object {
-
-    @Persisted(primaryKey: true) var index = ""
-    @Persisted var account = ""
-    @Persisted var id = ""
-    @Persisted var type = ""
-    @Persisted var text = ""
-    @Persisted var link = ""
-}
-
 class tableDashboardWidget: Object {
 
     @Persisted(primaryKey: true) var index = ""
@@ -46,6 +36,19 @@ class tableDashboardWidget: Object {
     @Persisted var iconUrl: String?
     @Persisted var widgetUrl: String?
     @Persisted var itemIconsRound: Bool = false
+}
+
+class tableDashboardWidgetButton: Object {
+
+    @Persisted(primaryKey: true) var index = ""
+    @Persisted var account = ""
+    @Persisted var id = ""
+    @Persisted var type = ""
+    @Persisted var text = ""
+    @Persisted var link = ""
+}
+
+extension NCManageDatabase {
 
     func getDashboardWidget(account: String, id: String) -> (tableDashboardWidget?, [tableDashboardWidgetButton]?) {
      

+ 1 - 1
iOSClient/Networking/NCService.swift

@@ -284,7 +284,7 @@ class NCService: NSObject {
         NextcloudKit.shared.getDashboardWidget(options: options) { account, dashboardWidgets, data, error in
             Task {
                 if error == .success, let dashboardWidgets = dashboardWidgets  {
-                    tableDashboardWidget().addDashboardWidget(account: account, dashboardWidgets: dashboardWidgets)
+                    NCManageDatabase.shared.addDashboardWidget(account: account, dashboardWidgets: dashboardWidgets)
                     for widget in dashboardWidgets {
                         if let url = URL(string: widget.iconUrl), let fileName = widget.iconClass {
                             let (_, data, error) = await NextcloudKit.shared.getPreview(url: url)