Browse Source

Fix NCShare loading indicator

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

+ 2 - 2
iOSClient/Activity/NCActivity.swift

@@ -249,7 +249,7 @@ extension NCActivity: UITableViewDataSource {
         
         // Image
         let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + comment.actorId + ".png"
-        NCOperationQueue.shared.downloadAvatar(user: comment.actorId, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+        NCOperationQueue.shared.downloadAvatar(user: comment.actorId, fileName: fileName, cell: cell, view: tableView)
         // Username
         cell.labelUser.text = comment.actorDisplayName
         cell.labelUser.textColor = NCBrandColor.shared.label
@@ -315,7 +315,7 @@ extension NCActivity: UITableViewDataSource {
             
             let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + activity.user + ".png"
             
-            NCOperationQueue.shared.downloadAvatar(user: activity.user, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+            NCOperationQueue.shared.downloadAvatar(user: activity.user, fileName: fileName, cell: cell, view: tableView)
         }
         
         // subject

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

@@ -1337,9 +1337,12 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
         }
         
         // Avatar
-        if metadata.ownerId.count > 0 && metadata.ownerId != appDelegate.userId && appDelegate.account == metadata.account {
+        if metadata.ownerId.count > 0,
+           metadata.ownerId != appDelegate.userId,
+           appDelegate.account == metadata.account,
+           let cell = cell as? NCCellProtocol {
             let fileName = String(CCUtility.getUserUrlBase(metadata.user, urlBase: metadata.urlBase)) + "-" + metadata.ownerId + ".png"
-            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, fileName: fileName, placeholder: NCBrandColor.cacheImages.shared, cell: cell, view: collectionView)
+            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, fileName: fileName, cell: cell, view: collectionView)
         }
     }
     

+ 1 - 2
iOSClient/Networking/NCOperationQueue.swift

@@ -161,9 +161,8 @@ import NCCommunication
     
     // Download Avatar
     
-    func downloadAvatar(user: String, fileName: String, placeholder: UIImage?, cell: UIView, view: UIView?) {
+    func downloadAvatar(user: String, fileName: String, cell: NCCellProtocol, view: UIView?) {
 
-        let cell: NCCellProtocol = cell as! NCCellProtocol
         let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
         
         if let image = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) {

+ 1 - 1
iOSClient/Notification/NCNotification.swift

@@ -150,7 +150,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
                         cell.avatar.isHidden = false
                         cell.avatarLeadingMargin.constant = 50
                         cell.fileUser = user
-                        NCOperationQueue.shared.downloadAvatar(user: user, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+                        NCOperationQueue.shared.downloadAvatar(user: user, fileName: fileName, cell: cell, view: tableView)
                     }
                 }
             }

+ 5 - 2
iOSClient/Select/NCSelect.swift

@@ -415,9 +415,12 @@ extension NCSelect: UICollectionViewDataSource {
         }
         
         // Avatar
-        if metadata.ownerId.count > 0 && metadata.ownerId != activeAccount.userId && activeAccount.account == metadata.account {
+        if metadata.ownerId.count > 0,
+           metadata.ownerId != activeAccount.userId,
+           activeAccount.account == metadata.account,
+           let cell = cell as? NCCellProtocol {
             let fileName = String(CCUtility.getUserUrlBase(metadata.user, urlBase: metadata.urlBase)) + "-" + metadata.ownerId + ".png"
-            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, fileName: fileName, placeholder: NCBrandColor.cacheImages.shared, cell: cell, view: collectionView)
+            NCOperationQueue.shared.downloadAvatar(user: metadata.ownerId, fileName: fileName, cell: cell, view: collectionView)
         }
     }
     

+ 20 - 19
iOSClient/Share/NCShare.swift

