diff options
author | Henrik Storch <henrik.storch@nextcloud.com> | 2022-03-24 11:14:07 +0300 |
---|---|---|
committer | Henrik Storch <henrik.storch@nextcloud.com> | 2022-05-10 11:57:20 +0300 |
commit | acc2221bf218fae04cfda7776547a203de8347cf (patch) | |
tree | 37391d914cbf713d7dba5812843c037b7adf9480 | |
parent | dbbbc9c87e8733c6c184a7af4b3a5e0ea19dc7b2 (diff) |
Improove files lock
- use NotificationCenter to reload data after lock/unlock instead of completion handler
- - keep using completion handler in action to dismiss selection
- adjust title for single / multiple files
Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
-rw-r--r-- | iOSClient/Main/Collection Common/NCSelectableNavigationView.swift | 5 | ||||
-rw-r--r-- | iOSClient/Main/NCFunctionCenter.swift | 16 | ||||
-rw-r--r-- | iOSClient/Menu/NCCollectionViewCommon+Menu.swift | 2 | ||||
-rw-r--r-- | iOSClient/Menu/NCMenuAction.swift | 15 | ||||
-rw-r--r-- | iOSClient/Networking/NCNetworking.swift | 5 | ||||
-rw-r--r-- | iOSClient/Supporting Files/en.lproj/Localizable.strings | 6 |
6 files changed, 26 insertions, 23 deletions
diff --git a/iOSClient/Main/Collection Common/NCSelectableNavigationView.swift b/iOSClient/Main/Collection Common/NCSelectableNavigationView.swift index dc3f45753..9c5511861 100644 --- a/iOSClient/Main/Collection Common/NCSelectableNavigationView.swift +++ b/iOSClient/Main/Collection Common/NCSelectableNavigationView.swift @@ -118,10 +118,7 @@ extension NCSelectableNavigationView where Self: UIViewController { actions.append(.openInAction(selectedMetadatas: selectedMetadatas, viewController: self, completion: tapSelect)) if !isAnyFolder { - actions.append(.lockUnlockFiles(shouldLock: !isAnyLocked, metadatas: selectedMetadatas, completion: { - self.reloadDataSource() - self.tapSelect() - })) + actions.append(.lockUnlockFiles(shouldLock: !isAnyLocked, metadatas: selectedMetadatas, completion: tapSelect)) } if !selectedMediaMetadatas.isEmpty { diff --git a/iOSClient/Main/NCFunctionCenter.swift b/iOSClient/Main/NCFunctionCenter.swift index 8a4459e70..88d8076bd 100644 --- a/iOSClient/Main/NCFunctionCenter.swift +++ b/iOSClient/Main/NCFunctionCenter.swift @@ -616,7 +616,8 @@ import SVGKit } } let titleOffline = isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: "") - + let titleLock = metadata.lock ? NSLocalizedString("_unlock_file_", comment: "") : NSLocalizedString("_lock_file_", comment: "") + let iconLock = metadata.lock ? "lock.open" : "lock" let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc")) { _ in self.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: viewController.view) } @@ -637,7 +638,10 @@ import SVGKit viewController.reloadDataSource() } } - + + let lockUnlock = UIAction(title: titleLock, image: NCUtility.shared.loadImage(named: iconLock)) { _ in + NCNetworking.shared.lockUnlockFile(metadata, shoulLock: !metadata.lock) + } let save = UIAction(title: titleSave, image: UIImage(systemName: "square.and.arrow.down")) { _ in if metadataMOV != nil { self.saveLivePhoto(metadata: metadata, metadataMOV: metadataMOV!) @@ -741,7 +745,7 @@ import SVGKit // FILE - var children: [UIMenuElement] = [favorite, offline, openIn, rename, moveCopy, copy, copyPath, delete] + var children: [UIMenuElement] = [favorite, lockUnlock, offline, openIn, rename, moveCopy, copy, copyPath, delete] if (metadata.contentType != "image/svg+xml") && (metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue) { children.insert(save, at: 2) @@ -756,18 +760,18 @@ import SVGKit } if enableViewInFolder { - children.insert(viewInFolder, at: children.count-1) + children.insert(viewInFolder, at: children.count - 1) } if (!isFolderEncrypted && metadata.contentType != "image/gif" && metadata.contentType != "image/svg+xml") && (metadata.contentType == "com.adobe.pdf" || metadata.contentType == "application/pdf" || metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue) { - children.insert(modify, at: children.count-1) + children.insert(modify, at: children.count - 1) } if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && viewController is NCCollectionViewCommon && !NCBrandOptions.shared.disable_background_image { let viewController: NCCollectionViewCommon = viewController as! NCCollectionViewCommon let layoutKey = viewController.layoutKey if layoutKey == NCGlobal.shared.layoutViewFiles { - children.insert(saveBackground, at: children.count-1) + children.insert(saveBackground, at: children.count - 1) } } diff --git a/iOSClient/Menu/NCCollectionViewCommon+Menu.swift b/iOSClient/Menu/NCCollectionViewCommon+Menu.swift index 4580d25d3..9621dd88d 100644 --- a/iOSClient/Menu/NCCollectionViewCommon+Menu.swift +++ b/iOSClient/Menu/NCCollectionViewCommon+Menu.swift @@ -89,7 +89,7 @@ extension NCCollectionViewCommon { ) if !metadata.directory { - actions.append(.lockUnlockFiles(shouldLock: !metadata.lock, metadatas: [metadata], completion: self.reloadDataSource)) + actions.append(.lockUnlockFiles(shouldLock: !metadata.lock, metadatas: [metadata])) } // diff --git a/iOSClient/Menu/NCMenuAction.swift b/iOSClient/Menu/NCMenuAction.swift index 2a78de319..ed9feae01 100644 --- a/iOSClient/Menu/NCMenuAction.swift +++ b/iOSClient/Menu/NCMenuAction.swift @@ -215,20 +215,21 @@ extension NCMenuAction { /// Lock or unlock a file using files_lock static func lockUnlockFiles(shouldLock: Bool, metadatas: [tableMetadata], completion: (() -> Void)? = nil) -> NCMenuAction { - let titleKey = !shouldLock ? "_unlock_file_" : "_lock_file_" + let titleKey: String + if metadatas.count == 1 { + titleKey = shouldLock ? "_lock_file_" : "_unlock_file_" + } else { + titleKey = shouldLock ? "_lock_selected_files_" : "_unlock_selected_files_" + } let imageName = !shouldLock ? "lock.open" : "lock" return NCMenuAction( title: NSLocalizedString(titleKey, comment: ""), icon: NCUtility.shared.loadImage(named: imageName), action: { _ in - let dispatchGroup = DispatchGroup() for metadata in metadatas where metadata.lock != shouldLock { - dispatchGroup.enter() - NCNetworking.shared.lockUnlockFile(metadata, shoulLock: shouldLock) { _, _ in - dispatchGroup.leave() - } + NCNetworking.shared.lockUnlockFile(metadata, shoulLock: shouldLock) } - dispatchGroup.notify(queue: .main, execute: completion ?? { }) + completion?() } ) } diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift index 48323ab52..bc7c6520f 100644 --- a/iOSClient/Networking/NCNetworking.swift +++ b/iOSClient/Networking/NCNetworking.swift @@ -1171,17 +1171,16 @@ import Queuer // MARK: - Lock Files - @objc func lockUnlockFile(_ metadata: tableMetadata, shoulLock: Bool, completion: @escaping (_ errorCode: Int, _ errorDescription: String) -> Void) { + @objc func lockUnlockFile(_ metadata: tableMetadata, shoulLock: Bool) { NCCommunication.shared.lockUnlockFile(shouldLock: shoulLock, fileId: metadata.fileId) { errorCode, errorDescription in guard errorCode == 0 else { - completion(errorCode, errorDescription) NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode, priority: .max) return } NCNetworking.shared.readFile(serverUrlFileName: metadata.serverUrl + "/" + metadata.fileName, account: metadata.account) { account, metadata, errorCode, errorDescription in - completion(errorCode, errorDescription) guard errorCode == 0, let metadata = metadata else { return } NCManageDatabase.shared.addMetadata(metadata) + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource) } } } diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index d911fb684..2f1a91453 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -148,8 +148,10 @@ "_leave_share_" = "Leave this share"; /* Files lock */ -"_lock_" = "Lock"; -"_unlock_" = "Unock"; +"_lock_file_" = "Lock file"; +"_unlock_file_" = "Unock file"; +"_lock_selected_files_" = "Lock files"; +"_unlock_selected_files_" = "Unock files"; /* Remove a file from a list, don't delete it entirely */ "_remove_file_" = "Remove file"; |