Browse Source

coding

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

+ 14 - 5
Widget/Dashboard/DashboardData.swift

@@ -60,15 +60,13 @@ let dashboardDatasTest: [DashboardData] = [
 func getDashboardDataEntry(isPreview: Bool, displaySize: CGSize, completion: @escaping (_ entry: DashboardDataEntry) -> Void) {
 
     let datasPlaceholder = Array(dashboardDatasTest[0...dashboaardItems - 1])
-    var title = "Dashboard"
-    var titleImage = UIImage(named: "nextcloud")!
     
     if isPreview {
-        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
+        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: UIImage(named: "nextcloud")!, title: "Dashboard", footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
     }
 
     guard let account = NCManageDatabase.shared.getActiveAccount() else {
-        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: "")))
+        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: UIImage(named: "nextcloud")!, title: "Dashboard", footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
     }
     
     // NETWORKING
@@ -98,8 +96,19 @@ func getDashboardDataEntry(isPreview: Bool, displaySize: CGSize, completion: @es
         NKCommon.shared.writeLog("Start \(NCBrandOptions.shared.brand) dashboard widget session with level \(levelLog) " + versionNextcloudiOS)
     }
     
-    title = "recommendations"
+    let id = "recommendations"
+    let result = NCManageDatabase.shared.getDashboardWidget(account: account.account, id: id)
     
+    let title = result?.title ?? id
+    var titleImage = UIImage()
+
+    if let fileName = result?.iconClass {
+        let fileNamePath: String = CCUtility.getDirectoryUserData() + "/" + fileName + ".png"
+        if let image = UIImage(contentsOfFile: fileNamePath) {
+            titleImage = image.imageColor(NCBrandColor.shared.label)
+        }
+    }
+
     NextcloudKit.shared.getDashboardWidgetsApplication(title) { account, results, data, error in
         
         var datas = [DashboardData]()

+ 11 - 1
iOSClient/Data/NCManageDatabase+DashboardWidget.swift

@@ -27,7 +27,17 @@ import NextcloudKit
 
 extension NCManageDatabase {
 
-    func addDasboardWidget(account: String, dashboardWidgets: [NCCDashboardWidget]) {
+    func getDashboardWidget(account: String, id: String) -> tableDashboardWidget? {
+     
+        let realm = try! Realm()
+        guard let result = realm.objects(tableDashboardWidget.self).filter("account == %@ AND id == %@", account, id).first else {
+            return nil
+        }
+        
+        return tableDashboardWidget.init(value: result)
+    }
+    
+    func addDashboardWidget(account: String, dashboardWidgets: [NCCDashboardWidget]) {
         
         let realm = try! Realm()
 

+ 3 - 1
iOSClient/Data/NCManageDatabase.swift

@@ -70,7 +70,7 @@ class NCManageDatabase: NSObject {
             let config = Realm.Configuration(
                 fileURL: dirGroup?.appendingPathComponent(NCGlobal.shared.appDatabaseNextcloud + "/" + NCGlobal.shared.databaseDefault),
                 schemaVersion: NCGlobal.shared.databaseSchemaVersion,
-                objectTypes: [tableMetadata.self, tableLocalFile.self, tableDirectory.self, tableTag.self, tableAccount.self, tableCapabilities.self, tablePhotoLibrary.self, tableE2eEncryption.self, tableE2eEncryptionLock.self, tableShare.self, tableChunk.self, tableAvatar.self]
+                objectTypes: [tableMetadata.self, tableLocalFile.self, tableDirectory.self, tableTag.self, tableAccount.self, tableCapabilities.self, tablePhotoLibrary.self, tableE2eEncryption.self, tableE2eEncryptionLock.self, tableShare.self, tableChunk.self, tableAvatar.self, tableDashboardWidget.self, tableDashboardWidgetButton.self]
             )
 
             Realm.Configuration.defaultConfiguration = config
@@ -259,6 +259,8 @@ class NCManageDatabase: NSObject {
         self.clearTable(tableCapabilities.self, account: account)
         self.clearTable(tableChunk.self, account: account)
         self.clearTable(tableComments.self, account: account)
+        self.clearTable(tableDashboardWidget.self, account: account)
+        self.clearTable(tableDashboardWidgetButton.self, account: account)
         self.clearTable(tableDirectEditingCreators.self, account: account)
         self.clearTable(tableDirectEditingEditors.self, account: account)
         self.clearTable(tableDirectory.self, account: account)

+ 1 - 1
iOSClient/Networking/NCService.swift

@@ -274,7 +274,7 @@ class NCService: NSObject {
 
         NextcloudKit.shared.getDashboardWidget(options: options) { account, dashboardWidgets, data, error in
             if error == .success, let dashboardWidgets = dashboardWidgets  {
-                NCManageDatabase.shared.addDasboardWidget(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 {
                         NCUtility.shared.getImageUserData(url: url, fileName: fileName, size: 128)