Эх сурвалжийг харах

fix user avatar request & profileButton tittle + refactoring

Signed-off-by: Henrik Storch <thisisthefoxe@gmail.com>
Henrik Storch 3 жил өмнө
parent
commit
ff2e355963

+ 9 - 22
Share/NCShareExtension.swift

@@ -237,36 +237,23 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
             }
             self.setNavigationBar(navigationTitle: navigationTitle)
         }
-        
+
         // PROFILE BUTTON
-                
-        var image: UIImage?
-        
-        if #available(iOS 13.0, *) {
-            let config = UIImage.SymbolConfiguration(pointSize: 30)
-            image = NCUtility.shared.loadImage(named: "person.crop.circle", symbolConfiguration: config)
-        } else {
-            image = NCUtility.shared.loadImage(named: "person.crop.circle", size: 30)
-        }
-        
-        let fileName = String(CCUtility.getUserUrlBase(activeAccount.user, urlBase: activeAccount.urlBase)) + "-" + activeAccount.user + "-original.png"
-        let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
-        if let imageUser = UIImage(contentsOfFile: fileNameLocalPath) {
-            image = NCUtility.shared.createAvatar(image: imageUser, size: 30)
-        }
-        
+
+        let image = NCUtility.shared.loadUserImage(for: activeAccount.user, urlBase: activeAccount.urlBase)
+
         let profileButton = UIButton(type: .custom)
         profileButton.setImage(image, for: .normal)
