From 129b98fb050748787bdf285301e0b7e39597e996 Mon Sep 17 00:00:00 2001 From: TSI-amrutwaghmare <96108296+TSI-amrutwaghmare@users.noreply.github.com> Date: Wed, 10 Apr 2024 14:52:24 +0530 Subject: [PATCH] NMC 2253 - Menu update after NC 5.0 Release --- iOSClient/Menu/NCContextMenu.swift | 121 ++++++++++++++++++++++------- iOSClient/Menu/NCViewer+Menu.swift | 97 ++++++----------------- 2 files changed, 117 insertions(+), 101 deletions(-) diff --git a/iOSClient/Menu/NCContextMenu.swift b/iOSClient/Menu/NCContextMenu.swift index bce48972eb..efe9f95367 100644 --- a/iOSClient/Menu/NCContextMenu.swift +++ b/iOSClient/Menu/NCContextMenu.swift @@ -35,7 +35,7 @@ class NCContextMenu: NSObject { let utilityFileSystem = NCUtilityFileSystem() let utility = NCUtility() - func viewMenu(ocId: String, viewController: UIViewController, image: UIImage?) -> UIMenu { + func viewMenu(ocId: String, indexPath: IndexPath, viewController: UIViewController, image: UIImage?) -> UIMenu { guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return UIMenu() } var downloadRequest: DownloadRequest? @@ -43,16 +43,6 @@ class NCContextMenu: NSObject { let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) if metadata.directory { titleDeleteConfirmFile = NSLocalizedString("_delete_folder_", comment: "") } - if metadataMOV != nil { titleSave = NSLocalizedString("_livephoto_save_", comment: "") } - - let serverUrl = metadata.serverUrl + "/" + metadata.fileName - var isOffline: Bool = false - - if metadata.directory, let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl)) { - isOffline = directory.offline - } else if let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) { - isOffline = localFile.offline - } let hud = JGProgressHUD() hud.indicatorView = JGProgressHUDRingIndicatorView() @@ -64,13 +54,25 @@ class NCContextMenu: NSObject { request.cancel() } } + + var titleSave: String = NSLocalizedString("_save_selected_files_", comment: "") + if metadataMOV != nil { titleSave = NSLocalizedString("_livephoto_save_", comment: "") } + let serverUrl = metadata.serverUrl + "/" + metadata.fileName + var isOffline: Bool = false + + if metadata.directory, let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl)) { + isOffline = directory.offline + } else if let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) { + isOffline = localFile.offline + } // MENU ITEMS - let detail = UIAction(title: NSLocalizedString("_details_", comment: "")) { _ in + let detail = UIAction(title: NSLocalizedString("_details_", comment: ""), + image: UIImage(systemName: "info.circle")) { _ in NCActionCenter.shared.openShare(viewController: viewController, metadata: metadata, page: .activity) } - + let titleOffline = isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: "") let offline = UIAction(title: titleOffline, image: UIImage(systemName: "tray.and.arrow.down")) { _ in @@ -81,7 +83,7 @@ class NCContextMenu: NSObject { } let print = UIAction(title: NSLocalizedString("_print_", comment: ""), image: UIImage(systemName: "printer") ) { _ in - NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorPrint) { _, _ in } + NCNetworking.shared.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: NCGlobal.shared.selectorPrint)) } let moveCopy = UIAction(title: NSLocalizedString("_move_or_copy_", comment: ""), image: UIImage(systemName: "arrow.up.right.square")) { action in @@ -124,7 +126,7 @@ class NCContextMenu: NSObject { let favorite = UIAction(title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""), - image: utility.loadImage(named: metadata.favorite ? "star.slash" : "star", color: NCBrandColor.shared.yellowFavorite)) { _ in + image: utility.loadImage(named: "star.fill", color: NCBrandColor.shared.yellowFavorite)) { _ in NCNetworking.shared.favoriteMetadata(metadata) { error in if error != .success { NCContentPresenter().showError(error: error) @@ -132,6 +134,76 @@ class NCContextMenu: NSObject { } } + let openIn = UIAction(title: NSLocalizedString("_open_in_", comment: ""), + image: UIImage(systemName: "square.and.arrow.up") ) { _ in + if self.utilityFileSystem.fileProviderStorageExists(metadata) { + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "selector": NCGlobal.shared.selectorOpenIn, "error": NKError(), "account": metadata.account]) + } else { + guard let metadata = NCManageDatabase.shared.setMetadatasSessionInWaitDownload(metadatas: [metadata], + session: NextcloudKit.shared.nkCommonInstance.sessionIdentifierDownload, + selector: NCGlobal.shared.selectorOpenIn) else { return } + hud.show(in: viewController.view) + NCNetworking.shared.download(metadata: metadata, withNotificationProgressTask: false) { + } requestHandler: { request in + downloadRequest = request + } progressHandler: { progress in + hud.progress = Float(progress.fractionCompleted) + } completion: { afError, error in + DispatchQueue.main.async { + if error == .success || afError?.isExplicitlyCancelledError ?? false { + hud.dismiss() + } else { + hud.indicatorView = JGProgressHUDErrorIndicatorView() + hud.textLabel.text = error.description + hud.dismiss(afterDelay: NCGlobal.shared.dismissAfterSecond) + } + } + } + } + } + + let viewInFolder = UIAction(title: NSLocalizedString("_view_in_folder_", comment: ""), + image: UIImage(systemName: "arrow.forward.square")) { _ in + NCActionCenter.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName, fileNameOpen: nil) + } + + let save = UIAction(title: titleSave, + image: UIImage(systemName: "square.and.arrow.down")) { _ in + if let metadataMOV = metadataMOV { + NCNetworking.shared.saveLivePhotoQueue.addOperation(NCOperationSaveLivePhoto(metadata: metadata, metadataMOV: metadataMOV)) + } else { + if self.utilityFileSystem.fileProviderStorageExists(metadata) { + NCActionCenter.shared.saveAlbum(metadata: metadata) + } else { + guard let metadata = NCManageDatabase.shared.setMetadatasSessionInWaitDownload(metadatas: [metadata], + session: NextcloudKit.shared.nkCommonInstance.sessionIdentifierDownload, + selector: NCGlobal.shared.selectorSaveAlbum) else { return } + hud.show(in: viewController.view) + NCNetworking.shared.download(metadata: metadata, withNotificationProgressTask: false) { + } requestHandler: { request in + downloadRequest = request + } progressHandler: { progress in + hud.progress = Float(progress.fractionCompleted) + } completion: { afError, error in + DispatchQueue.main.async { + if error == .success || afError?.isExplicitlyCancelledError ?? false { + hud.dismiss() + } else { + hud.indicatorView = JGProgressHUDErrorIndicatorView() + hud.textLabel.text = error.description + hud.dismiss(afterDelay: NCGlobal.shared.dismissAfterSecond) + } + } + } + } + } + } + + let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), + image: UIImage(systemName: "doc.on.doc")) { _ in + NCActionCenter.shared.copyPasteboard(pasteboardOcIds: [metadata.ocId]) + } + let share = UIAction(title: NSLocalizedString("_share_", comment: ""), image: UIImage(systemName: "square.and.arrow.up") ) { _ in if self.utilityFileSystem.fileProviderStorageExists(metadata) { @@ -166,10 +238,6 @@ class NCContextMenu: NSObject { } } - let viewInFolder = UIAction(title: NSLocalizedString("_view_in_folder_", comment: ""), - image: UIImage(systemName: "arrow.forward.square")) { _ in - NCActionCenter.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName, fileNameOpen: nil) - } let livePhotoSave = UIAction(title: NSLocalizedString("_livephoto_save_", comment: ""), image: UIImage(systemName: "livephoto")) { _ in @@ -177,11 +245,6 @@ class NCContextMenu: NSObject { NCNetworking.shared.saveLivePhotoQueue.addOperation(NCOperationSaveLivePhoto(metadata: metadata, metadataMOV: metadataMOV)) } } - - let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), - image: UIImage(systemName: "doc.on.doc")) { _ in - NCActionCenter.shared.copyPasteboard(pasteboardOcIds: [metadata.ocId]) - } let modify = UIAction(title: NSLocalizedString("_modify_", comment: ""), image: UIImage(systemName: "pencil.tip.crop.circle")) { _ in @@ -234,7 +297,7 @@ class NCContextMenu: NSObject { } else { NCContentPresenter().showError(error: error) } - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "onlyLocalCache": false, "error": error]) + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "indexPath": [indexPath], "onlyLocalCache": false, "error": error]) } }) alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { _ in }) @@ -251,7 +314,7 @@ class NCContextMenu: NSObject { } else { NCContentPresenter().showError(error: error) } - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "onlyLocalCache": true, "error": error]) + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocId, "indexPath": [indexPath], "onlyLocalCache": true, "error": error]) } } @@ -264,14 +327,14 @@ class NCContextMenu: NSObject { if metadata.directory { let serverUrlHome = utilityFileSystem.getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId) - let isEncryptionDisabled = metadata.isDirectoryUnsettableE2EE - let isEncrytptionEnabled = metadata.serverUrl == serverUrlHome && metadata.isDirectoySettableE2EE + let isEncryptionDisabled = metadata.canUnsetDirectoryAsE2EE + let isEncrytptionEnabled = metadata.serverUrl == serverUrlHome && metadata.canSetDirectoryAsE2EE let submenu = UIMenu(title: "", options: .displayInline, children: isEncrytptionEnabled ? [favorite, offline, rename, moveCopy, encrypt, deleteSubMenu] : [favorite, offline, rename, moveCopy, deleteSubMenu]) let childrenArray = metadata.e2eEncrypted ? ( isEncryptionDisabled ? [offline, decrypt] : (metadata.serverUrl == serverUrlHome) ? [offline] : [offline, deleteSubMenu]) : [detail,submenu] return UIMenu(title: "", children: childrenArray) } else { - + var children: [UIMenuElement] = metadata.e2eEncrypted ? [openIn, copy, deleteSubMenu] : [offline, openIn, deleteSubMenu] if !metadata.lock { diff --git a/iOSClient/Menu/NCViewer+Menu.swift b/iOSClient/Menu/NCViewer+Menu.swift index f18cf66113..e5d3abe79c 100644 --- a/iOSClient/Menu/NCViewer+Menu.swift +++ b/iOSClient/Menu/NCViewer+Menu.swift @@ -36,21 +36,6 @@ extension NCViewer { let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) let isOffline = localFile?.offline == true - // - // DETAIL - // - if !appDelegate.disableSharesView { - actions.append( - NCMenuAction( - title: NSLocalizedString("_details_", comment: ""), - icon: utility.loadImage(named: "info.circle"), - action: { _ in - NCActionCenter.shared.openShare(viewController: viewController, metadata: metadata, page: .activity) - } - ) - ) - } - // // VIEW IN FOLDER // @@ -58,7 +43,7 @@ extension NCViewer { actions.append( NCMenuAction( title: NSLocalizedString("_view_in_folder_", comment: ""), - icon: utility.loadImage(named: "questionmark.folder"), + icon: utility.loadImage(named: "arrow.forward.square", color: NCBrandColor.shared.iconColor), action: { _ in NCActionCenter.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName, fileNameOpen: nil) } @@ -70,11 +55,11 @@ extension NCViewer { // FAVORITE // Workaround: PROPPATCH doesn't work // https://github.com/nextcloud/files_lock/issues/68 - if !metadata.lock { + if !metadata.lock, !metadata.isDirectoryE2EE{ actions.append( NCMenuAction( title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""), - icon: utility.loadImage(named: metadata.favorite ? "star.slash.fill" : "star.fill", color: NCBrandColor.shared.yellowFavorite), + icon: utility.loadImage(named: "star.fill", color: NCBrandColor.shared.yellowFavorite), action: { _ in NCNetworking.shared.favoriteMetadata(metadata) { error in if error != .success { @@ -99,58 +84,42 @@ extension NCViewer { if !webView, metadata.canShare { actions.append(.share(selectedMetadatas: [metadata], viewController: viewController)) } - - // - // SAVE LIVE PHOTO - // - if let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) { - actions.append( - NCMenuAction( - title: NSLocalizedString("_livephoto_save_", comment: ""), - icon: NCUtility().loadImage(named: "livephoto"), - action: { _ in - NCNetworking.shared.saveLivePhotoQueue.addOperation(NCOperationSaveLivePhoto(metadata: metadata, metadataMOV: metadataMOV)) - } - ) - ) - } - + // - // SAVE AS SCAN + // PRINT // - if !webView, metadata.isSavebleAsImage { + if !webView, metadata.isPrintable { actions.append( NCMenuAction( - title: NSLocalizedString("_save_as_scan_", comment: ""), - icon: utility.loadImage(named: "doc.viewfinder"), + title: NSLocalizedString("_print_", comment: ""), + icon: utility.loadImage(named: "printer", color: NCBrandColor.shared.iconColor), action: { _ in if self.utilityFileSystem.fileProviderStorageExists(metadata) { - NotificationCenter.default.post( - name: Notification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), - object: nil, - userInfo: ["ocId": metadata.ocId, - "selector": NCGlobal.shared.selectorSaveAsScan, - "error": NKError(), - "account": metadata.account]) + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "selector": NCGlobal.shared.selectorPrint, "error": NKError(), "account": metadata.account]) } else { - guard let metadata = NCManageDatabase.shared.setMetadatasSessionInWaitDownload(metadatas: [metadata], - session: NextcloudKit.shared.nkCommonInstance.sessionIdentifierDownload, - selector: NCGlobal.shared.selectorSaveAsScan) else { return } - NCNetworking.shared.download(metadata: metadata, withNotificationProgressTask: true) + NCNetworking.shared.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: NCGlobal.shared.selectorPrint)) } } ) ) } + + // + // SAVE CAMERA ROLL + // + if !webView, metadata.isSavebleInCameraRoll { + actions.append(.saveMediaAction(selectedMediaMetadatas: [metadata])) + } + // // RENAME // - if !webView, metadata.isRenameable { + if !webView, metadata.isRenameable, !metadata.isDirectoryE2EE { actions.append( NCMenuAction( title: NSLocalizedString("_rename_", comment: ""), - icon: utility.loadImage(named: "text.cursor"), + icon: utility.loadImage(named: "rename", color: NCBrandColor.shared.iconColor), action: { _ in if let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile { @@ -177,25 +146,9 @@ extension NCViewer { } // - // DOWNLOAD FULL RESOLUTION - // - if !webView, metadata.session.isEmpty, !self.utilityFileSystem.fileProviderStorageExists(metadata) { - actions.append( - NCMenuAction( - title: NSLocalizedString("_try_download_full_resolution_", comment: ""), - icon: utility.loadImage(named: "photo"), - action: { _ in - guard let metadata = NCManageDatabase.shared.setMetadatasSessionInWaitDownload(metadatas: [metadata], - session: NextcloudKit.shared.nkCommonInstance.sessionIdentifierDownload, - selector: "") else { return } - NCNetworking.shared.download(metadata: metadata, withNotificationProgressTask: true) - } - ) - ) - } // COPY IN PASTEBOARD // - if !webView, metadata.isCopyableInPasteboard { + if !webView, metadata.isCopyableInPasteboard, !metadata.isDirectoryE2EE { actions.append(.copyAction(selectOcId: [metadata.ocId])) } @@ -206,7 +159,7 @@ extension NCViewer { actions.append( NCMenuAction( title: NSLocalizedString("_search_", comment: ""), - icon: UIImage(named: "search")!.image(color: UIColor.systemGray, size: 50), + icon: UIImage(named: "search")!.image(color: NCBrandColor.shared.iconColor, size: 50), action: { _ in NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuSearchTextPDF) } @@ -216,7 +169,7 @@ extension NCViewer { actions.append( NCMenuAction( title: NSLocalizedString("_go_to_page_", comment: ""), - icon: utility.loadImage(named: "repeat"), + icon: utility.loadImage(named: "go-to-page", color: NCBrandColor.shared.iconColor), action: { _ in NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuGotToPageInPDF) } @@ -231,7 +184,7 @@ extension NCViewer { actions.append( NCMenuAction( title: NSLocalizedString("_modify_", comment: ""), - icon: utility.loadImage(named: "pencil.tip.crop.circle"), + icon: utility.loadImage(named: "pencil.tip.crop.circle", color: NCBrandColor.shared.iconColor), action: { _ in if self.utilityFileSystem.fileProviderStorageExists(metadata) { NotificationCenter.default.post( @@ -256,7 +209,7 @@ extension NCViewer { // DELETE // if !webView, metadata.isDeletable { - actions.append(.deleteAction(selectedMetadatas: [metadata], indexPaths: [], metadataFolder: nil, viewController: viewController)) + actions.append(.deleteAction(selectedMetadatas: [metadata], indexPath: [], metadataFolder: nil, viewController: viewController)) } viewController.presentMenu(with: actions)