|
@@ -22,9 +22,9 @@
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
//
|
|
|
|
|
|
-import Foundation
|
|
|
import NCCommunication
|
|
|
import Realm
|
|
|
+import UIKit
|
|
|
|
|
|
extension RealmSwiftObject {
|
|
|
var primaryKeyValue: String? {
|
|
@@ -45,6 +45,7 @@ protocol NCSelectableNavigationView: AnyObject {
|
|
|
func tapSelectMenu()
|
|
|
func tapSelect()
|
|
|
func setNavigationItem()
|
|
|
+ var selectActions: [NCMenuAction] { get }
|
|
|
}
|
|
|
|
|
|
extension NCSelectableNavigationView {
|
|
@@ -78,148 +79,36 @@ extension NCSelectableNavigationView {
|
|
|
|
|
|
extension NCSelectableNavigationView where Self: UIViewController {
|
|
|
func tapSelectMenu() {
|
|
|
+ presentMenu(with: selectActions)
|
|
|
+ }
|
|
|
|
|
|
+ var selectActions: [NCMenuAction] {
|
|
|
var actions = [NCMenuAction]()
|
|
|
-
|
|
|
- //
|
|
|
- // SELECT ALL
|
|
|
- //
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_select_all_", comment: ""),
|
|
|
- icon: NCUtility.shared.loadImage(named: "checkmark.circle.fill"),
|
|
|
- action: { _ in
|
|
|
- self.collectionViewSelectAll()
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
-
|
|
|
- if let trash = self as? NCTrash {
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_trash_restore_selected_", comment: ""),
|
|
|
- icon: NCUtility.shared.loadImage(named: "restore"),
|
|
|
- action: { _ in
|
|
|
- self.selectOcId.forEach(trash.restoreItem)
|
|
|
- self.tapSelect()
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_trash_delete_selected_", comment: ""),
|
|
|
- icon: NCUtility.shared.loadImage(named: "trash"),
|
|
|
- action: { _ in
|
|
|
- let alert = UIAlertController(title: NSLocalizedString("_trash_delete_selected_", comment: ""), message: "", preferredStyle: .alert)
|
|
|
- alert.addAction(UIAlertAction(title: NSLocalizedString("_delete_", comment: ""), style: .destructive, handler: { _ in
|
|
|
- self.selectOcId.forEach(trash.deleteItem)
|
|
|
- self.tapSelect()
|
|
|
- }))
|
|
|
- alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in }))
|
|
|
- self.present(alert, animated: true, completion: nil)
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
- return presentMenu(with: actions)
|
|
|
+ if selectOcId.count != selectableDataSource.count {
|
|
|
+ actions.append(.selectAllAction(action: collectionViewSelectAll))
|
|
|
}
|
|
|
|
|
|
- //
|
|
|
- // OPEN IN
|
|
|
- //
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_open_in_", comment: ""),
|
|
|
- icon: NCUtility.shared.loadImage(named: "square.and.arrow.up"),
|
|
|
- action: { _ in
|
|
|
- NCFunctionCenter.shared.openActivityViewController(selectOcId: self.selectOcId)
|
|
|
- self.tapSelect()
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
-
|
|
|
- //
|
|
|
- // SAVE TO PHOTO GALLERY
|
|
|
- //
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_save_selected_files_", comment: ""),
|
|
|
- icon: NCUtility.shared.loadImage(named: "square.and.arrow.down"),
|
|
|
- action: { _ in
|
|
|
- self.selectOcId
|
|
|
- .compactMap(NCManageDatabase.shared.getMetadataFromOcId)
|
|
|
- .filter({ $0.classFile == NCCommunicationCommon.typeClassFile.image.rawValue || $0.classFile == NCCommunicationCommon.typeClassFile.video.rawValue })
|
|
|
- .forEach { metadata in
|
|
|
- if let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
|
|
|
- NCFunctionCenter.shared.saveLivePhoto(metadata: metadata, metadataMOV: metadataMOV)
|
|
|
- } else {
|
|
|
- if CCUtility.fileProviderStorageExists(metadata) {
|
|
|
- NCFunctionCenter.shared.saveAlbum(metadata: metadata)
|
|
|
- } else {
|
|
|
- NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorSaveAlbum)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- self.tapSelect()
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
+ guard !selectOcId.isEmpty else { return actions }
|
|
|
+ var selectedMetadatas: [tableMetadata] = []
|
|
|
+ var selectedMediaMetadatas: [tableMetadata] = []
|
|
|
|
|
|
- //
|
|
|
- // COPY - MOVE
|
|
|
- //
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_move_or_copy_selected_files_", comment: ""),
|
|
|
- icon: NCUtility.shared.loadImage(named: "arrow.up.right.square"),
|
|
|
- action: { _ in
|
|
|
- let meradatasSelect = self.selectOcId.compactMap(NCManageDatabase.shared.getMetadataFromOcId)
|
|
|
- if !meradatasSelect.isEmpty {
|
|
|
- NCFunctionCenter.shared.openSelectView(items: meradatasSelect, viewController: self)
|
|
|
- }
|
|
|
- self.tapSelect()
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
-
|
|
|
- //
|
|
|
- // COPY
|
|
|
- //
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_copy_file_", comment: ""),
|
|
|
- icon: NCUtility.shared.loadImage(named: "doc.on.doc"),
|
|
|
- action: { _ in
|
|
|
- NCFunctionCenter.shared.copyPasteboard(pasteboardOcIds: self.selectOcId, hudView: self.view)
|
|
|
- self.tapSelect()
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
+ for ocId in selectOcId {
|
|
|
+ guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { continue }
|
|
|
+ selectedMetadatas.append(metadata)
|
|
|
+ if [NCCommunicationCommon.typeClassFile.image.rawValue, NCCommunicationCommon.typeClassFile.video.rawValue].contains(metadata.classFile) {
|
|
|
+ selectedMediaMetadatas.append(metadata)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //
|
|
|
- // DELETE
|
|
|
- //
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_delete_selected_files_", comment: ""),
|
|
|
- icon: NCUtility.shared.loadImage(named: "trash"),
|
|
|
- action: { _ in
|
|
|
- let meradatasSelect = self.selectOcId.compactMap(NCManageDatabase.shared.getMetadataFromOcId)
|
|
|
+ actions.append(.openInAction(selectedMetadatas: selectedMetadatas, viewController: self, completion: tapSelect))
|
|
|
|
|
|
- let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
|
|
|
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (_: UIAlertAction) in
|
|
|
- meradatasSelect.forEach({ NCOperationQueue.shared.delete(metadata: $0, onlyLocalCache: false) })
|
|
|
- self.tapSelect()
|
|
|
- })
|
|
|
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_remove_local_file_", comment: ""), style: .default) { (_: UIAlertAction) in
|
|
|
- meradatasSelect.forEach({ NCOperationQueue.shared.delete(metadata: $0, onlyLocalCache: true) })
|
|
|
- self.tapSelect()
|
|
|
- })
|
|
|
- alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (_: UIAlertAction) in })
|
|
|
- self.present(alertController, animated: true, completion: nil)
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
+ if !selectedMediaMetadatas.isEmpty {
|
|
|
+ actions.append(.saveMediaAction(selectedMediaMetadatas: selectedMediaMetadatas, completion: tapSelect))
|
|
|
+ }
|
|
|
|
|
|
- presentMenu(with: actions)
|
|
|
+ actions.append(.moveOrCopyAction(selectedMetadatas: selectedMetadatas, completion: tapSelect))
|
|
|
+ actions.append(.copyAction(selectOcId: selectOcId, hudView: self.view, completion: tapSelect))
|
|
|
+ actions.append(.deleteAction(selectedMetadatas: selectedMetadatas, viewController: self, completion: tapSelect))
|
|
|
+ return actions
|
|
|
}
|
|
|
}
|