Przeglądaj źródła

improvements on context menu

marinofaggiana 3 lat temu
rodzic
commit
707303a3f9
1 zmienionych plików z 39 dodań i 6 usunięć
  1. 39 6
      iOSClient/Main/NCFunctionCenter.swift

+ 39 - 6
iOSClient/Main/NCFunctionCenter.swift

@@ -529,17 +529,50 @@ import NCCommunication
         }
         let titleFavorite = metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: "")
         
-        let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc") ) { action in
+        let serverUrl = metadata.serverUrl + "/" + metadata.fileName
+        var isOffline = false
+        if metadata.directory {
+            if 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 titleOffline = isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") :  NSLocalizedString("_set_available_offline_", comment: "")
+        
+        let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc")) { action in
             self.appDelegate.pasteboardOcIds = [metadata.ocId]
             self.copyPasteboard()
         }
         
-        let detail = UIAction(title: NSLocalizedString("_details_", comment: ""), image: UIImage(systemName: "info") ) { action in
+        let detail = UIAction(title: NSLocalizedString("_details_", comment: ""), image: UIImage(systemName: "info")) { action in
             self.openShare(ViewController: viewController, metadata: metadata, indexPage: 0)
         }
         
-        let offline = UIAction(title: NSLocalizedString("_details_", comment: ""), image: UIImage(systemName: "info") ) { action in
-            self.openShare(ViewController: viewController, metadata: metadata, indexPage: 0)
+        let offline = UIAction(title: titleOffline, image: NCUtility.shared.loadImage(named: "tray.and.arrow.down")) { action in
+            if isOffline {
+                if metadata.directory {
+                    NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, offline: false, account: self.appDelegate.account)
+                } else {
+                    NCManageDatabase.shared.setLocalFile(ocId: metadata.ocId, offline: false)
+                }
+            } else {
+                if metadata.directory {
+                    NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, offline: true, account: self.appDelegate.account)
+                    NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCGlobal.shared.selectorDownloadAllFile)
+                } else {
+                    NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadOffline) { (_) in }
+                    if let metadataLivePhoto = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
+                        NCNetworking.shared.download(metadata: metadataLivePhoto, selector: NCGlobal.shared.selectorLoadOffline) { (_) in }
+                    }
+                }
+            }
+            
+            if viewController is NCCollectionViewCommon {
+                (viewController as! NCCollectionViewCommon).reloadDataSource()
+            }
         }
         
         let save = UIAction(title: titleSave, image: UIImage(systemName: "square.and.arrow.down")) { action in
@@ -635,13 +668,13 @@ import NCCommunication
         
         if metadata.directory {
             
-            let submenu = UIMenu(title: "", options: .displayInline, children: [favorite, rename, moveCopy, delete])
+            let submenu = UIMenu(title: "", options: .displayInline, children: [favorite, offline, rename, moveCopy, delete])
             return UIMenu(title: "", children: [detail, submenu])
         }
         
         // FILE
         
-        var children: [UIMenuElement] = [favorite, open, rename, moveCopy, copy, delete]
+        var children: [UIMenuElement] = [favorite, offline, open, rename, moveCopy, copy, delete]
 
         if metadata.typeFile == NCGlobal.shared.metadataTypeFileImage || metadata.typeFile == NCGlobal.shared.metadataTypeFileVideo {
             children.insert(save, at: 2)