123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- import FloatingPanel
- import NCCommunication
- extension CCMain {
-
-
- @objc func toggleSelectMenu(viewController: UIViewController) {
-
- let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
- mainMenuViewController.actions = self.initSelectMenu()
- 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 initSelectMenu() -> [NCMenuAction] {
- var actions = [NCMenuAction]()
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_select_all_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "selectFull"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- self.didSelectAll()
- }
- )
- )
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- self.moveOpenWindow(self.tableView.indexPathsForSelectedRows)
- }
- )
- )
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_download_selected_files_folders_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "downloadSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- self.downloadSelectedFilesFolders()
- }
- )
- )
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_save_selected_files_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "saveSelectedFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- self.saveSelectedFiles()
- }
- )
- )
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_delete_selected_files_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
- action: { menuAction in
- self.deleteMetadatas()
- }
- )
- )
- return actions
- }
-
- @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) {
-
- if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(metadata.ocId) {
-
- let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
- mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata, metadataFolder: metadataFolder)
- 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(indexPath: IndexPath, metadata: tableMetadata, metadataFolder: tableMetadata) -> [NCMenuAction] {
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- var actions = [NCMenuAction]()
- if (metadata.directory) {
-
- var isOffline = false
- let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl+"/"+metadata.fileName, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account, urlBase: metadata.urlBase)
- if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!)) {
- isOffline = directory.offline
- }
- actions.append(
- NCMenuAction(
- title: metadata.fileNameView,
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement),
- action: nil
- )
- )
- actions.append(
- NCMenuAction(
- title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
- action: { menuAction in
- NCNetworking.shared.favoriteMetadata(metadata, urlBase: appDelegate.urlBase) { (errorCode, errorDescription) in }
- }
- )
- )
- if (!isFolderEncrypted) {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_details_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- NCMainCommon.shared.openShare(ViewController: self, metadata: metadata, indexPage: 0)
- }
- )
- )
- }
- if (!metadata.e2eEncrypted) {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_rename_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
- alertController.addTextField { (textField) in
- textField.text = metadata.fileNameView
- textField.delegate = self as? UITextFieldDelegate
- textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
- ), for: UIControl.Event.editingChanged)
- }
- 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: appDelegate.urlBase, viewController: self) { (errorCode, errorDescription) in }
- })
- okAction.isEnabled = false
- alertController.addAction(cancelAction)
- alertController.addAction(okAction)
- self.present(alertController, animated: true, completion: nil)
- }
- )
- )
- }
- if (!isFolderEncrypted) {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_move_or_copy_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- self.moveOpenWindow([indexPath])
- }
- )
- )
- }
- if (!isFolderEncrypted) {
- actions.append(
- NCMenuAction(
- title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") : NSLocalizedString("_set_available_offline_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- let serverUrl = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!
- NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, offline: !isOffline, account: appDelegate.account)
- if (!isOffline) {
- NCOperationQueue.shared.synchronizationMetadata(metadata, selector: selectorDownloadAllFile)
- }
- NotificationCenter.default.postOnMainThread(name: k_notificationCenter_reloadDataSource, userInfo: ["ocId":metadata.ocId, "serverUrl":metadata.serverUrl])
- }
- )
- )
- }
- if (!metadata.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.account)) {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_e2e_set_folder_encrypted_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- NCCommunication.shared.markE2EEFolder(fileId: metadata.fileId, delete: false) { (account, errorCode, errorDescription) in
- if errorCode == 0 {
- let serverUrl = self.serverUrl + "/" + metadata.fileName
- NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl))
- NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: true, richWorkspace: nil, account: metadata.account)
- NCManageDatabase.sharedInstance.setMetadataEncrypted(ocId: metadata.ocId, encrypted: true)
-
- NotificationCenter.default.postOnMainThread(name: k_notificationCenter_reloadDataSource, userInfo: ["ocId":metadata.ocId, "serverUrl":metadata.serverUrl])
- } else {
- NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_mark_folder_", comment: ""), description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: errorCode)
- }
- }
- }
- )
- )
- }
-
- if (metadata.e2eEncrypted && !metadataFolder.e2eEncrypted && CCUtility.isEnd(toEndEnabled: appDelegate.account)) {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_e2e_remove_folder_encrypted_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "lock"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- NCCommunication.shared.markE2EEFolder(fileId: metadata.fileId, delete: true) { (account, errorCode, errorDescription) in
- if errorCode == 0 {
- let serverUrl = self.serverUrl + "/" + metadata.fileName
- NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, "\(self.serverUrl ?? "")/\(metadata.fileName)"))
- NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: nil, ocId: nil, fileId: nil, encrypted: false, richWorkspace: nil, account: metadata.account)
- NCManageDatabase.sharedInstance.setMetadataEncrypted(ocId: metadata.ocId, encrypted: false)
-
- NotificationCenter.default.postOnMainThread(name: k_notificationCenter_reloadDataSource, userInfo: ["ocId":metadata.ocId, "serverUrl":metadata.serverUrl])
- } else {
- NCContentPresenter.shared.messageNotification(NSLocalizedString("_e2e_error_delete_mark_folder_", comment: ""), description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: .error, errorCode: errorCode)
- }
- }
- }
- )
- )
- }
-
- } else {
-
- var iconHeader: UIImage!
- if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
- iconHeader = icon
- } else {
- iconHeader = UIImage(named: metadata.iconName)
- }
- let isEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account, urlBase: metadata.urlBase)
- actions.append(
- NCMenuAction(
- title: metadata.fileNameView,
- icon: iconHeader,
- action: nil
- )
- )
- actions.append(
- NCMenuAction(
- title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
- action: { menuAction in
- NCNetworking.shared.favoriteMetadata(metadata, urlBase: appDelegate.urlBase) { (errorCode, errorDescription) in }
- }
- )
- )
- if (!isEncrypted) {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_details_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- NCMainCommon.shared.openShare(ViewController: self, metadata: metadata, indexPage: 0)
- }
- )
- )
- }
- if(!NCBrandOptions.sharedInstance.disable_openin_file) {
- actions.append(
- NCMenuAction(title: NSLocalizedString("_open_in_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- self.tableView.setEditing(false, animated: true)
- NCMainCommon.shared.downloadOpen(metadata: metadata, selector: selectorOpenIn)
- }
- )
- )
- }
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_rename_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "rename"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
- alertController.addTextField { (textField) in
- textField.text = metadata.fileNameView
- textField.delegate = self as? UITextFieldDelegate
- textField.addTarget(self, action: #selector(self.minCharTextFieldDidChange(_:)
- ), for: UIControl.Event.editingChanged)
- }
- 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: appDelegate.urlBase, viewController: self) { (errorCode, errorDescription) in }
- })
- okAction.isEnabled = false
- alertController.addAction(cancelAction)
- alertController.addAction(okAction)
- self.present(alertController, animated: true, completion: nil)
- }
- )
- )
-
- if (!isEncrypted) {
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_move_or_copy_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "move"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- self.moveOpenWindow([indexPath])
- }
- )
- )
- }
- if (!isEncrypted) {
- let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
- var title: String!
- if (localFile == nil || localFile!.offline == false) {
- title = NSLocalizedString("_set_available_offline_", comment: "")
- } else {
- title = NSLocalizedString("_remove_available_offline_", comment: "")
- }
- actions.append(
- NCMenuAction(
- title: title,
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "offline"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
- action: { menuAction in
- if (localFile == nil || !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView)) {
-
- NCNetworking.shared.download(metadata: metadata, selector: selectorLoadOffline) { (_) in }
-
- if let metadataLivePhoto = NCManageDatabase.sharedInstance.isLivePhoto(metadata: metadata) {
- NCNetworking.shared.download(metadata: metadataLivePhoto, selector: selectorLoadOffline) { (_) in }
- }
-
- } else {
- NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: !localFile!.offline)
- NotificationCenter.default.postOnMainThread(name: k_notificationCenter_reloadDataSource, userInfo: ["ocId":metadata.ocId, "serverUrl":metadata.serverUrl])
- }
- }
- )
- )
- }
- }
- actions.append(
- NCMenuAction(
- title: NSLocalizedString("_delete_", comment: ""),
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
- action: { menuAction in
- self.actionDelete(indexPath)
- }
- )
- )
- return actions
- }
- }
|