Browse Source

Theming color

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 years ago
parent
commit
fc13471fc0

+ 1 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -3277,7 +3277,7 @@
 			isa = XCRemoteSwiftPackageReference;
 			repositoryURL = "https://github.com/nextcloud/ios-communication-library/";
 			requirement = {
-				branch = unifiedsearchimprovement;
+				branch = develop;
 				kind = branch;
 			};
 		};

+ 0 - 3
iOSClient/AppDelegate.swift

@@ -306,9 +306,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // Registeration push notification
         NCPushNotification.shared().pushNotification()
 
-        // Setting Theming
-        NCBrandColor.shared.settingThemingColor(account: account)
-
         // Start Auto Upload
         NCAutoUpload.shared.initAutoUpload(viewController: nil) { _ in }
 

+ 2 - 7
iOSClient/Brand/NCBrand.swift

@@ -403,9 +403,7 @@ class NCBrandColor: NSObject {
         if NCBrandOptions.shared.use_themingColor {
 
             let themingColor = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColor)
-
             let themingColorElement = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement)
-
             let themingColorText = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorText)
 
             settingBrandColor(themingColor, themingColorElement: themingColorElement, themingColorText: themingColorText)
@@ -437,11 +435,8 @@ class NCBrandColor: NSObject {
             NCBrandColor.shared.brand = NCBrandColor.shared.customer
             NCBrandColor.shared.brandText = NCBrandColor.shared.customerText
         }
-
-        DispatchQueue.main.async {
-            self.createImagesThemingColor()
-            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeTheming)
-        }
+        
+        createImagesThemingColor()
     }
     #endif
 

+ 1 - 0
iOSClient/Files/NCFiles.swift

@@ -99,6 +99,7 @@ class NCFiles: NCCollectionViewCommon {
             searchResults: self.searchResults)
 
         DispatchQueue.main.async {
+            self.changeTheming()
             self.refreshControl.endRefreshing()
             self.collectionView.reloadData()
         }

+ 6 - 5
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -135,7 +135,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         // Notification
 
         NotificationCenter.default.addObserver(self, selector: #selector(initialize), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterInitialize), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(changeThemingWithReloadData), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
 
         changeTheming()
     }
@@ -181,7 +181,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         navigationController?.setNavigationBarHidden(false, animated: true)
         setNavigationItem()
 
-        changeTheming()
         reloadDataSource()
     }
 
@@ -287,9 +286,13 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
 
         setNavigationItem()
         reloadDataSource()
-        changeTheming()
     }
 
+    @objc func changeThemingWithReloadData() {
+        changeTheming()
+        self.collectionView.reloadData()
+    }
+    
     @objc func changeTheming() {
 
         view.backgroundColor = NCBrandColor.shared.systemBackground
@@ -336,8 +339,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                 collectionView.backgroundColor = NCBrandColor.shared.systemBackground
             }
         }
-
-        collectionView.reloadData()
     }
 
     @objc func reloadDataSource(_ notification: NSNotification) {

+ 80 - 84
iOSClient/Networking/NCService.swift

@@ -80,8 +80,7 @@ class NCService: NSObject {
     }
 
     private func requestUserProfile() {
-
-        if appDelegate.account == "" { return }
+        guard !appDelegate.account.isEmpty else { return }
 
         NCCommunication.shared.getUserProfile(queue: NCCommunicationCommon.shared.backgroundQueue) { account, userProfile, errorCode, errorDescription in
 
@@ -143,116 +142,113 @@ class NCService: NSObject {
     }
 
     private func requestServerCapabilities() {
-
-        if appDelegate.account == "" { return }
+        guard !appDelegate.account.isEmpty else { return }
 
         NCCommunication.shared.getCapabilities(queue: NCCommunicationCommon.shared.backgroundQueue) { account, data, errorCode, errorDescription in
 
-            if errorCode == 0 && data != nil {
+            let themingColor = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColor)
+            let themingColorElement = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement)
+            let themingColorText = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorText)
 
-                NCManageDatabase.shared.addCapabilitiesJSon(data!, account: account)
+            guard errorCode == 0, let data = data else {
+                if errorCode == 401 || errorCode == 403 {
+                    NCBrandColor.shared.settingThemingColor(account: account)
+                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeTheming)
+                    
+                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, errorCode: errorCode, errorDescription: errorDescription)
+                }
+                return
+            }
 
-                let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
+            NCManageDatabase.shared.addCapabilitiesJSon(data, account: account)
+            let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
 
-                // Setup communication
-                if serverVersionMajor > 0 {
-                    NCCommunicationCommon.shared.setup(nextcloudVersion: serverVersionMajor)
-                }
-                NCCommunicationCommon.shared.setup(webDav: NCUtilityFileSystem.shared.getWebDAV(account: account))
+            // Setup communication
+            if serverVersionMajor > 0 {
+                NCCommunicationCommon.shared.setup(nextcloudVersion: serverVersionMajor)
+            }
+            NCCommunicationCommon.shared.setup(webDav: NCUtilityFileSystem.shared.getWebDAV(account: account))
 
-                // Theming
+            // Theming
+            let themingColorNew = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColor)
+            let themingColorElementNew = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorElement)
+            let themingColorTextNew = NCManageDatabase.shared.getCapabilitiesServerString(account: account, elements: NCElementsJSON.shared.capabilitiesThemingColorText)
+            if themingColorNew != themingColor || themingColorElementNew != themingColorElement || themingColorTextNew != themingColorText {
                 NCBrandColor.shared.settingThemingColor(account: account)
+                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeTheming)
+            }
 
