diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index de48cf1181..ec8c704363 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -85,6 +85,8 @@ AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */; }; AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* Shareable.swift */; }; CB3666201AF7550816B5CD6A /* NCContextMenuComment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8932E90EC4278026D86CCCC9 /* NCContextMenuComment.swift */; }; + B516E8DC2EF026F2005E049B /* NCViewer+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = B516E8DB2EF026F2005E049B /* NCViewer+Menu.swift */; }; + D575039F27146F93008DC9DC /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extension.swift */; }; D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; }; F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; }; F31165022F9674A1009A1E37 /* AppIcon.icon in Resources */ = {isa = PBXBuildFile; fileRef = F31165012F9674A1009A1E37 /* AppIcon.icon */; }; @@ -1263,6 +1265,7 @@ AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = ""; }; B4C7A5B36D1ED178FB6B76CB /* NCContextMenuPlayerTracks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCContextMenuPlayerTracks.swift; sourceTree = ""; }; BB7697C94BA14450A0867940 /* NCContextMenuProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCContextMenuProfile.swift; sourceTree = ""; }; + B516E8DB2EF026F2005E049B /* NCViewer+Menu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCViewer+Menu.swift"; sourceTree = ""; }; C0046CDA2A17B98400D87C9D /* NextcloudUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; C04E2F202A17BB4D001BAD85 /* NextcloudIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = ""; }; @@ -2046,6 +2049,7 @@ 371B5A2F23D0B04B00FAFAE9 /* Menu */ = { isa = PBXGroup; children = ( + B516E8DB2EF026F2005E049B /* NCViewer+Menu.swift */, F376A3732E5CC5FF0067EE25 /* ContextMenuActions.swift */, 8932E90EC4278026D86CCCC9 /* NCContextMenuComment.swift */, F78C6FDD296D677300C952C3 /* NCContextMenuMain.swift */, @@ -4659,6 +4663,7 @@ F7D4BF402CA2E8D800A5E746 /* TOPasscodeButtonLabel.m in Sources */, F70898692EDDB51700EF85BD /* NCSelectOpen+SelectDelegate.swift in Sources */, F7D4BF412CA2E8D800A5E746 /* TOPasscodeViewControllerAnimatedTransitioning.m in Sources */, + B516E8DC2EF026F2005E049B /* NCViewer+Menu.swift in Sources */, F7D4BF422CA2E8D800A5E746 /* TOPasscodeSettingsViewController.m in Sources */, F7D4BF432CA2E8D800A5E746 /* TOPasscodeCircleImage.m in Sources */, F78026102E9CFA3700B63436 /* NCTransfersView.swift in Sources */, diff --git a/iOSClient/Menu/NCViewer+Menu.swift b/iOSClient/Menu/NCViewer+Menu.swift new file mode 100644 index 0000000000..4202df8fae --- /dev/null +++ b/iOSClient/Menu/NCViewer+Menu.swift @@ -0,0 +1,216 @@ +// +// NCViewer.swift +// Nextcloud +// +// Created by Marino Faggiana on 07/02/2020. +// Copyright © 2020 Marino Faggiana All rights reserved. +// +// Author Marino Faggiana +// +// 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 . +// + +import UIKit +import FloatingPanel +import NextcloudKit + +extension NCViewer { + func toggleMenu(controller: NCMainTabBarController?, metadata: tableMetadata, webView: Bool, imageIcon: UIImage?, indexPath: IndexPath = IndexPath()) { + guard let metadata = self.database.getMetadataFromOcId(metadata.ocId), + let controller else { return } + var actions = [NCMenuAction]() + let localFile = self.database.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) + let isOffline = localFile?.offline == true + + // + // VIEW IN FOLDER + // + if !webView { + actions.append( + NCMenuAction( + title: NSLocalizedString("_view_in_folder_", comment: ""), + icon: utility.loadImage(named: "arrow.forward.square", colors: [NCBrandColor.shared.iconColor]), + action: { _ in + NCActionCenter.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName, fileNameOpen: nil, sceneIdentifier: controller.sceneIdentifier) + } + ) + ) + } + + // + // FAVORITE + // Workaround: PROPPATCH doesn't work + // https://github.com/nextcloud/files_lock/issues/68 + if !metadata.lock, !metadata.isDirectoryE2EE{ + actions.append( + NCMenuAction( + title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""), + icon: utility.loadImage(named: "star.fill", colors: [NCBrandColor.shared.yellowFavorite]), + action: { _ in + NCNetworking.shared.favoriteMetadata(metadata) { error in + if error != .success { + NCContentPresenter().showError(error: error) + } + } + } + ) + ) + } + + // + // OFFLINE + // + if !webView, metadata.canSetAsAvailableOffline { + actions.append(.setAvailableOfflineAction(selectedMetadatas: [metadata], isAnyOffline: isOffline, viewController: controller)) + } + + // + // SHARE + // + if !webView, metadata.canShare { + actions.append(.share(selectedMetadatas: [metadata], controller: controller)) + } + + // + // PRINT + // + if !webView, metadata.isPrintable { + actions.append( + NCMenuAction( + title: NSLocalizedString("_print_", comment: ""), + icon: utility.loadImage(named: "printer", colors: [NCBrandColor.shared.iconColor]), + action: { _ in + if self.utilityFileSystem.fileProviderStorageExists(metadata) { + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "selector": NCGlobal.shared.selectorPrint, "error": NKError(), "account": metadata.account, "ocIdTransfer": metadata.ocIdTransfer]) + } else { + NCNetworking.shared.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: NCGlobal.shared.selectorPrint)) + } + } + ) + ) + } + + // + // SAVE CAMERA ROLL + // + if !webView, metadata.isSavebleInCameraRoll { + actions.append(.saveMediaAction(selectedMediaMetadatas: [metadata], controller: controller)) + } + + + // + // RENAME + // + if !webView, metadata.isRenameable, !metadata.isDirectoryE2EE { + actions.append( + NCMenuAction( + title: NSLocalizedString("_rename_", comment: ""), + icon: utility.loadImage(named: "rename", colors: [NCBrandColor.shared.iconColor]), + action: { _ in + + if let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile { + + vcRename.metadata = metadata + vcRename.disableChangeExt = true + vcRename.imagePreview = imageIcon + vcRename.indexPath = indexPath + + let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height) + + controller.present(popup, animated: true) + } + } + ) + ) + } + + // + // COPY - MOVE + // + if !webView, metadata.isCopyableMovable { + actions.append(.moveOrCopyAction(selectedMetadatas: [metadata], controller: controller)) + } + + // COPY IN PASTEBOARD + // + if !webView, metadata.isCopyableInPasteboard, !metadata.isDirectoryE2EE { + actions.append(.copyAction(fileSelect: [metadata.ocId], controller: controller)) + } + + // + // PDF + // + if metadata.isPDF { + actions.append( + NCMenuAction( + title: NSLocalizedString("_search_", comment: ""), + icon: utility.loadImage(named: "search", colors: [NCBrandColor.shared.iconColor]), + action: { _ in + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuSearchTextPDF) + } + ) + ) + + actions.append( + NCMenuAction( + title: NSLocalizedString("_go_to_page_", comment: ""), + icon: utility.loadImage(named: "go-to-page", colors: [NCBrandColor.shared.iconColor]), + action: { _ in + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuGotToPageInPDF) + } + ) + ) + } + + // + // MODIFY WITH QUICK LOOK + // + if !webView, metadata.isModifiableWithQuickLook { + actions.append( + NCMenuAction( + title: NSLocalizedString("_modify_", comment: ""), + icon: utility.loadImage(named: "pencil.tip.crop.circle", colors: [NCBrandColor.shared.iconColor]), + action: { _ in + if self.utilityFileSystem.fileProviderStorageExists(metadata) { + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, + object: nil, + userInfo: ["ocId": metadata.ocId, + "ocIdTransfer": metadata.ocIdTransfer, + "session": metadata.session, + "selector": NCGlobal.shared.selectorLoadFileQuickLook, + "error": NKError(), + "account": metadata.account], + second: 0.5) + } else { + guard let metadata = self.database.setMetadatasSessionInWaitDownload(metadatas: [metadata], + session: NCNetworking.shared.sessionDownload, + selector: NCGlobal.shared.selectorLoadFileQuickLook, + sceneIdentifier: controller.sceneIdentifier) else { return } + NCNetworking.shared.download(metadata: metadata, withNotificationProgressTask: true) + } + } + ) + ) + } + + // + // DELETE + // + if !webView, metadata.isDeletable { + actions.append(.deleteAction(selectedMetadatas: [metadata], metadataFolder: nil, controller: controller)) + } + + controller.presentMenu(with: actions) + } +}