Browse Source

Sahne extension more listing + fix file header

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

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -39,6 +39,7 @@
 		AF4BF61F27562B3F0081CEEF /* NCManageDatabase+Activity.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF4BF61D27562B3F0081CEEF /* NCManageDatabase+Activity.swift */; };
 		AF4BF62027562B3F0081CEEF /* NCManageDatabase+Activity.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF4BF61D27562B3F0081CEEF /* NCManageDatabase+Activity.swift */; };
 		AF4BF62127562B3F0081CEEF /* NCManageDatabase+Activity.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF4BF61D27562B3F0081CEEF /* NCManageDatabase+Activity.swift */; };
+		AF730AFA27843E4C00B7520E /* NCShareExtension+NCDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF730AF927843E4C00B7520E /* NCShareExtension+NCDelegate.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 */; };
@@ -461,6 +462,7 @@
 		AF4BF613275629E20081CEEF /* NCManageDatabase+Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabase+Account.swift"; sourceTree = "<group>"; };
 		AF4BF61827562A4B0081CEEF /* NCManageDatabse+Metadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabse+Metadata.swift"; sourceTree = "<group>"; };
 		AF4BF61D27562B3F0081CEEF /* NCManageDatabase+Activity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabase+Activity.swift"; sourceTree = "<group>"; };
+		AF730AF927843E4C00B7520E /* NCShareExtension+NCDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShareExtension+NCDelegate.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>"; };
@@ -1445,6 +1447,7 @@
 			children = (
 				F714803A262EBE3900693E51 /* MainInterface.storyboard */,
 				F7148040262EBE4000693E51 /* NCShareExtension.swift */,
+				AF730AF927843E4C00B7520E /* NCShareExtension+NCDelegate.swift */,
 				AF22B215277D196700DAB0CC /* NCShareExtension+DataSource.swift */,
 				AF22B216277D196700DAB0CC /* NCShareExtension+Files.swift */,
 				AF22B20B277C6F4D00DAB0CC /* NCShareCell.swift */,
@@ -2282,6 +2285,7 @@
 				F7EDE4D1262D7B8400414FE6 /* NCDataSource.swift in Sources */,
 				F71459D21D12E3B700CAFEEC /* CCUtility.m in Sources */,
 				F75A9EE723796C6F0044CFCE /* NCNetworking.swift in Sources */,
+				AF730AFA27843E4C00B7520E /* NCShareExtension+NCDelegate.swift in Sources */,
 				F7EDE4E0262D7BAF00414FE6 /* NCGridCell.swift in Sources */,
 				F7A76DC8256A71CD00119AB3 /* UIImage+Extensions.swift in Sources */,
 				F7B8CD96261AF401007C1359 /* NCNetworkingChunkedUpload.swift in Sources */,

+ 59 - 47
Share/NCShareExtension+DataSource.swift

@@ -3,7 +3,22 @@
 //  Share
 //
 //  Created by Henrik Storch on 29.12.21.
-//  Copyright © 2021 Marino Faggiana. All rights reserved.
+//  Copyright © 2021 Henrik Storch. All rights reserved.
+//
+//  Author Henrik Storch <henrik.storch@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
 import UIKit
@@ -47,19 +62,6 @@ extension NCShareExtension: UICollectionViewDataSource {
             return UICollectionViewCell()
         }
 
-        var tableShare: tableShare?
-        var isShare = false
-        var isMounted = false
-
-        if let metadataFolder = metadataFolder {
-            isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionShared)
-            isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionMounted)
-        }
-
-        if dataSource.metadataShare[metadata.ocId] != nil {
-            tableShare = dataSource.metadataShare[metadata.ocId]
-        }
-
         cell.delegate = self
 
         cell.fileObjectId = metadata.ocId
