diff --git a/iOSClient/Files/NCFilesNavigationController.swift b/iOSClient/Files/NCFilesNavigationController.swift index 90d6004ee4..2dbfdfb51d 100644 --- a/iOSClient/Files/NCFilesNavigationController.swift +++ b/iOSClient/Files/NCFilesNavigationController.swift @@ -98,7 +98,7 @@ class NCFilesNavigationController: NCMainNavigationController { let action = UIAction(title: name, image: image, attributes: attributes, state: account.account == controller.account ? .on : .off) { _ in Task { @MainActor in await NCAccount().changeAccount(account.account, userProfile: nil, controller: self.controller) - self.collectionViewCommon?.setEditMode(false) + await self.collectionViewCommon?.setEditMode(false) } } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift index c6d7a5dfc0..9f37ebd5cb 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift @@ -26,8 +26,8 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { if canDeleteServer { alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .destructive) { _ in - self.setEditMode(false) Task { + await self.setEditMode(false) await self.networking.setStatusWaitDelete(metadatas: metadatas, sceneIdentifier: self.controller?.sceneIdentifier) await self.reloadDataSource() } @@ -42,8 +42,8 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { for metadata in copyMetadatas where error == .success { error = await self.networking.deleteCache(metadata, sceneIdentifier: self.controller?.sceneIdentifier) } + await self.setEditMode(false) } - self.setEditMode(false) }) alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { (_: UIAlertAction) in }) @@ -51,20 +51,23 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { } func move() { - let metadatas = getSelectedMetadatas() + Task { + let metadatas = getSelectedMetadatas() + await setEditMode(false) + + NCSelectOpen.shared.openView(items: metadatas, controller: self.controller) + } - NCSelectOpen.shared.openView(items: metadatas, controller: self.controller) - setEditMode(false) } func share() { Task { let metadatas = getSelectedMetadatas() + await setEditMode(false) await NCCreate().createActivityViewController( selectedMetadata: metadatas, controller: self.controller, sender: nil) - setEditMode(false) } } @@ -80,8 +83,9 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { for metadata in metadatas { await NCNetworking.shared.setMetadataAvalableOffline(metadata, isOffline: isAnyOffline) } + await self.setEditMode(false) } - self.setEditMode(false) + })) alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel)) self.present(alert, animated: true) @@ -90,17 +94,19 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { for metadata in metadatas { await NCNetworking.shared.setMetadataAvalableOffline(metadata, isOffline: isAnyOffline) } + await setEditMode(false) } - setEditMode(false) } } func lock(isAnyLocked: Bool) { - let metadatas = getSelectedMetadatas() - for metadata in metadatas where metadata.lock == isAnyLocked { - self.networking.lockUnlockFile(metadata, shoulLock: !isAnyLocked) + Task { + let metadatas = getSelectedMetadatas() + for metadata in metadatas where metadata.lock == isAnyLocked { + self.networking.lockUnlockFile(metadata, shoulLock: !isAnyLocked) + } + await setEditMode(false) } - setEditMode(false) } func getSelectedMetadatas() -> [tableMetadata] { @@ -112,24 +118,23 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { return selectedMetadatas } - func setEditMode(_ editMode: Bool) { - Task { - isEditMode = editMode - fileSelect.removeAll() - - navigationItem.hidesBackButton = editMode - navigationController?.interactivePopGestureRecognizer?.isEnabled = !editMode - searchController(enabled: !editMode) - mainNavigationController?.hiddenPlusButton(editMode) - - if editMode { - navigationItem.leftBarButtonItems = nil - } else { - await (self.navigationController as? NCMainNavigationController)?.setNavigationLeftItems() - } - await (self.navigationController as? NCMainNavigationController)?.setNavigationRightItems() + @MainActor + func setEditMode(_ editMode: Bool) async { + isEditMode = editMode + fileSelect.removeAll() - self.collectionView.reloadData() + navigationItem.hidesBackButton = editMode + navigationController?.interactivePopGestureRecognizer?.isEnabled = !editMode + searchController(enabled: !editMode) + mainNavigationController?.hiddenPlusButton(editMode) + + if editMode { + navigationItem.leftBarButtonItems = nil + } else { + await (self.navigationController as? NCMainNavigationController)?.setNavigationLeftItems() } + await (self.navigationController as? NCMainNavigationController)?.setNavigationRightItems() + + self.collectionView.reloadData() } } diff --git a/iOSClient/Main/NCMainNavigationController.swift b/iOSClient/Main/NCMainNavigationController.swift index 1c35e45932..86710f684e 100644 --- a/iOSClient/Main/NCMainNavigationController.swift +++ b/iOSClient/Main/NCMainNavigationController.swift @@ -542,7 +542,9 @@ class NCMainNavigationController: UINavigationController, UINavigationController collectionViewCommon.tabBarSelect?.show() let select = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: .plain) { - collectionViewCommon.setEditMode(false) + Task { + await collectionViewCommon.setEditMode(false) + } } collectionViewCommon.navigationItem.rightBarButtonItems = [select] @@ -634,9 +636,11 @@ class NCMainNavigationController: UINavigationController, UINavigationController let layoutForView = database.getLayoutForView(account: session.account, key: collectionViewCommon.layoutKey, serverUrl: collectionViewCommon.serverUrl) let select = UIAction(title: NSLocalizedString("_select_", comment: ""), image: utility.loadImage(named: "checkmark.circle")) { _ in - if !collectionViewCommon.dataSource.isEmpty() { - collectionViewCommon.setEditMode(true) - collectionViewCommon.collectionView.reloadData() + Task { + if !collectionViewCommon.dataSource.isEmpty() { + await collectionViewCommon.setEditMode(true) + collectionViewCommon.collectionView.reloadData() + } } }