-            
+
         if serverUrl == NCUtilityFileSystem.shared.getHomeServer(account: activeAccount.account) {
 
             var title = "  "
-            if activeAccount?.alias == "" {
-                title = title + (activeAccount?.user ?? "")
+            if let userAlias = activeAccount?.alias, !userAlias.isEmpty {
+                title += userAlias
             } else {
-                title = title + (activeAccount?.alias ?? "")
+                title += activeAccount?.displayName ?? ""
             }
-                
+
             profileButton.setTitle(title, for: .normal)
             profileButton.setTitleColor(.systemBlue, for: .normal)
         }

+ 3 - 10
iOSClient/Main/Account Request/NCAccountRequest.swift

@@ -235,16 +235,9 @@ extension NCAccountRequest: UITableViewDataSource {
         } else {
         
             let account = accounts[indexPath.row]
-            
-            let fileName = String(CCUtility.getUserUrlBase(account.user, urlBase: account.urlBase)) + "-" + account.user + ".png"
-            let fileNamePath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
-            
-            if let image = UIImage(contentsOfFile: fileNamePath) {
-                avatarImage?.image = image
-            } else {
-                avatarImage?.image = NCUtility.shared.loadImage(named: "person.crop.circle")
-            }
-                    
+
+            avatarImage?.image = NCUtility.shared.loadUserImage(for: account.user, urlBase: account.urlBase)
+
             if account.alias != "" {
                 userLabel?.text = account.alias.uppercased()
             } else {

+ 9 - 28
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -591,22 +591,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             // PROFILE BUTTON
             
             if layoutKey == NCGlobal.shared.layoutViewFiles {
-            
-                var image: UIImage?
-                
-                if #available(iOS 13.0, *) {
-                    let config = UIImage.SymbolConfiguration(pointSize: 30)
-                    image = NCUtility.shared.loadImage(named: "person.crop.circle", symbolConfiguration: config)
-                } else {
-                    image = NCUtility.shared.loadImage(named: "person.crop.circle", size: 30)
-                }
-                
-                let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + self.appDelegate.user + "-original.png"
-                let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
-                if let imageUser = UIImage(contentsOfFile: fileNameLocalPath) {
-                    image = NCUtility.shared.createAvatar(image: imageUser, size: 30)
-                }
-                
+
+                let image = NCUtility.shared.loadUserImage(for: appDelegate.user, urlBase: appDelegate.urlBase)
+
                 let button = UIButton(type: .custom)
                 button.setImage(image, for: .normal)
                 
@@ -614,17 +601,13 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                  
                     let activeAccount = NCManageDatabase.shared.getActiveAccount()
                     var titleButton = "  "
-                    
-                    if activeAccount?.alias == "" {
-                        titleButton = titleButton + (activeAccount?.user ?? "")
-                    } else {
-                        titleButton = titleButton + (activeAccount?.alias ?? "")
-                    }
-                    
+
                     if getNavigationTitle() == activeAccount?.alias {
                         titleButton = ""
+                    } else {
+                        titleButton += activeAccount?.displayName ?? ""
                     }
-                    
+
                     button.setTitle(titleButton, for: .normal)
                     button.setTitleColor(.systemBlue, for: .normal)
                 }
@@ -662,13 +645,11 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     }
     
     func getNavigationTitle() -> String {
-        
         let activeAccount = NCManageDatabase.shared.getActiveAccount()
-        if activeAccount?.alias == "" {
+        guard let userAlias = activeAccount?.alias, !userAlias.isEmpty else {
             return NCBrandOptions.shared.brand
-        } else {
-            return activeAccount?.alias ?? NCBrandOptions.shared.brand
         }
+        return userAlias
     }
     
     // MARK: - BackgroundImageColor Delegate

+ 3 - 7
iOSClient/Menu/NCLoginWeb+Menu.swift

@@ -37,13 +37,9 @@ extension NCLoginWeb {
         for account in accounts {
             
             let title = account.user + " " + (URL(string: account.urlBase)?.host ?? "")
-            let fileName = String(CCUtility.getUserUrlBase(account.user, urlBase: account.urlBase)) + "-" + account.user + ".png"
-            let fileNamePath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
 
-            if let image = UIImage(contentsOfFile: fileNamePath) {
-                avatar = image
-            }
-            
+            avatar = NCUtility.shared.loadUserImage(for: account.user, urlBase: account.urlBase)
+
             actions.append(
                 NCMenuAction(
                     title: title,
@@ -64,7 +60,7 @@ extension NCLoginWeb {
                 )
             )
         }
-        
+
         actions.append(
             NCMenuAction(
                 title: NSLocalizedString("_delete_active_account_", comment: ""),

+ 3 - 9
iOSClient/More/NCMore.swift

@@ -322,15 +322,9 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
             cell.icon.image = nil
             cell.status.text = ""
             cell.displayName.text = ""
-            
-            let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + self.appDelegate.user + "-original.png"
-            let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
-            if let image = UIImage.init(contentsOfFile: fileNameLocalPath) {
-                cell.avatar?.image = NCUtility.shared.createAvatar(image: image, size: 50)
-            } else {
-                cell.avatar?.image = UIImage.init(named: "avatar")?.imageColor(NCBrandColor.shared.gray)
-            }
-           
+
+            cell.avatar.image = NCUtility.shared.loadUserImage(for: appDelegate.user, urlBase: appDelegate.urlBase)
+
             if let account = tabAccount {
                 if account.alias == "" {
                     cell.displayName?.text = account.displayName

+ 3 - 3
iOSClient/Networking/NCService.swift

@@ -110,9 +110,9 @@ class NCService: NSObject {
                     let fileName = String(CCUtility.getUserUrlBase(user, urlBase: url)) + "-" + self.appDelegate.user + ".png"
                     let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
                     let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
-                    
-                    NCCommunication.shared.downloadAvatar(user: user, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag) { (account, image, imageOriginal, etag, errorCode, errorMessage) in
-                        
+
+                    NCCommunication.shared.downloadAvatar(user: tableAccount.userId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag) { (account, image, imageOriginal, etag, errorCode, errorMessage) in
+
                         if let etag = etag, errorCode == 0, let imageOriginal = imageOriginal {
                             
                             do {

+ 18 - 0
iOSClient/Utility/NCUtility.swift

@@ -39,6 +39,24 @@ class NCUtility: NSObject {
     private var viewActivityIndicator: UIView?
     private var viewBackgroundActivityIndicator: UIView?
 
+    func loadUserImage(for user: String, urlBase: String) -> UIImage {
+        var image: UIImage
+        
+        let fileName = String(CCUtility.getUserUrlBase(user, urlBase: urlBase)) + "-" + user + "-original.png"
+        let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
+        if let imageUser = UIImage(contentsOfFile: fileNameLocalPath) {
+            image = NCUtility.shared.createAvatar(image: imageUser, size: 30)
+        } else {
+            if #available(iOS 13.0, *) {
+                let config = UIImage.SymbolConfiguration(pointSize: 30)
+                image = NCUtility.shared.loadImage(named: "person.crop.circle", symbolConfiguration: config)
+            } else {
+                image = NCUtility.shared.loadImage(named: "person.crop.circle", size: 30)
+            }
+        }
+        return image
+    }
+
     func setLayoutForView(key: String, serverUrl: String, layoutForView: NCGlobal.layoutForViewType) {
         
         let string =  layoutForView.layout + "|" + layoutForView.sort + "|" + "\(layoutForView.ascending)" + "|" + layoutForView.groupBy + "|" + "\(layoutForView.directoryOnTop)" + "|" + layoutForView.titleButtonHeader + "|" + "\(layoutForView.itemForLine)" + "|" + layoutForView.imageBackgroud + "|" + layoutForView.imageBackgroudContentMode