@@ -80,35 +82,7 @@ extension NCShareExtension: UICollectionViewDataSource {
         cell.progressView.progress = 0.0
 
         if metadata.directory {
-
-            if metadata.e2eEncrypted {
-                cell.imageItem.image = NCBrandColor.cacheImages.folderEncrypted
-            } else if isShare {
-                cell.imageItem.image = NCBrandColor.cacheImages.folderSharedWithMe
-            } else if tableShare != nil && tableShare?.shareType != 3 {
-                cell.imageItem.image = NCBrandColor.cacheImages.folderSharedWithMe
-            } else if tableShare != nil && tableShare?.shareType == 3 {
-                cell.imageItem.image = NCBrandColor.cacheImages.folderPublic
-            } else if metadata.mountType == "group" {
-                cell.imageItem.image = NCBrandColor.cacheImages.folderGroup
-            } else if isMounted {
-                cell.imageItem.image = NCBrandColor.cacheImages.folderExternal
-            } else if metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory {
-                cell.imageItem.image = NCBrandColor.cacheImages.folderAutomaticUpload
-            } else {
-                cell.imageItem.image = NCBrandColor.cacheImages.folder
-            }
-
-            cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date)
-
-            let lockServerUrl = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!
-            let tableDirectory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", activeAccount.account, lockServerUrl))
-
-            // Local image: offline
-            if tableDirectory != nil && tableDirectory!.offline {
-                cell.imageLocal.image = NCBrandColor.cacheImages.offlineFlag
-            }
-
+            setupDirectoryCell(cell, with: metadata)
         }
 
         // image Favorite
@@ -128,13 +102,51 @@ extension NCShareExtension: UICollectionViewDataSource {
         }
 
         // Remove last separator
-        if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {
-            cell.separator.isHidden = true
+        cell.separator.isHidden = collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1
+
+        return cell
+    }
+
+    func setupDirectoryCell(_ cell: NCListCell, with metadata: tableMetadata) {
+        var isShare = false
+        var isMounted = false
+        if let metadataFolder = metadataFolder {
+            isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionShared)
+            isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionMounted)
+        }
+
+        var tableShare: tableShare?
+        if dataSource.metadataShare[metadata.ocId] != nil {
+            tableShare = dataSource.metadataShare[metadata.ocId]
+        }
+
+        if metadata.e2eEncrypted {
+            cell.imageItem.image = NCBrandColor.cacheImages.folderEncrypted
+        } else if isShare {
+            cell.imageItem.image = NCBrandColor.cacheImages.folderSharedWithMe
+        } else if tableShare != nil && tableShare?.shareType != 3 {
+            cell.imageItem.image = NCBrandColor.cacheImages.folderSharedWithMe
+        } else if tableShare != nil && tableShare?.shareType == 3 {
+            cell.imageItem.image = NCBrandColor.cacheImages.folderPublic
+        } else if metadata.mountType == "group" {
+            cell.imageItem.image = NCBrandColor.cacheImages.folderGroup
+        } else if isMounted {
+            cell.imageItem.image = NCBrandColor.cacheImages.folderExternal
+        } else if metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory {
+            cell.imageItem.image = NCBrandColor.cacheImages.folderAutomaticUpload
         } else {
-            cell.separator.isHidden = false
+            cell.imageItem.image = NCBrandColor.cacheImages.folder
         }
 
-        return cell
+        cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date)
+
+        let lockServerUrl = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!
+        let tableDirectory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", activeAccount.account, lockServerUrl))
+
+        // Local image: offline
+        if tableDirectory != nil && tableDirectory!.offline {
+            cell.imageLocal.image = NCBrandColor.cacheImages.offlineFlag
+        }
     }
 }
 

+ 17 - 2
Share/NCShareExtension+Files.swift

@@ -3,7 +3,22 @@
 //  Share
 //
 //  Created by Henrik Storch on 29.12.21.
-//  Copyright © 2021 Marino Faggiana. All rights reserved.
+//  Copyright © 2021 Henrik Storch. All rights reserved.
+//
+//  Author Henrik Storch <henrik.storch@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
 import Foundation
