Преглед изворни кода

Fix lining issues for NCShare

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch пре 3 година
родитељ
комит
404f440eb7

+ 0 - 4
.swiftlint.yml

@@ -106,15 +106,11 @@ excluded:
   - iOSClient/Select/NCSelect.swift
   - iOSClient/Settings/NCEndToEndInitialize.swift
   - iOSClient/Settings/NCManageAutoUploadFileName.swift
-  - iOSClient/Share/NCShare.swift
   - iOSClient/Share/NCShareCommentsCell.swift
   - iOSClient/Share/NCShareCommon.swift
-  - iOSClient/Share/NCShareLinkCell.swift
   - iOSClient/Share/NCShareLinkMenuView.swift
   - iOSClient/Share/NCShareNetworking.swift
-  - iOSClient/Share/NCSharePaging.swift
   - iOSClient/Share/NCShareQuickStatusMenu.swift
-  - iOSClient/Share/NCShareUserCell.swift
   - iOSClient/Share/NCShareUserMenuView.swift
   - iOSClient/Shares/NCShares.swift
   - iOSClient/Transfers/NCTransferCell.swift

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -49,6 +49,7 @@
 		AF730AFA27843E4C00B7520E /* NCShareExtension+NCDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF730AF927843E4C00B7520E /* NCShareExtension+NCDelegate.swift */; };
 		AF7E504E27A2D8FF00B5E4AF /* UIBarButton+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF7E504D27A2D8FF00B5E4AF /* UIBarButton+Extension.swift */; };
 		AF7E505027A2D92300B5E4AF /* NCSelectableNavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF7E504F27A2D92300B5E4AF /* NCSelectableNavigationView.swift */; };
+		AF730AF827834B1400B7520E /* NCShare+NCCellDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF730AF727834B1400B7520E /* NCShare+NCCellDelegate.swift */; };
 		AF817EF1274BC781009ED85B /* NCUserBaseUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */; };
 		AF817EF2274BC781009ED85B /* NCUserBaseUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */; };
 		AF817EF3274BC781009ED85B /* NCUserBaseUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */; };
@@ -501,6 +502,7 @@
 		AF730AF927843E4C00B7520E /* NCShareExtension+NCDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShareExtension+NCDelegate.swift"; sourceTree = "<group>"; };
 		AF7E504D27A2D8FF00B5E4AF /* UIBarButton+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIBarButton+Extension.swift"; sourceTree = "<group>"; };
 		AF7E504F27A2D92300B5E4AF /* NCSelectableNavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCSelectableNavigationView.swift; sourceTree = "<group>"; };
+		AF730AF727834B1400B7520E /* NCShare+NCCellDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShare+NCCellDelegate.swift"; sourceTree = "<group>"; };
 		AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCUserBaseUrl.swift; sourceTree = "<group>"; };
 		AF8ED1F92757821000B8DBC4 /* NextcloudTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
 		AF8ED1FB2757821000B8DBC4 /* NextcloudTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextcloudTests.swift; sourceTree = "<group>"; };
@@ -1189,6 +1191,7 @@
 			children = (
 				F700510022DF63AC003A3356 /* NCShare.storyboard */,
 				F700510422DF6A89003A3356 /* NCShare.swift */,
+				AF730AF727834B1400B7520E /* NCShare+NCCellDelegate.swift */,
 				F723B3DC22FC6D1C00301EFE /* NCShareCommentsCell.xib */,
 				F7E4D9C322ED929B003675FD /* NCShareCommentsCell.swift */,
 				F769454522E9F1B0000A798A /* NCShareCommon.swift */,
@@ -2563,6 +2566,7 @@
 				F7A0D1352591FBC5008F8A13 /* String+Extensions.swift in Sources */,
 				F77B0E5F1D118A16002130FE /* NCSettings.m in Sources */,
 				F7F9D1BB25397CE000D9BFF5 /* NCViewer.swift in Sources */,
+				AF730AF827834B1400B7520E /* NCShare+NCCellDelegate.swift in Sources */,
 				F70460522499061800BB98A7 /* NotificationCenter+MainThread.swift in Sources */,
 				F78F74362163781100C2ADAD /* NCTrash.swift in Sources */,
 				AF817EF1274BC781009ED85B /* NCUserBaseUrl.swift in Sources */,

+ 1 - 1
iOSClient/Extensions/String+Extensions.swift

