123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- import FloatingPanel
- import NCCommunication
- extension NCViewer {
- @objc func toggleMoreMenu(viewController: UIViewController, metadata: tableMetadata, webView: Bool) {
-
- let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
-
- mainMenuViewController.actions = self.initMoreMenu(viewController: viewController, metadata: metadata, webView: webView)
-
- let menuPanelController = NCMenuPanelController()
- menuPanelController.parentPresenter = viewController
- menuPanelController.delegate = mainMenuViewController
- menuPanelController.set(contentViewController: mainMenuViewController)
- menuPanelController.track(scrollView: mainMenuViewController.tableView)
- viewController.present(menuPanelController, animated: true, completion: nil)
- }
-
- private func initMoreMenu(viewController: UIViewController, metadata: tableMetadata, webView: Bool) -> [NCMenuAction] {
-
- var actions = [NCMenuAction]()
- var titleFavorite = NSLocalizedString("_add_favorites_", comment: "")
- if metadata.favorite { titleFavorite = NSLocalizedString("_remove_favorites_", comment: "") }
- let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-
- var titleOffline = ""
- if (localFile == nil || localFile!.offline == false) {
- titleOffline = NSLocalizedString("_set_available_offline_", comment: "")
- } else {
- titleOffline = NSLocalizedString("_remove_available_offline_", comment: "")
- }
-
- var titleDelete = NSLocalizedString("_delete_", comment: "")
- if NCManageDatabase.shared.isMetadataShareOrMounted(metadata: metadata, metadataFolder: nil) {
- titleDelete = NSLocalizedString("_leave_share_", comment: "")
- } else if metadata.directory {
- titleDelete = NSLocalizedString("_delete_folder_", comment: "")
- } else {
- titleDelete = NSLocalizedString("_delete_file_", comment: "")
- }
-
-
-
-
- actions.append(
- NCMenuAction(
- title: titleFavorite,
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.shared.yellowFavorite),
- action: { menuAction in
- NCNetworking.shared.favoriteMetadata(metadata, urlBase: self.appDelegate.urlBase) { (errorCode, errorDescription) in
- if errorCode != 0 {
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
- }
- }
- }
- )
- )
-
-
-
-
- if !appDelegate.disableSharesView {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_details_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.shared.icon),
- action: { menuAction in
- NCNetworkingNotificationCenter.shared.openShare(ViewController: viewController, metadata: metadata, indexPage: 0)
- }
- )
- )
- }
-
-
-
-
- if metadata.session == "" && !webView {
- actions.append(
- NCMenuAction(title: NSLocalizedString("_open_in_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.shared.icon),
- action: { menuAction in
- NCNetworkingNotificationCenter.shared.downloadOpen(metadata: metadata, selector: selectorOpenIn)
- }
- )
- )
- }
-
-
-
-
- if !webView {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_rename_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.shared.icon),
- action: { menuAction in
- let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
- alertController.addTextField { (textField) in textField.text = metadata.fileNameView }
- let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil)
- let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in
- let fileNameNew = alertController.textFields![0].text
- NCNetworking.shared.renameMetadata(metadata, fileNameNew: fileNameNew!, urlBase: self.appDelegate.urlBase, viewController: viewController) { (errorCode, errorDescription) in
- if errorCode != 0 {
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
- }
- }
- })
- alertController.addAction(cancelAction)
- alertController.addAction(okAction)
- viewController.present(alertController, animated: true, completion: nil)
- }
- )
- )
- }
-
-
-
-
- if !webView {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_move_or_copy_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.shared.icon),
- action: { menuAction in
-
- let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
- let navigationController = storyboard.instantiateInitialViewController() as! UINavigationController
- let viewController = navigationController.topViewController as! NCSelect
-
- viewController.delegate = NCViewer.shared
- viewController.hideButtonCreateFolder = false
- viewController.items = [metadata]
- viewController.selectFile = false
- viewController.includeDirectoryE2EEncryption = false
- viewController.includeImages = false
- viewController.type = ""
- viewController.titleButtonDone = NSLocalizedString("_move_", comment: "")
- viewController.titleButtonDone1 = NSLocalizedString("_copy_", comment: "")
- viewController.isButtonDone1Hide = false
- viewController.isOverwriteHide = false
-
- navigationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen
- self.appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
- }
- )
- )
- }
-
-
-
-
- if metadata.session == "" && !webView {
- actions.append(
- NCMenuAction(
- title: titleOffline,
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.shared.icon),
- action: { menuAction in
- if ((localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) && metadata.session == "") {
-
- NCNetworking.shared.download(metadata: metadata, selector: selectorLoadOffline) { (_) in }
- } else {
- NCManageDatabase.shared.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
- }
- }
- )
- )
- }
-
-
-
-
- if !webView {
- if appDelegate.activeFileViewInFolder == nil {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_view_in_folder_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "viewInFolder"), width: 50, height: 50, color: NCBrandColor.shared.icon),
- action: { menuAction in
- NCCollectionCommon.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileName: metadata.fileName)
- }
- )
- )
- }
- }
-
-
-
-
- if !webView {
- actions.append(
- NCMenuAction(title: titleDelete,
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: NCBrandColor.shared.icon),
- action: { menuAction in
-
- let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
-
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (action:UIAlertAction) in
-
- NCNetworking.shared.deleteMetadata(metadata, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, onlyLocal: false) { (errorCode, errorDescription) in
- if errorCode != 0 {
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
- }
- }
- })
-
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (action:UIAlertAction) in })
-
- viewController.present(alertController, animated: true, completion:nil)
- }
- )
- )
- }
-
-
-
-
- if (metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileDocument && metadata.contentType == "application/pdf" ) {
- actions.append(
- NCMenuAction(title: NSLocalizedString("_search_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "search"), width: 50, height: 50, color: NCBrandColor.shared.icon),
- action: { menuAction in
- NotificationCenter.default.postOnMainThread(name: NCBrandGlobal.shared.notificationCenterMenuSearchTextPDF)
- }
- )
- )
- }
-
-
-
-
- if metadata.session == "" {
- if metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileImage && !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && metadata.session == "" {
- actions.append(
- NCMenuAction(title: NSLocalizedString("_download_image_max_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "downloadImageFullRes"), width: 50, height: 50, color: NCBrandColor.shared.icon),
- action: { menuAction in
- NCNetworking.shared.download(metadata: metadata, selector: "") { (_) in }
- }
- )
- )
- }
- }
-
- if metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileImage || metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileVideo || metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileAudio {
- if let metadataLive = NCManageDatabase.shared.isLivePhoto(metadata: metadata) {
- if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataLive.ocId, fileNameView: metadataLive.fileNameView) {
- actions.append(
- NCMenuAction(title: NSLocalizedString("_livephoto_save_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "livePhoto"), width: 50, height: 50, color: NCBrandColor.shared.icon),
- action: { menuAction in
- NotificationCenter.default.postOnMainThread(name: NCBrandGlobal.shared.notificationCenterMenuSaveLivePhoto, userInfo: ["ocId": metadata.ocId, "ocIdMov": metadataLive.ocId])
- }
- )
- )
- }
- }
- }
-
- return actions
- }
- }
|