@@ -129,7 +144,7 @@ class NCFilesExtensionHandler {
     }
 
     // URL
-    // FIXME: Does not work for directories
+    // Does not work for directories
     func getItem(url: URL, fileName: String) -> String? {
         var fileName = fileName
         guard url.isFileURL else {

+ 134 - 0
Share/NCShareExtension+NCDelegate.swift

@@ -0,0 +1,134 @@
+//
+//  NCShareExtension.swift
+//  Share
+//
+//  Created by Marino Faggiana on 04.01.2022.
+//  Copyright © 2022 Henrik Storch. All rights reserved.
+//
+//  Author Henrik Storch <henrik.storch@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import NCCommunication
+import UIKit
+
+extension NCShareExtension: NCEmptyDataSetDelegate, NCAccountRequestDelegate {
+    // MARK: - Empty
+
+    func emptyDataSetView(_ view: NCEmptyView) {
+
+        if networkInProgress {
+            view.emptyImage.image = UIImage(named: "networkInProgress")?.image(color: .gray, size: UIScreen.main.bounds.width)
+            view.emptyTitle.text = NSLocalizedString("_request_in_progress_", comment: "")
+            view.emptyDescription.text = ""
+        } else {
+            view.emptyImage.image = UIImage(named: "folder")?.image(color: NCBrandColor.shared.brandElement, size: UIScreen.main.bounds.width)
+            view.emptyTitle.text = NSLocalizedString("_files_no_folders_", comment: "")
+            view.emptyDescription.text = ""
+        }
+    }
+
+    // MARK: - Account
+
+    func showAccountPicker() {
+        let accounts = NCManageDatabase.shared.getAllAccountOrderAlias()
+        guard accounts.count > 1,
+              let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest else { return }
+
+        // Only here change the active account
+        for account in accounts {
+            account.active = account.account == self.activeAccount.account
+        }
+
+        vcAccountRequest.activeAccount = self.activeAccount
+        vcAccountRequest.accounts = accounts.sorted { sorg, dest -> Bool in
+            return sorg.active && !dest.active
+        }
+        vcAccountRequest.enableTimerProgress = false
+        vcAccountRequest.enableAddAccount = false
+        vcAccountRequest.delegate = self
+        vcAccountRequest.dismissDidEnterBackground = true
+
+        let screenHeighMax = UIScreen.main.bounds.height - (UIScreen.main.bounds.height / 5)
+        let height = min(CGFloat(accounts.count * Int(vcAccountRequest.heightCell) + 45), screenHeighMax)
+
+        let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: height + 20)
+
+        self.present(popup, animated: true)
+    }
+
+    func accountRequestChangeAccount(account: String) {
+        guard let activeAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else {
+            extensionContext?.cancelRequest(withError: NCShareExtensionError.noAccount)
+            return
+        }
+        self.activeAccount = activeAccount
+
+        // NETWORKING
+        NCCommunicationCommon.shared.setup(
+            account: activeAccount.account,
+            user: activeAccount.user,
+            userId: activeAccount.userId,
+            password: CCUtility.getPassword(activeAccount.account),
+            urlBase: activeAccount.urlBase,
+            userAgent: CCUtility.getUserAgent(),
+            webDav: NCUtilityFileSystem.shared.getWebDAV(account: activeAccount.account),
+            nextcloudVersion: 0,
+            delegate: NCNetworking.shared)
+
+        // get auto upload folder
+        autoUploadFileName = NCManageDatabase.shared.getAccountAutoUploadFileName()
+        autoUploadDirectory = NCManageDatabase.shared.getAccountAutoUploadDirectory(urlBase: activeAccount.urlBase, account: activeAccount.account)
+
+        serverUrl = NCUtilityFileSystem.shared.getHomeServer(account: activeAccount.account)
+
+        layoutForView = NCUtility.shared.getLayoutForView(key: keyLayout, serverUrl: serverUrl)
+
+        reloadDatasource(withLoadFolder: true)
+        setNavigationBar(navigationTitle: NCBrandOptions.shared.brand)
+    }
+}
+
+extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate, NCListCellDelegate {
+    func removeFile(named fileName: String) {
+        guard let index = self.filesName.firstIndex(of: fileName) else {
+            return showAlert(title: "_file_not_found_", description: fileName)
+        }
+        self.filesName.remove(at: index)
+        if self.filesName.isEmpty {
+            self.extensionContext?.cancelRequest(withError: NCShareExtensionError.noFiles)
+        } else {
+            self.setCommandView()
+        }
+    }
+
+    func rename(fileName: String, fileNameNew: String) {
+        guard let fileIx = self.filesName.firstIndex(of: fileName),
+              !self.filesName.contains(fileNameNew),
+              NCUtilityFileSystem.shared.moveFile(atPath: (NSTemporaryDirectory() + fileName), toPath: (NSTemporaryDirectory() + fileNameNew)) else {
+                  return showAlert(title: "_single_file_conflict_title_", description: "'\(fileName)' -> '\(fileNameNew)'")
+              }
+
+        filesName[fileIx] = fileNameNew
+        tableView.reloadData()
+    }
+}
+
+extension NCShareExtension: NCCreateFormUploadConflictDelegate {
+    func dismissCreateFormUploadConflict(metadatas: [tableMetadata]?) {
+        metadatas?.forEach { self.upload($0) }
+        uploadDispatchGroup?.leave()
+    }
+}

+ 42 - 185
Share/NCShareExtension.swift

@@ -1,6 +1,6 @@
 //
 //  NCShareExtension.swift
-//  Nextcloud
+//  Share
 //
 //  Created by Marino Faggiana on 20/04/2021.
 //  Copyright © 2021 Marino Faggiana. All rights reserved.
@@ -31,7 +31,7 @@ enum NCShareExtensionError: Error {
     case cancel, fileUpload, noAccount, noFiles
 }
 
-class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDelegate, NCAccountRequestDelegate {
+class NCShareExtension: UIViewController {
 
     @IBOutlet weak var collectionView: UICollectionView!
     @IBOutlet weak var tableView: UITableView!
@@ -75,7 +75,7 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
 
     private var numberFilesName: Int = 0
     private var counterUpload: Int = 0
-    private var uploadDispatchGroup: DispatchGroup?
+    var uploadDispatchGroup: DispatchGroup?
     private var uploadErrors: [tableMetadata] = []
     private var uploadStarted = false
 
@@ -155,7 +155,7 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
             }
         }
 
-        setAccount(account: activeAccount.account)
+        accountRequestChangeAccount(account: activeAccount.account)
         guard let inputItems = extensionContext?.inputItems as? [NSExtensionItem] else {
             self.extensionContext?.cancelRequest(withError: NCShareExtensionError.noFiles)
             return
@@ -166,17 +166,8 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         }
     }
 