@@ -54,7 +54,7 @@ extension String {
         //https://stackoverflow.com/a/32166735/9506784
 
         let length = Int(CC_MD5_DIGEST_LENGTH)
-        let messageData = self.data(using: .utf8)!
+        let messageData = self.data(using: .utf8) ?? Data()
         var digestData = Data(count: length)
 
         _ = digestData.withUnsafeMutableBytes { digestBytes -> UInt8 in

+ 2 - 2
iOSClient/Menu/NCTrash+Menu.swift

@@ -109,7 +109,7 @@ extension NCTrash {
             iconHeader = icon
         } else {
             if tableTrash.directory {
-                iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
+                iconHeader = UIImage(named: "folder")?.image(color: NCBrandColor.shared.gray, size: 50)
             } else {
                 iconHeader = UIImage(named: tableTrash.iconName)
             }
@@ -126,7 +126,7 @@ extension NCTrash {
         actions.append(
             NCMenuAction(
                 title: NSLocalizedString("_restore_", comment: ""),
-                icon: UIImage(named: "restore")!.image(color: NCBrandColor.shared.gray, size: 50),
+                icon: NCUtility.shared.loadImage(named: "restore", color: NCBrandColor.shared.gray),
                 action: { _ in
                     self.restoreItem(with: objectId)
                 }

+ 7 - 7
iOSClient/RichWorkspace/NCViewerRichWorkspaceWebView.swift

@@ -41,8 +41,8 @@ class NCViewerRichWorkspaceWebView: UIViewController, WKNavigationDelegate, WKSc
 
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
-
-        var request = URLRequest(url: URL(string: url)!)
+        guard let url = URL(string: url) else { return }
+        var request = URLRequest(url: url)
         request.addValue("true", forHTTPHeaderField: "OCS-APIRequest")
         let language = NSLocale.preferredLanguages[0] as String
         request.addValue(language, forHTTPHeaderField: "Accept-Language")
@@ -54,7 +54,7 @@ class NCViewerRichWorkspaceWebView: UIViewController, WKNavigationDelegate, WKSc
     }
 
     @objc func keyboardDidShow(notification: Notification) {
-        let safeAreaInsetsBottom = UIApplication.shared.keyWindow!.safeAreaInsets.bottom
+        let safeAreaInsetsBottom = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
         guard let info = notification.userInfo else { return }
         guard let frameInfo = info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return }
         let keyboardFrame = frameInfo.cgRectValue
@@ -73,8 +73,8 @@ class NCViewerRichWorkspaceWebView: UIViewController, WKNavigationDelegate, WKSc
 
             if message.body as? String == "close" {
 
-                if #available(iOS 13.0, *) {
-                    self.presentationController?.delegate?.presentationControllerWillDismiss?(self.presentationController!)
+                if #available(iOS 13.0, *), let presentationController = self.presentationController {
+                    self.presentationController?.delegate?.presentationControllerWillDismiss?(presentationController)
                 }
 
                 dismiss(animated: true) {
@@ -83,8 +83,8 @@ class NCViewerRichWorkspaceWebView: UIViewController, WKNavigationDelegate, WKSc
             }
 
             if message.body as? String == "share" {
-                if metadata != nil {
-                    NCFunctionCenter.shared.openShare(viewController: self, metadata: metadata!, indexPage: .sharing)
+                if let metadata = metadata {
+                    NCFunctionCenter.shared.openShare(viewController: self, metadata: metadata, indexPage: .sharing)
                 }
             }
 

+ 91 - 0
iOSClient/Share/NCShare+NCCellDelegate.swift

@@ -0,0 +1,91 @@
+//
+//  NCShare+NCCellDelegate.swift
+//  Nextcloud
+//
+//  Created by Henrik Storch on 03.01.22.
+//  Copyright © 2022 Marino Faggiana. All rights reserved.
+//
+
+import UIKit
+
+// MARK: - NCCell Delegates
+extension NCShare: NCShareLinkCellDelegate, NCShareUserCellDelegate {
+
+    func copyInternalLink(sender: Any) {
+        guard let metadata = self.metadata, let appDelegate = appDelegate else { return }
+
+        let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
+        NCNetworking.shared.readFile(serverUrlFileName: serverUrlFileName, account: metadata.account) { _, metadata, errorCode, errorDescription in
+            if errorCode == 0, let metadata = metadata {
+                let internalLink = appDelegate.urlBase + "/index.php/f/" + metadata.fileId
+                NCShareCommon.shared.copyLink(link: internalLink, viewController: self, sender: sender)
+            } else {
+                NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+            }
+        }
+    }
+
+    func tapCopy(with tableShare: tableShare?, sender: Any) {
+        guard let tableShare = tableShare else {
+            return copyInternalLink(sender: sender)
+        }
+        NCShareCommon.shared.copyLink(link: tableShare.url, viewController: self, sender: sender)
+    }
+
+    func tapMenu(with tableShare: tableShare?, sender: Any) {
+        guard let metadata = self.metadata else { return }
+        let isFilesSharingPublicPasswordEnforced = NCManageDatabase.shared.getCapabilitiesServerBool(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesFileSharingPubPasswdEnforced, exists: false)
+
+        if let tableShare = tableShare {
+            // open share menu
+            if tableShare.shareType == 3 {
+                let views = NCShareCommon.shared.openViewMenuShareLink(shareViewController: self, tableShare: tableShare, metadata: metadata)
+                shareLinkMenuView = views.shareLinkMenuView
+                shareMenuViewWindow = views.viewWindow
+
+                let tap = UITapGestureRecognizer(target: self, action: #selector(tapLinkMenuViewWindow))
+                tap.delegate = self
+                shareMenuViewWindow?.addGestureRecognizer(tap)
+            } else {
+                let views = NCShareCommon.shared.openViewMenuUser(shareViewController: self, tableShare: tableShare, metadata: metadata)
+                shareUserMenuView = views.shareUserMenuView
+                shareMenuViewWindow = views.viewWindow
+
+                let tap = UITapGestureRecognizer(target: self, action: #selector(tapLinkMenuViewWindow))
+                tap.delegate = self
+                shareMenuViewWindow?.addGestureRecognizer(tap)
+            }
+        } else if isFilesSharingPublicPasswordEnforced {
+            // create share with pw
+            let alertController = UIAlertController(title: NSLocalizedString("_enforce_password_protection_", comment: ""), message: "", preferredStyle: .alert)
+            alertController.addTextField { textField in
+                textField.isSecureTextEntry = true
+            }
+            alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default) { _ in })
+            let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { _ in
+                let password = alertController.textFields?.first?.text
+                self.networking?.createShareLink(password: password ?? "")
+            }
+
+            alertController.addAction(okAction)
+            self.present(alertController, animated: true, completion: nil)
+        } else {
+            // create sahre without pw
+            networking?.createShareLink(password: "")
+        }
+    }
+
+    func showProfile(with tableShare: tableShare?, sender: Any) {
+        guard let tableShare = tableShare else { return }
+        showProfileMenu(userId: tableShare.shareWith)
+    }
+
+    func quickStatus(with tableShare: tableShare?, sender: Any) {
+        guard let tableShare = tableShare,
+              let metadata = metadata,
+              tableShare.shareType != NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption else { return }
+
+        let quickStatusMenu = NCShareQuickStatusMenu()
+        quickStatusMenu.toggleMenu(viewController: self, directory: metadata.directory, tableShare: tableShare)
+    }
+}

+ 76 - 220
iOSClient/Share/NCShare.swift

@@ -42,19 +42,19 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
 
     @IBOutlet weak var tableView: UITableView!
 
-    private let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    weak var appDelegate = UIApplication.shared.delegate as? AppDelegate
 
     public var metadata: tableMetadata?
     public var sharingEnabled = true
     public var height: CGFloat = 0
 
-    var shares: (firstShareLink: tableShare?,  share: [tableShare]?) = (nil, nil)
+    var shares: (firstShareLink: tableShare?, share: [tableShare]?) = (nil, nil)
 
-    private var shareLinkMenuView: NCShareLinkMenuView?
-    private var shareUserMenuView: NCShareUserMenuView?
-    private var shareMenuViewWindow: UIView?
+    var shareLinkMenuView: NCShareLinkMenuView?
+    var shareUserMenuView: NCShareUserMenuView?
+    var shareMenuViewWindow: UIView?
     private var dropDown = DropDown()
-    private var networking: NCShareNetworking?
+    var networking: NCShareNetworking?
 
     // MARK: - View Life Cycle
 
@@ -67,7 +67,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
         searchFieldTopConstraint.constant = 10
 
         searchField.placeholder = NSLocalizedString("_shareLinksearch_placeholder_", comment: "")
-        
+
         tableView.dataSource = self
         tableView.delegate = self
         tableView.allowsSelection = false
@@ -78,58 +78,13 @@ 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 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
-            sharedWithYouByImage.image = NCUtility.shared.loadUserImage(
-                for: metadata.ownerId,
-                   displayName: metadata.ownerDisplayName,
-                   userBaseUrl: appDelegate)
-            let shareAction = UITapGestureRecognizer(target: self, action: #selector(openShareProfile))
-            sharedWithYouByImage.addGestureRecognizer(shareAction)
-            let shareLabelAction = UITapGestureRecognizer(target: self, action: #selector(openShareProfile))
-            sharedWithYouByLabel.addGestureRecognizer(shareLabelAction)
-
-            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.textColor = NCBrandColor.shared.label
-                sharedWithYouByNote.trailingBuffer = sharedWithYouByNote.frame.width
-            } else {
-                sharedWithYouByNoteImage.isHidden = true
-                sharedWithYouByNote.isHidden = true
-            }
-
-            let fileName = appDelegate.userBaseUrl + "-" + 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) { _, imageAvatar, _, etag, errorCode, _ in
-
-                    if errorCode == 0, let etag = etag, let imageAvatar = imageAvatar {
-
-                        NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
-                        self.sharedWithYouByImage.image = imageAvatar
-
-                    } else if errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = NCManageDatabase.shared.setAvatarLoaded(fileName: fileName) {
+        guard let appDelegate = appDelegate, let metadata = metadata else { return }
 
-                        self.sharedWithYouByImage.image = imageAvatar
-                    }
-                }
-            }
-        }
+        checkSharedWithYou()
 
         reloadData()
 
-        networking = NCShareNetworking(metadata: metadata!, urlBase: appDelegate.urlBase, view: self.view, delegate: self)
+        networking = NCShareNetworking(metadata: metadata, urlBase: appDelegate.urlBase, view: self.view, delegate: self)
         if sharingEnabled {
             let isVisible = (self.navigationController?.topViewController as? NCSharePaging)?.indexPage == .sharing
             networking?.readShare(showLoadingIndicator: isVisible)
@@ -142,6 +97,57 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
         changeTheming()
     }
 
+    // Shared with you by ...
+    func checkSharedWithYou() {
+        guard let appDelegate = self.appDelegate, let metadata = metadata, !metadata.ownerId.isEmpty, metadata.ownerId != appDelegate.userId else { return }
+
+        searchFieldTopConstraint.constant = 65
+        sharedWithYouByView.isHidden = false
+        sharedWithYouByLabel.text = NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata.ownerDisplayName
+        sharedWithYouByImage.image = NCUtility.shared.loadUserImage(
+            for: metadata.ownerId,
+               displayName: metadata.ownerDisplayName,
+               userBaseUrl: appDelegate)
+        let shareAction = UITapGestureRecognizer(target: self, action: #selector(openShareProfile))
+        sharedWithYouByImage.addGestureRecognizer(shareAction)
+        let shareLabelAction = UITapGestureRecognizer(target: self, action: #selector(openShareProfile))
+        sharedWithYouByLabel.addGestureRecognizer(shareLabelAction)
+
+        if !metadata.note.isEmpty {
+            searchFieldTopConstraint.constant = 95
+            sharedWithYouByNoteImage.isHidden = false
+            sharedWithYouByNoteImage.image = NCUtility.shared.loadImage(named: "note.text", color: .gray)
+            sharedWithYouByNote.isHidden = false
+            sharedWithYouByNote.text = metadata.note
+            sharedWithYouByNote.textColor = NCBrandColor.shared.label
+            sharedWithYouByNote.trailingBuffer = sharedWithYouByNote.frame.width
+        } else {
+            sharedWithYouByNoteImage.isHidden = true
+            sharedWithYouByNote.isHidden = true
+        }
+
+        let fileName = appDelegate.userBaseUrl + "-" + 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) { _, imageAvatar, _, etag, errorCode, _ in
+                    if errorCode == 0, let etag = etag, let imageAvatar = imageAvatar {
+                        NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
+                        self.sharedWithYouByImage.image = imageAvatar
+                    } else if errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = NCManageDatabase.shared.setAvatarLoaded(fileName: fileName) {
+                        self.sharedWithYouByImage.image = imageAvatar
+                    }
+                }
+        }
+    }
+
     // MARK: - Notification Center
 
     @objc func openShareProfile() {
@@ -165,7 +171,9 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
     // MARK: -
 
     @objc func reloadData() {
-        shares = NCManageDatabase.shared.getTableShares(metadata: metadata!)
+        if let metadata = metadata {
+            shares = NCManageDatabase.shared.getTableShares(metadata: metadata)
+        }
         tableView.reloadData()
     }
 
@@ -193,9 +201,9 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
 
         alertController.addAction(okAction)
 
-        self.present(alertController, animated: true, completion:nil)
+        self.present(alertController, animated: true, completion: nil)
     }
-    
+
     @objc func tapLinkMenuViewWindow(gesture: UITapGestureRecognizer) {
         shareLinkMenuView?.unLoad()
         shareLinkMenuView = nil
@@ -225,7 +233,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
 
     func getSharees(sharees: [NCCommunicationSharee]?) {
 
-        guard let sharees = sharees else { return }
+        guard let sharees = sharees, let appDelegate = appDelegate else { return }
 
         dropDown = DropDown()
         let appearance = DropDown.appearance()
@@ -242,7 +250,7 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
         for sharee in sharees {
             var label = sharee.label
             if sharee.shareType == NCShareCommon.shared.SHARE_TYPE_CIRCLE {
-                label += " (" + sharee.circleInfo + ", " +  sharee.circleOwner + ")"
+                label += " (\(sharee.circleInfo), \(sharee.circleOwner))"
             }
             dropDown.dataSource.append(label)
         }
@@ -253,49 +261,17 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareNetworkingD
         dropDown.direction = .bottom
 
         dropDown.cellNib = UINib(nibName: "NCSearchUserDropDownCell", bundle: nil)
-        dropDown.customCellConfiguration = { (index: Index, item: String, cell: DropDownCell) -> Void in
+        dropDown.customCellConfiguration = { (index: Index, _, cell: DropDownCell) -> Void in
             guard let cell = cell as? NCSearchUserDropDownCell else { return }
             let sharee = sharees[index]
-            cell.imageItem.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
-            cell.imageShareeType.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
-            let status = NCUtility.shared.getUserStatus(userIcon: sharee.userIcon, userStatus: sharee.userStatus, userMessage: sharee.userMessage)
-            cell.imageStatus.image = status.onlineStatus
-            cell.status.text = status.statusMessage
-            if cell.status.text?.count ?? 0 > 0 {
-                cell.centerTitle.constant = -5
-            } else {
-                cell.centerTitle.constant = 0
-            }
-
-            cell.imageItem.image = NCUtility.shared.loadUserImage(
-                for: sharee.shareWith,
-                   displayName: nil,
-                   userBaseUrl: self.appDelegate)
-
-            let fileName = self.appDelegate.userBaseUrl + "-" + sharee.shareWith + ".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: sharee.shareWith, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag) { _, imageAvatar, _, etag, errorCode, _ in
-
-                    if errorCode == 0, let etag = etag, let imageAvatar = imageAvatar {
-
-                        NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
-                        cell.imageItem.image = imageAvatar
-
-                    } else if errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = NCManageDatabase.shared.setAvatarLoaded(fileName: fileName) {
-
-                        cell.imageItem.image = imageAvatar
-                    }
-                }
-            }
+            cell.setupCell(sharee: sharee, baseUrl: appDelegate)
         }
 
-        dropDown.selectionAction = { (index, item) in
+        dropDown.selectionAction = { index, _ in
             let sharee = sharees[index]
             self.checkEnforcedPassword { password in
-                self.networking?.createShare(shareWith: sharee.shareWith, shareType: sharee.shareType, password: password, metadata: self.metadata!)
+                guard let metadata = self.metadata else { return }
+                self.networking?.createShare(shareWith: sharee.shareWith, shareType: sharee.shareType, password: password, metadata: metadata)
             }
         }
 
@@ -343,8 +319,8 @@ extension NCShare: UITableViewDataSource {
             cell.setupCellUI()
             return cell
         }
-        
-        let tableShare = shares.share![indexPath.row]
+
+        guard let appDelegate = appDelegate, let tableShare = shares.share?[indexPath.row] else { return UITableViewCell() }
 
         // LINK
         if tableShare.shareType == 3 {
@@ -357,47 +333,11 @@ extension NCShare: UITableViewDataSource {
         } else {
         // USER
             if let cell = tableView.dequeueReusableCell(withIdentifier: "cellUser", for: indexPath) as? NCShareUserCell {
-
                 cell.tableShare = tableShare
                 cell.delegate = self
-                cell.labelTitle.text = tableShare.shareWithDisplayname
-                cell.labelTitle.textColor = NCBrandColor.shared.label
-                cell.isUserInteractionEnabled = true
-                cell.labelQuickStatus.isHidden = false
-                cell.imageDownArrow.isHidden = false
-                cell.buttonMenu.isHidden = false
-                cell.imageItem.image = NCShareCommon.shared.getImageShareType(shareType: tableShare.shareType)
-
-                let status = NCUtility.shared.getUserStatus(userIcon: tableShare.userIcon, userStatus: tableShare.userStatus, userMessage: tableShare.userMessage)
-                cell.imageStatus.image = status.onlineStatus
-                cell.status.text = status.statusMessage
-
+                cell.setupCellUI(userId: appDelegate.userId)
                 let fileName = appDelegate.userBaseUrl + "-" + tableShare.shareWith + ".png"
-
                 NCOperationQueue.shared.downloadAvatar(user: tableShare.shareWith, dispalyName: tableShare.shareWithDisplayname, 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 {
-                    cell.isUserInteractionEnabled = false
-                    cell.labelQuickStatus.isHidden = true
-                    cell.imageDownArrow.isHidden = true
-                    cell.buttonMenu.isHidden = true
-                }
-
-                cell.btnQuickStatus.setTitle("", for: .normal)
-                cell.btnQuickStatus.contentHorizontalAlignment = .left
-
-                if tableShare.permissions == NCGlobal.shared.permissionCreateShare {
-                    cell.labelQuickStatus.text = NSLocalizedString("_share_file_drop_", comment: "")
-                } else {
-                    // Read Only
-                    if CCUtility.isAnyPermission(toEdit: tableShare.permissions) {
-                        cell.labelQuickStatus.text = NSLocalizedString("_share_editing_", comment: "")
-                    } else {
-                        cell.labelQuickStatus.text = NSLocalizedString("_share_read_only_", comment: "")
-                    }
-                }
-
                 return cell
             }
         }
@@ -405,87 +345,3 @@ extension NCShare: UITableViewDataSource {
         return UITableViewCell()
     }
 }
-
-// MARK: - NCCell Delegates
-extension NCShare: NCShareLinkCellDelegate, NCShareUserCellDelegate {
-
-    func copyInternalLink(sender: Any) {
-        guard let metadata = self.metadata else { return }
-
-        let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
-        NCNetworking.shared.readFile(serverUrlFileName: serverUrlFileName, account: metadata.account) { (account, metadata, errorCode, errorDescription) in
-            if errorCode == 0 && metadata != nil {
-                let internalLink = self.appDelegate.urlBase + "/index.php/f/" + metadata!.fileId
-                NCShareCommon.shared.copyLink(link: internalLink, viewController: self, sender: sender)
-            } else {
-                NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
-            }
-        }
-    }
-
-    func tapCopy(with tableShare: tableShare?, sender: Any) {
-        guard let tableShare = tableShare else {
-            return copyInternalLink(sender: sender)
-        }
-        NCShareCommon.shared.copyLink(link: tableShare.url, viewController: self, sender: sender)
-    }
-
-    func tapMenu(with tableShare: tableShare?, sender: Any) {
-        guard let metadata = self.metadata else { return }
-        let isFilesSharingPublicPasswordEnforced = NCManageDatabase.shared.getCapabilitiesServerBool(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesFileSharingPubPasswdEnforced, exists: false)
-
-        if let tableShare = tableShare {
-            // open share menu
-            if tableShare.shareType == 3 {
-                let views = NCShareCommon.shared.openViewMenuShareLink(shareViewController: self, tableShare: tableShare, metadata: metadata)
-                shareLinkMenuView = views.shareLinkMenuView
-                shareMenuViewWindow = views.viewWindow
-                
-                let tap = UITapGestureRecognizer(target: self, action: #selector(tapLinkMenuViewWindow))
-                tap.delegate = self
-                shareMenuViewWindow?.addGestureRecognizer(tap)
-            } else {
-                let views = NCShareCommon.shared.openViewMenuUser(shareViewController: self, tableShare: tableShare, metadata: metadata)
-                shareUserMenuView = views.shareUserMenuView
-                shareMenuViewWindow = views.viewWindow
-                
-                let tap = UITapGestureRecognizer(target: self, action: #selector(tapLinkMenuViewWindow))
-                tap.delegate = self
-                shareMenuViewWindow?.addGestureRecognizer(tap)
-            }
-        } else if isFilesSharingPublicPasswordEnforced {
-            // create share with pw
-            let alertController = UIAlertController(title: NSLocalizedString("_enforce_password_protection_", comment: ""), message: "", preferredStyle: .alert)
-            alertController.addTextField { (textField) in
-                textField.isSecureTextEntry = true
-            }
-            alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default) { (action:UIAlertAction) in })
-            let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { (action:UIAlertAction) in
-                let password = alertController.textFields?.first?.text
-                self.networking?.createShareLink(password: password ?? "")
-            }
-            
-            alertController.addAction(okAction)
-            self.present(alertController, animated: true, completion: nil)
-        } else {
-            // create sahre without pw
-            networking?.createShareLink(password: "")
-        }
-    }
-
-    func showProfile(with tableShare: tableShare?, sender: Any) {
-        guard let tableShare = tableShare else { return }
-        showProfileMenu(userId: tableShare.shareWith)
-    }
-
-    func quickStatus(with tableShare: tableShare?, sender: Any) {
-
-        guard let tableShare = tableShare else { return }
-
-        if tableShare.shareType != NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption {
-
-            let quickStatusMenu = NCShareQuickStatusMenu()
-            quickStatusMenu.toggleMenu(viewController: self, directory: metadata!.directory, tableShare: tableShare)
-        }
-    }
-}

+ 4 - 4
iOSClient/Share/NCShareLinkCell.swift

@@ -31,7 +31,7 @@ class NCShareLinkCell: UITableViewCell {
     @IBOutlet private weak var menuButton: UIButton!
     @IBOutlet private weak var copyButton: UIButton!
     var tableShare: tableShare?
-    var delegate: NCShareLinkCellDelegate?
+    weak var delegate: NCShareLinkCellDelegate?
     var isInternalLink = false
 
     override func prepareForReuse() {
@@ -67,14 +67,14 @@ class NCShareLinkCell: UITableViewCell {
             imageName = "sharebylink"
             imageBGColor = NCBrandColor.shared.brandElement
 
-            menuButton.setImage(UIImage.init(named: menuImageName)!.image(color: .gray, size: 50), for: .normal)
+            menuButton.setImage(UIImage(named: menuImageName)?.image(color: .gray, size: 50), for: .normal)
         }
 
         labelTitle.textColor = NCBrandColor.shared.label
         imageItem.image = NCShareCommon.shared.createLinkAvatar(imageName: imageName, colorCircle: imageBGColor)
-        copyButton.setImage(UIImage.init(named: "shareCopy")!.image(color: .gray, size: 50), for: .normal)
+        copyButton.setImage(UIImage(named: "shareCopy")?.image(color: .gray, size: 50), for: .normal)
     }
-    
+
     @IBAction func touchUpCopy(_ sender: Any) {
         delegate?.tapCopy(with: tableShare, sender: sender)
     }

+ 56 - 65
iOSClient/Share/NCSharePaging.swift

@@ -34,7 +34,7 @@ protocol NCSharePagingContent {
 class NCSharePaging: UIViewController {
 
     private let pagingViewController = NCShareHeaderViewController()
-    private let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    private weak var appDelegate = UIApplication.shared.delegate as? AppDelegate
 
     private var activityEnabled = true
     private var commentsEnabled = true
@@ -53,29 +53,8 @@ class NCSharePaging: UIViewController {
 
         navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_close_", comment: ""), style: .done, target: self, action: #selector(exitTapped))
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
-         NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
-
-        // Verify Comments & Sharing enabled
-        let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
-        let comments = NCManageDatabase.shared.getCapabilitiesServerBool(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesComments, exists: false)
-        if serverVersionMajor >= NCGlobal.shared.nextcloudVersion20 && comments == false {
-            commentsEnabled = false
-        }
-        let sharing = NCManageDatabase.shared.getCapabilitiesServerBool(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
-        if sharing == false {
-            sharingEnabled = false
-        }
-        let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesActivity)
-        if activity == nil {
-            activityEnabled = false
-        }
-        if indexPage == .sharing && !sharingEnabled {
-            indexPage = .activity
-        }
-        if indexPage == .activity && !activityEnabled && sharingEnabled {
-            indexPage = .sharing
-        }
-
+        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
+        setupCapabilities()
         // *** MUST BE THE FIRST ONE ***
         pagingViewController.metadata = metadata
 
@@ -113,14 +92,36 @@ class NCSharePaging: UIViewController {
         pagingViewController.dataSource = self
         pagingViewController.delegate = self
         pagingViewController.select(index: indexPage.rawValue)
-        let pagingIndexItem = self.pagingViewController(pagingViewController, pagingItemAt: indexPage.rawValue) as! PagingIndexItem
-        self.title = pagingIndexItem.title
+        let pagingIndexItem = self.pagingViewController(pagingViewController, pagingItemAt: indexPage.rawValue) as? PagingIndexItem
+        self.title = pagingIndexItem?.title
 
         NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(self.orientationDidChange), name: UIDevice.orientationDidChangeNotification, object: nil)
         changeTheming()
     }
 
+    func setupCapabilities() {
+        guard let appDelegate = appDelegate else { return }
+
+        // Verify Comments & Sharing enabled
+        let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
+        let comments = NCManageDatabase.shared.getCapabilitiesServerBool(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesComments, exists: false)
+        if serverVersionMajor >= NCGlobal.shared.nextcloudVersion20 && comments == false {
+            commentsEnabled = false
+        }
+        let sharing = NCManageDatabase.shared.getCapabilitiesServerBool(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFileSharingApiEnabled, exists: false)
+        sharingEnabled = sharing
+        let activity = NCManageDatabase.shared.getCapabilitiesServerArray(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesActivity)
+        activityEnabled = activity != nil
+
+        if indexPage == .sharing && !sharingEnabled {
+            indexPage = .activity
+        }
+        if indexPage == .activity && !activityEnabled && sharingEnabled {
+            indexPage = .sharing
+        }
+    }
+
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
         currentVC = pagingViewController.pageViewController.selectedViewController as? NCSharePagingContent
@@ -128,8 +129,7 @@ class NCSharePaging: UIViewController {
 
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
-
-        if appDelegate.disableSharesView {
+        if appDelegate?.disableSharesView == true {
             self.dismiss(animated: false, completion: nil)
         }
 
@@ -140,7 +140,6 @@ class NCSharePaging: UIViewController {
 
     override func viewWillDisappear(_ animated: Bool) {
         super.viewWillDisappear(animated)
-
         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl])
     }
 
@@ -150,7 +149,7 @@ class NCSharePaging: UIViewController {
         NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
     }
 
-    //MARK: - NotificationCenter
+    // MARK: - NotificationCenter
 
     @objc func orientationDidChange() {
         pagingViewController.menuItemSize = .fixed(
@@ -161,7 +160,7 @@ class NCSharePaging: UIViewController {
 
     @objc func changeTheming() {
         pagingViewController.indicatorColor = NCBrandColor.shared.brandElement
-        (pagingViewController.view as! NCSharePagingView).setupConstraints()
+        (pagingViewController.view as? NCSharePagingView)?.setupConstraints()
         pagingViewController.reloadMenu()
     }
 
@@ -201,9 +200,7 @@ extension NCSharePaging: PagingViewControllerDelegate {
             let itemIndex = NCGlobal.NCSharePagingIndex(rawValue: item.index)
         else { return }
 
-        if itemIndex == .activity && !activityEnabled {
-            pagingViewController.contentInteraction = .none
-        } else if itemIndex == .sharing && !sharingEnabled {
+        if itemIndex == .activity && !activityEnabled || itemIndex == .sharing && !sharingEnabled {
             pagingViewController.contentInteraction = .none
         } else {
             self.title = item.title
@@ -224,7 +221,9 @@ extension NCSharePaging: PagingViewControllerDataSource {
 
         switch NCGlobal.NCSharePagingIndex(rawValue: index) {
         case .activity:
-            let viewController = UIStoryboard(name: "NCActivity", bundle: nil).instantiateInitialViewController() as! NCActivity
+            guard let viewController = UIStoryboard(name: "NCActivity", bundle: nil).instantiateInitialViewController() as? NCActivity else {
+                return UIViewController()
+            }
             viewController.height = height
             viewController.showComments = true
             viewController.didSelectItemEnable = false
@@ -232,7 +231,9 @@ extension NCSharePaging: PagingViewControllerDataSource {
             viewController.objectType = "files"
             return viewController
         case .sharing:
-            let viewController = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "sharing") as! NCShare
+            guard let viewController = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "sharing") as? NCShare else {
+                return UIViewController()
+            }
             viewController.sharingEnabled = sharingEnabled
             viewController.metadata = metadata
             viewController.height = height
@@ -280,17 +281,15 @@ class NCShareHeaderViewController: PagingViewController {
     }
 
     override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-        if NCGlobal.NCSharePagingIndex(rawValue: indexPath.item) == .activity && !activityEnabled {
-            return
-        } else if NCGlobal.NCSharePagingIndex(rawValue: indexPath.item) == .sharing && !sharingEnabled {
-            return
-        }
+        guard NCGlobal.NCSharePagingIndex(rawValue: indexPath.item) != .activity || activityEnabled,
+              NCGlobal.NCSharePagingIndex(rawValue: indexPath.item) != .sharing || sharingEnabled
+        else { return }
         super.collectionView(collectionView, didSelectItemAt: indexPath)
     }
 }
 
 class NCSharePagingView: PagingView {
-    
+
     static let headerHeight: CGFloat = 100
     var metadata = tableMetadata()
 
@@ -310,7 +309,7 @@ class NCSharePagingView: PagingView {
 
     override func setupConstraints() {
 
-        let headerView = Bundle.main.loadNibNamed("NCShareHeaderView", owner: self, options: nil)?.first as! NCShareHeaderView
+        guard let headerView = Bundle.main.loadNibNamed("NCShareHeaderView", owner: self, options: nil)?.first as? NCShareHeaderView else { return }
         headerView.backgroundColor = NCBrandColor.shared.systemBackground
         headerView.ocId = metadata.ocId
 
@@ -318,9 +317,9 @@ class NCSharePagingView: PagingView {
             headerView.imageView.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
         } else {
             if metadata.directory {
-                let image = UIImage(named: "folder")!
-                headerView.imageView.image = image.image(color: NCBrandColor.shared.brandElement, size: image.size.width)
-            } else if metadata.iconName.count > 0 {
+                let image = UIImage(named: "folder")
+                headerView.imageView.image = image?.image(color: NCBrandColor.shared.brandElement, size: image?.size.width ?? 0)
+            } else if !metadata.iconName.isEmpty {
                 headerView.imageView.image = UIImage(named: metadata.iconName)
             } else {
                 headerView.imageView.image = UIImage(named: "file")
@@ -341,9 +340,7 @@ class NCSharePagingView: PagingView {
         collectionView.translatesAutoresizingMaskIntoConstraints = false
         headerView.translatesAutoresizingMaskIntoConstraints = false
 
-        headerHeightConstraint = headerView.heightAnchor.constraint(
-            equalToConstant: NCSharePagingView.headerHeight
-        )
+        headerHeightConstraint = headerView.heightAnchor.constraint(equalToConstant: NCSharePagingView.headerHeight)
         headerHeightConstraint?.isActive = true
 
         NSLayoutConstraint.activate([
@@ -374,32 +371,26 @@ class NCShareHeaderView: UIView {
 
     override func awakeFromNib() {
         super.awakeFromNib()
-
         let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(self.longTap))
         path.addGestureRecognizer(longGesture)
     }
 
     @IBAction func touchUpInsideFavorite(_ sender: UIButton) {
-        if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-            NCNetworking.shared.favoriteMetadata(metadata) { errorCode, errorDescription in
-                if errorCode == 0 {
-                    if !metadata.favorite {
-                        self.favorite.setImage(NCUtility.shared.loadImage(named: "star.fill", color: NCBrandColor.shared.yellowFavorite, size: 20), for: .normal)
-                    } else {
-                        self.favorite.setImage(NCUtility.shared.loadImage(named: "star.fill", color: NCBrandColor.shared.systemGray, size: 20), for: .normal)
-                    }
-                } else {
-                    NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
-                }
+        guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return }
+        NCNetworking.shared.favoriteMetadata(metadata) { errorCode, errorDescription in
+            if errorCode == 0 {
+                self.favorite.setImage(NCUtility.shared.loadImage(
+                    named: "star.fill",
+                    color: metadata.favorite ? NCBrandColor.shared.yellowFavorite : NCBrandColor.shared.systemGray,
+                    size: 20), for: .normal)
+            } else {
+                NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
             }
         }
     }
 
     @objc func longTap(sender: UIGestureRecognizer) {
-
-        let board = UIPasteboard.general
-        board.string = path.text
-
+        UIPasteboard.general.string = path.text
         NCContentPresenter.shared.messageNotification("", description: "_copied_path_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.errorNoError)
     }
 }

+ 85 - 32
iOSClient/Share/NCShareUserCell.swift

@@ -22,6 +22,7 @@
 
 import UIKit
 import DropDown
+import NCCommunication
 
 class NCShareUserCell: UITableViewCell, NCCellProtocol {
 
@@ -37,24 +38,48 @@ class NCShareUserCell: UITableViewCell, NCCellProtocol {
     var tableShare: tableShare?
     weak var delegate: NCShareUserCellDelegate?
 
-    var fileAvatarImageView: UIImageView? {
-        get {
-            return imageItem
-        }
-    }
-    var fileObjectId: String? {
-        get {
-            return nil
+    var fileAvatarImageView: UIImageView? { return imageItem }
+    var fileObjectId: String? { return nil }
+    var filePreviewImageView: UIImageView? { return nil }
+    var fileUser: String? { return tableShare?.shareWith }
+
+    func setupCellUI(userId: String) {
+        guard let tableShare = tableShare else {
+            return
         }
-    }
-    var filePreviewImageView: UIImageView? {
-        get {
-            return nil
+
+        labelTitle.text = tableShare.shareWithDisplayname
+        labelTitle.textColor = NCBrandColor.shared.label
+        isUserInteractionEnabled = true
+        labelQuickStatus.isHidden = false
+        imageDownArrow.isHidden = false
+        buttonMenu.isHidden = false
+        imageItem.image = NCShareCommon.shared.getImageShareType(shareType: tableShare.shareType)
+
+        let status = NCUtility.shared.getUserStatus(userIcon: tableShare.userIcon, userStatus: tableShare.userStatus, userMessage: tableShare.userMessage)
+        imageStatus.image = status.onlineStatus
+        self.status.text = status.statusMessage
+
+        // 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 != userId && tableShare.uidFileOwner != userId {
+            isUserInteractionEnabled = false
+            labelQuickStatus.isHidden = true
+            imageDownArrow.isHidden = true
+            buttonMenu.isHidden = true
         }
-    }
-    var fileUser: String? {
-        get {
-            return tableShare?.shareWith
+
+        btnQuickStatus.setTitle("", for: .normal)
+        btnQuickStatus.contentHorizontalAlignment = .left
+
+        if tableShare.permissions == NCGlobal.shared.permissionCreateShare {
+            labelQuickStatus.text = NSLocalizedString("_share_file_drop_", comment: "")
+        } else {
+            // Read Only
+            if CCUtility.isAnyPermission(toEdit: tableShare.permissions) {
+                labelQuickStatus.text = NSLocalizedString("_share_editing_", comment: "")
+            } else {
+                labelQuickStatus.text = NSLocalizedString("_share_read_only_", comment: "")
+            }
         }
     }
 
@@ -63,7 +88,7 @@ class NCShareUserCell: UITableViewCell, NCCellProtocol {
         let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapAvatarImage))
         imageItem?.addGestureRecognizer(tapGesture)
 
-        buttonMenu.setImage(UIImage(named: "shareMenu")!.image(color: .gray, size: 50), for: .normal)
+        buttonMenu.setImage(UIImage(named: "shareMenu")?.image(color: .gray, size: 50), for: .normal)
         labelQuickStatus.textColor = NCBrandColor.shared.customer
         imageDownArrow.image = NCUtility.shared.loadImage(named: "arrowtriangle.down.fill", color: NCBrandColor.shared.customer)
     }
@@ -99,21 +124,9 @@ class NCSearchUserDropDownCell: DropDownCell, NCCellProtocol {
 
     private var user: String = ""
 
-    var fileAvatarImageView: UIImageView? {
-        get {
-            return imageItem
-        }
-    }
-    var fileObjectId: String? {
-        get {
-            return nil
-        }
-    }
-    var filePreviewImageView: UIImageView? {
-        get {
-            return nil
-        }
-    }
+    var fileAvatarImageView: UIImageView? { return imageItem }
+    var fileObjectId: String? { return nil }
+    var filePreviewImageView: UIImageView? { return nil }
     var fileUser: String? {
         get {
             return user
@@ -122,4 +135,44 @@ class NCSearchUserDropDownCell: DropDownCell, NCCellProtocol {
             user = newValue ?? ""
         }
     }
+
+    func setupCell(sharee: NCCommunicationSharee, baseUrl: NCUserBaseUrl) {
+        imageItem.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
+        imageShareeType.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
+        let status = NCUtility.shared.getUserStatus(userIcon: sharee.userIcon, userStatus: sharee.userStatus, userMessage: sharee.userMessage)
+        imageStatus.image = status.onlineStatus
+        self.status.text = status.statusMessage
+        if self.status.text?.count ?? 0 > 0 {
+            centerTitle.constant = -5
+        } else {
+            centerTitle.constant = 0
+        }
+
+        imageItem.image = NCUtility.shared.loadUserImage(
+            for: sharee.shareWith,
+               displayName: nil,
+               userBaseUrl: baseUrl)
+
+        let fileName = baseUrl.userBaseUrl + "-" + sharee.shareWith + ".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: sharee.shareWith,
+                fileNameLocalPath: fileNameLocalPath,
+                sizeImage: NCGlobal.shared.avatarSize,
+                avatarSizeRounded: NCGlobal.shared.avatarSizeRounded,
+                etag: etag) { _, imageAvatar, _, etag, errorCode, _ in
+
+                    if errorCode == 0, let etag = etag, let imageAvatar = imageAvatar {
+                        NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
+                        self.imageItem.image = imageAvatar
+                    } else if errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = NCManageDatabase.shared.setAvatarLoaded(fileName: fileName) {
+                        self.imageItem.image = imageAvatar
+                    }
+                }
+        }
+
+    }
 }