-                // File Sharing
-                let isFilesSharingEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
-                if isFilesSharingEnabled {
-                    NCCommunication.shared.readShares(parameters: NCCShareParameter(), queue: NCCommunicationCommon.shared.backgroundQueue) { account, shares, errorCode, errorDescription in
-                        if errorCode == 0 {
-                            NCManageDatabase.shared.deleteTableShare(account: account)
-                            if shares != nil {
-                                NCManageDatabase.shared.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares!)
-                            }
-                            self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: account)
-                        } else {
-                            NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+            // File Sharing
+            let isFilesSharingEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
+            if isFilesSharingEnabled {
+                NCCommunication.shared.readShares(parameters: NCCShareParameter(), queue: NCCommunicationCommon.shared.backgroundQueue) { account, shares, errorCode, errorDescription in
+                    if errorCode == 0 {
+                        NCManageDatabase.shared.deleteTableShare(account: account)
+                        if shares != nil {
+                            NCManageDatabase.shared.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares!)
                         }
+                        self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: account)
+                    } else {
+                        NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
                     }
                 }
+            }
 
-                let comments = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFilesComments, exists: false)
-                let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesActivity)
-
-                if !isFilesSharingEnabled && !comments && activity == nil {
-                    self.appDelegate.disableSharesView = true
-                } else {
-                    self.appDelegate.disableSharesView = false
-                }
+            let comments = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesFilesComments, exists: false)
+            let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesActivity)
 
-                // Text direct editor detail
-                if serverVersionMajor >= NCGlobal.shared.nextcloudVersion18 {
-                    NCCommunication.shared.NCTextObtainEditorDetails(queue: NCCommunicationCommon.shared.backgroundQueue) { account, editors, creators, errorCode, _ in
-                        if errorCode == 0 && account == self.appDelegate.account {
-                            NCManageDatabase.shared.addDirectEditing(account: account, editors: editors, creators: creators)
-                        }
-                    }
-                }
+            if !isFilesSharingEnabled && !comments && activity == nil {
+                self.appDelegate.disableSharesView = true
+            } else {
+                self.appDelegate.disableSharesView = false
+            }
 