-    func showAlert(title: String = "_error_", description: String, onDismiss: (() -> Void)? = nil) {
-        let alertController = UIAlertController(title: NSLocalizedString(title, comment: ""), message: NSLocalizedString(description, comment: ""), preferredStyle: .alert)
-        alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in
-            onDismiss?()
-        }))
-        self.present(alertController, animated: true)
-    }
-
     override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
         super.viewWillTransition(to: size, with: coordinator)
-
         coordinator.animate(alongsideTransition: nil) { _ in
             self.collectionView?.collectionViewLayout.invalidateLayout()
         }
@@ -184,64 +175,34 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
 
     override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
         super.traitCollectionDidChange(previousTraitCollection)
-
         collectionView.reloadData()
         tableView.reloadData()
     }
 
     // MARK: -
 
-    @objc func triggerProgressTask(_ notification: NSNotification) {
+    func showAlert(title: String = "_error_", description: String, onDismiss: (() -> Void)? = nil) {
+        let alertController = UIAlertController(title: NSLocalizedString(title, comment: ""), message: NSLocalizedString(description, comment: ""), preferredStyle: .alert)
+        alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in
+            onDismiss?()
+        }))
+        self.present(alertController, animated: true)
+    }
 
+    @objc func triggerProgressTask(_ notification: NSNotification) {
         if let userInfo = notification.userInfo as NSDictionary?, let progressNumber = userInfo["progress"] as? NSNumber {
-
             let progress = CGFloat(progressNumber.floatValue)
             let status = NSLocalizedString("_upload_file_", comment: "") + " \(self.counterUpload) " + NSLocalizedString("_of_", comment: "") + " \(self.numberFilesName)"
             IHProgressHUD.show(progress: progress, status: status)
         }
     }
 
