Browse Source

Update `loadUserImage(for:)`

`userUrlBase` is needed, to load the image for the right server (and from the right account).

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
facb944baf

+ 4 - 1
Share/NCShareExtension.swift

@@ -263,7 +263,10 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
 
 
         // PROFILE BUTTON
         // PROFILE BUTTON
 
 
-        let image = NCUtility.shared.loadUserImage(for: activeAccount.user, displayName: activeAccount.displayName, urlBase: activeAccount.urlBase)
+        let image = NCUtility.shared.loadUserImage(
+            for: activeAccount.user,
+               displayName: activeAccount.displayName,
+               userUrlBase: String(CCUtility.getUserUrlBase(activeAccount.user, urlBase: activeAccount.urlBase)))
 
 
         let profileButton = UIButton(type: .custom)
         let profileButton = UIButton(type: .custom)
         profileButton.setImage(image, for: .normal)
         profileButton.setImage(image, for: .normal)

+ 4 - 1
iOSClient/Main/Account Request/NCAccountRequest.swift

@@ -236,7 +236,10 @@ extension NCAccountRequest: UITableViewDataSource {
         
         
             let account = accounts[indexPath.row]
             let account = accounts[indexPath.row]
 
 
-            avatarImage?.image = NCUtility.shared.loadUserImage(for: account.user, displayName: account.displayName, urlBase: account.urlBase)
+            avatarImage?.image = NCUtility.shared.loadUserImage(
+                for: account.user,
+                   displayName: account.displayName,
+                   userUrlBase: String(CCUtility.getUserUrlBase(account.user, urlBase: account.urlBase)))
 
 
             if account.alias != "" {
             if account.alias != "" {
                 userLabel?.text = account.alias.uppercased()
                 userLabel?.text = account.alias.uppercased()

+ 4 - 1
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -599,7 +599,10 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             if layoutKey == NCGlobal.shared.layoutViewFiles {
             if layoutKey == NCGlobal.shared.layoutViewFiles {
                 let activeAccount = NCManageDatabase.shared.getActiveAccount()
                 let activeAccount = NCManageDatabase.shared.getActiveAccount()
 
 
-                let image = NCUtility.shared.loadUserImage(for: appDelegate.user, displayName: activeAccount?.displayName, urlBase: appDelegate.urlBase)
+                let image = NCUtility.shared.loadUserImage(
+                    for: appDelegate.user,
+                       displayName: activeAccount?.displayName,
+                       userUrlBase: String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)))
 
 
                 let button = UIButton(type: .custom)
                 let button = UIButton(type: .custom)
                 button.setImage(image, for: .normal)
                 button.setImage(image, for: .normal)

+ 4 - 1
iOSClient/Menu/NCLoginWeb+Menu.swift

@@ -37,7 +37,10 @@ extension NCLoginWeb {
             
             
             let title = account.user + " " + (URL(string: account.urlBase)?.host ?? "")
             let title = account.user + " " + (URL(string: account.urlBase)?.host ?? "")
 
 
-            avatar = NCUtility.shared.loadUserImage(for: account.user, displayName: account.displayName, urlBase: account.urlBase)
+            avatar = NCUtility.shared.loadUserImage(
+                for: account.user,
+                   displayName: account.displayName,
+                   userUrlBase: String(CCUtility.getUserUrlBase(account.user, urlBase: account.urlBase)))
 
 
             actions.append(
             actions.append(
                 NCMenuAction(
                 NCMenuAction(

+ 5 - 2
iOSClient/Menu/UIViewController+Menu.swift

@@ -68,7 +68,10 @@ extension UIViewController {
 
 
             let personHeader = NCMenuAction(
             let personHeader = NCMenuAction(
                 title: card.displayName,
                 title: card.displayName,
-                icon: NCUtility.shared.loadUserImage(for: userId, displayName: card.displayName, urlBase: appDelegate.urlBase),
+                icon: NCUtility.shared.loadUserImage(
+                    for: userId,
+                       displayName: card.displayName,
+                       userUrlBase: String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase))),
                 action: nil)
                 action: nil)
 
 
             let actions = card.actions.map { action -> NCMenuAction in
             let actions = card.actions.map { action -> NCMenuAction in
@@ -76,7 +79,7 @@ extension UIViewController {
                 if let url = URL(string: action.icon),
                 if let url = URL(string: action.icon),
                    let svgSource = SVGKSourceURL.source(from: url),
                    let svgSource = SVGKSourceURL.source(from: url),
                    let svg = SVGKImage(source: svgSource) {
                    let svg = SVGKImage(source: svgSource) {
-                    image = svg.uiImage
+                    image = svg.uiImage.imageColor(NCBrandColor.shared.label)
                 }
                 }
                 return NCMenuAction(
                 return NCMenuAction(
                     title: action.title,
                     title: action.title,

+ 5 - 2
iOSClient/More/NCMore.swift

@@ -323,9 +323,12 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
             cell.status.text = ""
             cell.status.text = ""
             cell.displayName.text = ""
             cell.displayName.text = ""
 
 
-            cell.avatar.image = NCUtility.shared.loadUserImage(for: appDelegate.user, displayName: tabAccount?.displayName, urlBase: appDelegate.urlBase)
-
             if let account = tabAccount {
             if let account = tabAccount {
+                cell.avatar.image = NCUtility.shared.loadUserImage(
+                    for: account.user,
+                       displayName: account.displayName,
+                       userUrlBase: String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)))
+
                 if account.alias == "" {
                 if account.alias == "" {
                     cell.displayName?.text = account.displayName
                     cell.displayName?.text = account.displayName
                 } else {
                 } else {

+ 6 - 5
iOSClient/Networking/NCOperationQueue.swift

@@ -171,12 +171,13 @@ import NCCommunication
             return
             return
         }
         }
 
 
-        if let image = UIImage(contentsOfFile: fileNameLocalPath) {
-            cell.fileAvatarImageView?.image = image
-        } else {
-            cell.fileAvatarImageView?.image = placeholder
+        if let account = NCManageDatabase.shared.getActiveAccount() {
+            cell.fileAvatarImageView?.image = NCUtility.shared.loadUserImage(
+                for: user,
+                   displayName: nil,
+                   userUrlBase: String(CCUtility.getUserUrlBase(account.user, urlBase: account.urlBase)))
         }
         }
-        
+
         for operation in downloadAvatarQueue.operations as! [NCOperationDownloadAvatar] {
         for operation in downloadAvatarQueue.operations as! [NCOperationDownloadAvatar] {
             if operation.fileName == fileName {
             if operation.fileName == fileName {
                 return
                 return

+ 12 - 10
iOSClient/Utility/NCUtility.swift

@@ -496,19 +496,21 @@ class NCUtility: NSObject {
         return  UIImage(named: "file")!.image(color: color, size: size)
         return  UIImage(named: "file")!.image(color: color, size: size)
     }
     }
     
     
-    func loadUserImage(for user: String, displayName: String?, urlBase: String) -> UIImage {
-        var image: UIImage?
-        
-        let fileName = String(CCUtility.getUserUrlBase(user, urlBase: urlBase)) + "-" + user + "-original.png"
+    func loadUserImage(for user: String, displayName: String?, userUrlBase: String, original: Bool = false) -> UIImage {
+
+        //@marino: I'm not even sure the original is needed.. seems to work just fine with the 'normal' one
+        let fileName = userUrlBase + "-" + user + (original ? "-original.png" : ".png")
         let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
         let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
-        if let imageUser = UIImage(contentsOfFile: fileNameLocalPath) {
-            image = NCUtility.shared.createAvatar(image: imageUser, size: 30)
-        } else if let displayName = displayName, !displayName.isEmpty {
-            image = createAvatar(displayName: displayName, size: 30)
+        
+        if let localImage = UIImage(contentsOfFile: fileNameLocalPath) {
+            return NCUtility.shared.createAvatar(image: localImage, size: 30)
+        } else if let loadedAvatar = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) {
+            return loadedAvatar
+        } else if let displayName = displayName, !displayName.isEmpty, let avatarImg = createAvatar(displayName: displayName, size: 30) {
+            return avatarImg
         } else {
         } else {
-            // fallback to default icon
+            return getDefaultUserIcon()
         }
         }
-        return image ?? getDefaultUserIcon()
     }
     }
     
     
     func getDefaultUserIcon() -> UIImage {
     func getDefaultUserIcon() -> UIImage {