-                // External file Server
-                let isExternalSitesServerEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesExternalSitesExists, exists: true)
-                if isExternalSitesServerEnabled {
-                    NCCommunication.shared.getExternalSite(queue: NCCommunicationCommon.shared.backgroundQueue) { account, externalSites, errorCode, _ in
-                        if errorCode == 0 && account == self.appDelegate.account {
-                            NCManageDatabase.shared.deleteExternalSites(account: account)
-                            for externalSite in externalSites {
-                                NCManageDatabase.shared.addExternalSites(externalSite, account: account)
-                            }
-                        }
+            // Text direct editor detail
+            if serverVersionMajor >= NCGlobal.shared.nextcloudVersion18 {
+                NCCommunication.shared.NCTextObtainEditorDetails(queue: NCCommunicationCommon.shared.backgroundQueue) { account, editors, creators, errorCode, _ in
+                    if errorCode == 0 && account == self.appDelegate.account {
+                        NCManageDatabase.shared.addDirectEditing(account: account, editors: editors, creators: creators)
                     }
-
-                } else {
-                    NCManageDatabase.shared.deleteExternalSites(account: account)
                 }
+            }
 
-                // User Status
-                let userStatus = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesUserStatusEnabled, exists: false)
-                if userStatus {
-                    NCCommunication.shared.getUserStatus(queue: NCCommunicationCommon.shared.backgroundQueue) { account, clearAt, icon, message, messageId, messageIsPredefined, status, statusIsUserDefined, userId, errorCode, _ in
-                        if errorCode == 0 && account == self.appDelegate.account && userId == self.appDelegate.userId {
-                            NCManageDatabase.shared.setAccountUserStatus(userStatusClearAt: clearAt, userStatusIcon: icon, userStatusMessage: message, userStatusMessageId: messageId, userStatusMessageIsPredefined: messageIsPredefined, userStatusStatus: status, userStatusStatusIsUserDefined: statusIsUserDefined, account: account)
+            // External file Server
+            let isExternalSitesServerEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesExternalSitesExists, exists: true)
+            if isExternalSitesServerEnabled {
+                NCCommunication.shared.getExternalSite(queue: NCCommunicationCommon.shared.backgroundQueue) { account, externalSites, errorCode, _ in
+                    if errorCode == 0 && account == self.appDelegate.account {
+                        NCManageDatabase.shared.deleteExternalSites(account: account)
+                        for externalSite in externalSites {
+                            NCManageDatabase.shared.addExternalSites(externalSite, account: account)
                         }
                     }
                 }
+            } else {
+                NCManageDatabase.shared.deleteExternalSites(account: account)
+            }
 
-                // Added UTI for Collabora
-                if let richdocumentsMimetypes = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) {
-                    for mimeType in richdocumentsMimetypes {
-                        NCCommunicationCommon.shared.addInternalTypeIdentifier(typeIdentifier: mimeType, classFile: NCCommunicationCommon.typeClassFile.document.rawValue, editor: NCGlobal.shared.editorCollabora, iconName: NCCommunicationCommon.typeIconFile.document.rawValue, name: "document")
+            // User Status
+            let userStatus = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesUserStatusEnabled, exists: false)
+            if userStatus {
+                NCCommunication.shared.getUserStatus(queue: NCCommunicationCommon.shared.backgroundQueue) { account, clearAt, icon, message, messageId, messageIsPredefined, status, statusIsUserDefined, userId, errorCode, _ in
+                    if errorCode == 0 && account == self.appDelegate.account && userId == self.appDelegate.userId {
+                        NCManageDatabase.shared.setAccountUserStatus(userStatusClearAt: clearAt, userStatusIcon: icon, userStatusMessage: message, userStatusMessageId: messageId, userStatusMessageIsPredefined: messageIsPredefined, userStatusStatus: status, userStatusStatusIsUserDefined: statusIsUserDefined, account: account)
                     }
                 }
+            }
 
-                // Added UTI for ONLYOFFICE & Text
-                if let directEditingCreators = NCManageDatabase.shared.getDirectEditingCreators(account: account) {
-                    for directEditing in directEditingCreators {
-                        NCCommunicationCommon.shared.addInternalTypeIdentifier(typeIdentifier: directEditing.mimetype, classFile: NCCommunicationCommon.typeClassFile.document.rawValue, editor: directEditing.editor, iconName: NCCommunicationCommon.typeIconFile.document.rawValue, name: "document")
-                    }
+            // Added UTI for Collabora
+            if let richdocumentsMimetypes = NCManageDatabase.shared.getCapabilitiesServerArray(account: account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) {
+                for mimeType in richdocumentsMimetypes {
+                    NCCommunicationCommon.shared.addInternalTypeIdentifier(typeIdentifier: mimeType, classFile: NCCommunicationCommon.typeClassFile.document.rawValue, editor: NCGlobal.shared.editorCollabora, iconName: NCCommunicationCommon.typeIconFile.document.rawValue, name: "document")
                 }
+            }
 
-                //                    Handwerkcloud
-                //                    let isHandwerkcloudEnabled = NCManageDatabase.shared.getCapabilitiesServerBool(account: account, elements: NCElementsJSON.shared.capabilitiesHWCEnabled, exists: false)
-                //                    if (isHandwerkcloudEnabled) {
-                //                        self.requestHC()
-                //                    }
-
-            } else if errorCode != 0 {
-
-                NCBrandColor.shared.settingThemingColor(account: account)
-
-                if errorCode == 401 || errorCode == 403 {
-                    NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, errorCode: errorCode, errorDescription: errorDescription)
+            // Added UTI for ONLYOFFICE & Text
+            if let directEditingCreators = NCManageDatabase.shared.getDirectEditingCreators(account: account) {
+                for directEditing in directEditingCreators {
+                    NCCommunicationCommon.shared.addInternalTypeIdentifier(typeIdentifier: directEditing.mimetype, classFile: NCCommunicationCommon.typeClassFile.document.rawValue, editor: directEditing.editor, iconName: NCCommunicationCommon.typeIconFile.document.rawValue, name: "document")
                 }
-
-            } else {
-                NCBrandColor.shared.settingThemingColor(account: account)
             }
         }
     }