-    // MARK: -
-
-    func setAccount(account: String) {
-
-        guard let activeAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else {
-            extensionContext?.cancelRequest(withError: NCShareExtensionError.noAccount)
-            return
-        }
-        self.activeAccount = activeAccount
-
-        // NETWORKING
-        NCCommunicationCommon.shared.setup(
-            account: activeAccount.account,
-            user: activeAccount.user,
-            userId: activeAccount.userId,
-            password: CCUtility.getPassword(activeAccount.account),
-            urlBase: activeAccount.urlBase,
-            userAgent: CCUtility.getUserAgent(),
-            webDav: NCUtilityFileSystem.shared.getWebDAV(account: activeAccount.account),
-            nextcloudVersion: 0,
-            delegate: NCNetworking.shared)
-
-        // get auto upload folder
-        autoUploadFileName = NCManageDatabase.shared.getAccountAutoUploadFileName()
-        autoUploadDirectory = NCManageDatabase.shared.getAccountAutoUploadDirectory(urlBase: activeAccount.urlBase, account: activeAccount.account)
-
-        serverUrl = NCUtilityFileSystem.shared.getHomeServer(account: activeAccount.account)
-
-        layoutForView = NCUtility.shared.getLayoutForView(key: keyLayout, serverUrl: serverUrl)
-
-        reloadDatasource(withLoadFolder: true)
-        setNavigationBar(navigationTitle: NCBrandOptions.shared.brand)
-    }
-
     func setNavigationBar(navigationTitle: String) {
 
         navigationItem.title = navigationTitle
         cancelButton.title = NSLocalizedString("_cancel_", comment: "")
 
         // BACK BUTTON
-
         let backButton = UIButton(type: .custom)
         backButton.setImage(UIImage(named: "back"), for: .normal)
         backButton.tintColor = .systemBlue
@@ -250,9 +211,7 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         backButton.setTitleColor(.systemBlue, for: .normal)
         backButton.action(for: .touchUpInside) { _ in
 
-            while self.serverUrl.last != "/" {
-                self.serverUrl.removeLast()
-            }
+            while self.serverUrl.last != "/" { self.serverUrl.removeLast() }
             self.serverUrl.removeLast()
 
             self.reloadDatasource(withLoadFolder: true)
@@ -265,7 +224,6 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         }
 
         // PROFILE BUTTON
-
         let image = NCUtility.shared.loadUserImage(
             for: activeAccount.user,
                displayName: activeAccount.displayName,
@@ -290,94 +248,34 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         profileButton.semanticContentAttribute = .forceLeftToRight
         profileButton.sizeToFit()
         profileButton.action(for: .touchUpInside) { _ in
-
-            let accounts = NCManageDatabase.shared.getAllAccountOrderAlias()
-            if accounts.count > 1 {
-
-                if let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest {
-
-                    // Only here change the active account
-                    for account in accounts {
-                        if account.account == self.activeAccount.account {
-                            account.active = true
-                        } else {
-                            account.active = false
-                        }
-                    }
-
-                    vcAccountRequest.activeAccount = self.activeAccount
-                    vcAccountRequest.accounts = accounts.sorted { sorg, dest -> Bool in
-                        return sorg.active && !dest.active
-                    }
-                    vcAccountRequest.enableTimerProgress = false
-                    vcAccountRequest.enableAddAccount = false
-                    vcAccountRequest.delegate = self
-                    vcAccountRequest.dismissDidEnterBackground = true
-
-                    let screenHeighMax = UIScreen.main.bounds.height - (UIScreen.main.bounds.height / 5)
-                    let numberCell = accounts.count
-                    let height = min(CGFloat(numberCell * Int(vcAccountRequest.heightCell) + 45), screenHeighMax)
-
-                    let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: height + 20)
-
-                    self.present(popup, animated: true)
-                }
-            }
+            self.showAccountPicker()
         }
-
-        if serverUrl == NCUtilityFileSystem.shared.getHomeServer(account: activeAccount.account) {
-
-            navigationItem.setLeftBarButtonItems([UIBarButtonItem(customView: profileButton)], animated: true)
-
-        } else {
-
+        var navItems = [UIBarButtonItem(customView: profileButton)]
+        if serverUrl != NCUtilityFileSystem.shared.getHomeServer(account: activeAccount.account) {
             let space = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
             space.width = 20
-
-            navigationItem.setLeftBarButtonItems([UIBarButtonItem(customView: backButton), space, UIBarButtonItem(customView: profileButton)], animated: true)
+            navItems.append(contentsOf: [UIBarButtonItem(customView: backButton), space])
         }
+        navigationItem.setLeftBarButtonItems(navItems, animated: true)
     }
 
     func setCommandView() {
-
-        var counter: CGFloat = 0
-
-        if filesName.isEmpty {
+        guard !filesName.isEmpty else {
             self.extensionContext?.cancelRequest(withError: NCShareExtensionError.noFiles)
             return
-        } else {
-            if filesName.count < 3 {
-                counter = CGFloat(filesName.count)
-                self.commandViewHeightConstraint.constant = heightCommandView + (self.heightRowTableView * counter)
-            } else {
-                counter = 3
-                self.commandViewHeightConstraint.constant = heightCommandView + (self.heightRowTableView * counter)
-            }
-            if filesName.count <= 3 {
-                self.tableView.isScrollEnabled = false
-            }
-            // Label upload button
-            numberFilesName = filesName.count
-            uploadLabel.text = NSLocalizedString("_upload_", comment: "") + " \(numberFilesName) " + NSLocalizedString("_files_", comment: "")
-            // Empty
-            emptyDataSet = NCEmptyDataSet(view: collectionView, offset: -50 * counter, delegate: self)
-            self.tableView.reloadData()
         }
-    }
-
-    // MARK: - Empty
-
-    func emptyDataSetView(_ view: NCEmptyView) {
+        let counter = min(CGFloat(filesName.count), 3)
+        self.commandViewHeightConstraint.constant = heightCommandView + (self.heightRowTableView * counter)
 
-        if networkInProgress {
-            view.emptyImage.image = UIImage(named: "networkInProgress")?.image(color: .gray, size: UIScreen.main.bounds.width)
-            view.emptyTitle.text = NSLocalizedString("_request_in_progress_", comment: "")
-            view.emptyDescription.text = ""
-        } else {
-            view.emptyImage.image = UIImage(named: "folder")?.image(color: NCBrandColor.shared.brandElement, size: UIScreen.main.bounds.width)
-            view.emptyTitle.text = NSLocalizedString("_files_no_folders_", comment: "")
-            view.emptyDescription.text = ""
+        if filesName.count <= 3 {
+            self.tableView.isScrollEnabled = false
         }
+        // Label upload button
+        numberFilesName = filesName.count
+        uploadLabel.text = NSLocalizedString("_upload_", comment: "") + " \(numberFilesName) " + NSLocalizedString("_files_", comment: "")
+        // Empty
+        emptyDataSet = NCEmptyDataSet(view: collectionView, offset: -50 * counter, delegate: self)
+        self.tableView.reloadData()
     }
 
     // MARK: ACTION
@@ -407,7 +305,10 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
 
         self.present(alertController, animated: true, completion: nil)
     }
+}
 
+// MARK: - Upload
+extension NCShareExtension {
     @objc func actionUpload() {
         guard !uploadStarted else { return }
         guard !filesName.isEmpty else { return showAlert(description: "_files_no_files_") }
@@ -421,19 +322,13 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         var conflicts: [tableMetadata] = []
         for fileName in filesName {
             let ocId = NSUUID().uuidString
-            let atPath = (NSTemporaryDirectory() + fileName)
             let toPath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)!
-            guard NCUtilityFileSystem.shared.copyFile(atPath: atPath, toPath: toPath) else { continue }
+            guard NCUtilityFileSystem.shared.copyFile(atPath: (NSTemporaryDirectory() + fileName), toPath: toPath) else { continue }
             let metadata = NCManageDatabase.shared.createMetadata(
-                account: activeAccount.account,
-                user: activeAccount.user,
-                userId: activeAccount.userId,
-                fileName: fileName,
-                fileNameView: fileName,
+                account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId,
+                fileName: fileName, fileNameView: fileName,
                 ocId: ocId,
-                serverUrl: serverUrl,
-                urlBase: activeAccount.urlBase,
-                url: "",
+                serverUrl: serverUrl, urlBase: activeAccount.urlBase, url: "",
                 contentType: "",
                 livePhoto: false)
             metadata.session = NCCommunicationCommon.shared.sessionIdentifierUpload
@@ -450,14 +345,12 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         if !conflicts.isEmpty {
             uploadDispatchGroup?.enter()
             DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
-                if let conflict = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict {
-
-                    conflict.serverUrl = self.serverUrl
-                    conflict.metadatasUploadInConflict = conflicts
-                    conflict.delegate = self
-
-                    self.present(conflict, animated: true, completion: nil)
-                }
+                guard let conflict = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict
+                else { return }
+                conflict.serverUrl = self.serverUrl
+                conflict.metadatasUploadInConflict = conflicts
+                conflict.delegate = self
+                self.present(conflict, animated: true, completion: nil)
             }
         }
         uploadDispatchGroup?.leave()
@@ -503,40 +396,4 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
             }
         }
     }
