浏览代码

Add warning when setting multiple files avaliable offline

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 年之前
父节点
当前提交
95c17f8c55

+ 22 - 22
iOSClient/Main/NCFunctionCenter.swift

@@ -29,10 +29,8 @@ import JGProgressHUD
 @objc class NCFunctionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelectDelegate {
     @objc public static let shared: NCFunctionCenter = {
         let instance = NCFunctionCenter()
-
         NotificationCenter.default.addObserver(instance, selector: #selector(downloadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
         NotificationCenter.default.addObserver(instance, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
-
         return instance
     }()
 
@@ -168,6 +166,25 @@ import JGProgressHUD
         }
     }
 
+    func setMetadataAvalableOffline(_ metadata: tableMetadata, isOffline: Bool) {
+        let serverUrl = metadata.serverUrl + "/" + metadata.fileName
+        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 }
+            }
+        }
+    }
+
     // MARK: - Upload
 
     @objc func uploadedFile(_ notification: NSNotification) {
@@ -673,26 +690,9 @@ import JGProgressHUD
         }
 
         let offline = UIAction(title: titleOffline, image: UIImage(systemName: "tray.and.arrow.down")) { _ 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()
+            self.setMetadataAvalableOffline(metadata, isOffline: isOffline)
+            if let viewController = viewController as? NCCollectionViewCommon {
+                viewController.reloadDataSource()
             }
         }
 

+ 17 - 21
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -32,24 +32,11 @@ import Queuer
 
 extension NCCollectionViewCommon {
 
-    fileprivate func setAvailableOffline(metadata: tableMetadata, isOffline: Bool) {
-        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 }
-                }
-            }
+    fileprivate func setMetadatasAvalableOffline(_ metadatas: [tableMetadata], isOffline: Bool) {
+        metadatas.forEach { metadata in
+            NCFunctionCenter.shared.setMetadataAvalableOffline(metadata, isOffline: isOffline)
         }
+        self.tapSelect(sender: self)
         self.reloadDataSource()
     }
 
@@ -154,7 +141,7 @@ extension NCCollectionViewCommon {
                     title: isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") :  NSLocalizedString("_set_available_offline_", comment: ""),
                     icon: NCUtility.shared.loadImage(named: "tray.and.arrow.down"),
                     action: { _ in
-                        self.setAvailableOffline(metadata: metadata, isOffline: isOffline)
+                        self.setMetadatasAvalableOffline([metadata], isOffline: isOffline)
                     }
                 )
             )
@@ -485,10 +472,19 @@ extension NCCollectionViewCommon {
                 title: isAnyOffline ? NSLocalizedString("_remove_available_offline_", comment: "") :  NSLocalizedString("_set_available_offline_", comment: ""),
                 icon: NCUtility.shared.loadImage(named: "tray.and.arrow.down"),
                 action: { _ in
-                    selectedMetadatas.forEach { metadata in
-                        self.setAvailableOffline(metadata: metadata, isOffline: isAnyOffline)
+                    if !isAnyOffline, selectedMetadatas.count > 3 {
+                        let alert = UIAlertController(
+                            title: NSLocalizedString("_set_available_offline_", comment: ""),
+                            message: NSLocalizedString("_select_offline_warning_", comment: ""),
+                            preferredStyle: .alert)
+                        alert.addAction(UIAlertAction(title: NSLocalizedString("_continue_", comment: ""), style: .default, handler: { _ in
+                            self.setMetadatasAvalableOffline(selectedMetadatas, isOffline: isAnyOffline)
+                        }))
+                        alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel))
+                        self.present(alert, animated: true)
+                    } else {
+                        self.setMetadatasAvalableOffline(selectedMetadatas, isOffline: isAnyOffline)
                     }
-                    self.tapSelect(sender: self)
                 }
             )
         )

+ 1 - 2
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -333,8 +333,7 @@
 "_user_employee_"               = "Employee";
 "_user_contractor_"             = "Contractor";
 "_user_editprofile_"            = "Edit profile";
-"_favorite_offline_"            = "Favorites available offline";
-"_favorite_offline_footer_"     = "Making all favorites available offline may take a while and use a lot of memory while doing it.";
+"_select_offline_warning_"      = "Making multiple files and folders available offline may take a while and use a lot of memory while doing so.";
 "_advanced_"                    = "Advanced";
 "_disable_files_app_"           = "Disable Files App integration";
 "_disable_files_app_footer_"    = "Do not permit the access of files via the iOS Files application";