@@ -93,21 +93,21 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
         NotificationCenter.default.addObserver(self, selector: #selector(reloadData), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterReloadDataNCShare), object: nil)
         
         // Shared with you by ...
-        if metadata!.ownerId != "" && metadata!.ownerId != self.appDelegate.userId {
-            
+        if let metadata = metadata, !metadata.ownerId.isEmpty, metadata.ownerId != self.appDelegate.userId {
+
             searchFieldTopConstraint.constant = 65
             sharedWithYouByView.isHidden = false
-            sharedWithYouByLabel.text = NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata!.ownerDisplayName
+            sharedWithYouByLabel.text = NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata.ownerDisplayName
             sharedWithYouByImage.image = UIImage(named: "avatar")?.imageColor(NCBrandColor.shared.label)
             let shareAction = UITapGestureRecognizer(target: self, action: #selector(openShareProfile))
             sharedWithYouByView.addGestureRecognizer(shareAction)
-            
-            if metadata?.note.count ?? 0 > 0 {
+
+            if metadata.note.count > 0 {
                 searchFieldTopConstraint.constant = 95
                 sharedWithYouByNoteImage.isHidden = false
                 sharedWithYouByNoteImage.image = NCUtility.shared.loadImage(named: "note.text", color: .gray)
                 sharedWithYouByNote.isHidden = false
-                sharedWithYouByNote.text = metadata?.note
+                sharedWithYouByNote.text = metadata.note
                 sharedWithYouByNote.textColor = NCBrandColor.shared.label
                 sharedWithYouByNote.trailingBuffer = sharedWithYouByNote.frame.width
             } else {
@@ -115,18 +115,18 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
                 sharedWithYouByNote.isHidden = true
             }
             
-            let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + metadata!.ownerId + ".png"
-            
-            if let image = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) {
-                
-                sharedWithYouByImage.image = image
-                
-            } else {
-                
+            sharedWithYouByImage.image = NCUtility.shared.loadUserImage(
+                for: metadata.ownerId,
+                   displayName: metadata.ownerDisplayName,
+                   userUrlBase: String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)))
+
+            let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + metadata.ownerId + ".png"
+
+            if NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) == nil {
                 let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
                 let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
-                
-                NCCommunication.shared.downloadAvatar(user: metadata!.ownerId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag) { (account, imageAvatar, imageOriginal, etag, errorCode, errorMessage) in
+
+                NCCommunication.shared.downloadAvatar(user: metadata.ownerId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag) { (account, imageAvatar, imageOriginal, etag, errorCode, errorMessage) in
                     
                     if errorCode == 0, let etag = etag, let imageAvatar = imageAvatar {
                         
@@ -143,9 +143,10 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
         
         reloadData()
         
-        networking = NCShareNetworking.init(metadata: metadata!, urlBase: appDelegate.urlBase, view: self.view, delegate: self)
+        networking = NCShareNetworking(metadata: metadata!, urlBase: appDelegate.urlBase, view: self.view, delegate: self)
         if sharingEnabled {
-            networking?.readShare()
+            let isVisible = (self.navigationController?.topViewController as? NCSharePaging)?.indexPage == .sharing
+            networking?.readShare(showLoadingIndicator: isVisible)
         }
         
         // changeTheming
@@ -429,7 +430,7 @@ extension NCShare: UITableViewDataSource {
                 
                 let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + tableShare.shareWith + ".png"
                
-                NCOperationQueue.shared.downloadAvatar(user: tableShare.shareWith, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
+                NCOperationQueue.shared.downloadAvatar(user: tableShare.shareWith, fileName: fileName, cell: cell, view: tableView)
                 
                 // If the initiator or the recipient is not the current user, show the list of sharees without any options to edit it.
                 if tableShare.uidOwner != self.appDelegate.userId && tableShare.uidFileOwner != self.appDelegate.userId {

+ 9 - 3
iOSClient/Share/NCShareNetworking.swift

@@ -41,12 +41,18 @@ class NCShareNetworking: NSObject {
         super.init()
     }
     
-    func readShare() {
-        NCUtility.shared.startActivityIndicator(backgroundView: view, blurEffect: false)
+    func readShare(showLoadingIndicator: Bool) {
+        if showLoadingIndicator {
+            NCUtility.shared.startActivityIndicator(backgroundView: view, blurEffect: false)
+        }
+    
         let filenamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: urlBase, account: metadata.account)!
         let parameter = NCCShareParameter(path: filenamePath)
         NCCommunication.shared.readShares(parameters: parameter) { (account, shares, errorCode, errorDescription) in
-            NCUtility.shared.stopActivityIndicator()
+            if showLoadingIndicator {
+                NCUtility.shared.stopActivityIndicator()
+            }
+
              if errorCode == 0 && shares != nil {
                 NCManageDatabase.shared.addShare(urlBase: self.urlBase, account: self.metadata.account, shares: shares!)
                 self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: self.metadata.account)