-
-    func accountRequestChangeAccount(account: String) {
-        setAccount(account: account)
-    }
-}
-
-extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate {
-    func removeFile(named fileName: String) {
-        guard let index = self.filesName.firstIndex(of: fileName) else {
-            return showAlert(title: "_file_not_found_", description: fileName)
-        }
-        self.filesName.remove(at: index)
-        if self.filesName.isEmpty {
-            self.extensionContext?.cancelRequest(withError: NCShareExtensionError.noFiles)
-        } else {
-            self.setCommandView()
-        }
-    }
-
-    func rename(fileName: String, fileNameNew: String) {
-        guard let fileIx = self.filesName.firstIndex(of: fileName),
-              !self.filesName.contains(fileNameNew),
-              NCUtilityFileSystem.shared.moveFile(atPath: (NSTemporaryDirectory() + fileName), toPath: (NSTemporaryDirectory() + fileNameNew)) else {
-                  return showAlert(title: "_single_file_conflict_title_", description: "'\(fileName)' -> '\(fileNameNew)'")
-              }
-
-        filesName[fileIx] = fileNameNew
-        tableView.reloadData()
-    }
-}
-
-extension NCShareExtension: NCCreateFormUploadConflictDelegate {
-    func dismissCreateFormUploadConflict(metadatas: [tableMetadata]?) {
-        metadatas?.forEach { self.upload($0) }
-        uploadDispatchGroup?.leave()
-    }
 }