Browse Source

Removed the option "Favorite available offline", use the option "Set available offline"

marinofaggiana 4 years ago
parent
commit
10035f2227

+ 10 - 0
iOSClient/Data/NCManageDatabase.swift

@@ -2367,6 +2367,16 @@ class NCManageDatabase: NSObject {
         }
     }
     
+    func isDownloadMetadata(_ metadata: tableMetadata, download: Bool) -> Bool {
+        
+        let localFile = getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+        let fileSize = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
+        if (localFile != nil || download) && (localFile?.etag != metadata.etag || fileSize == 0) {
+            return true
+        }
+        return false
+    }
+    
     //MARK: -
     //MARK: Table Photo Library
     

+ 1 - 3
iOSClient/Favorites/NCFavorite.swift

@@ -92,9 +92,7 @@ class NCFavorite: NCCollectionViewCommon  {
                 if errorCode == 0 {
                     for metadata in metadatas ?? [] {
                         if !metadata.directory {
-                            let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                            let fileSize = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
-                            if localFile != nil && (localFile?.etag != metadata.etag || fileSize == 0) {
+                            if NCManageDatabase.shared.isDownloadMetadata(metadata, download: false) {
                                 NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorDownloadFile, setFavorite: false)
                             }
                         }

+ 1 - 3
iOSClient/FileViewInFolder/NCFileViewInFolder.swift

@@ -132,9 +132,7 @@ class NCFileViewInFolder: NCCollectionViewCommon  {
             if errorCode == 0 {
                 for metadata in metadatas ?? [] {
                     if !metadata.directory {
-                        let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                        let fileSize = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
-                        if localFile != nil && (localFile?.etag != metadata.etag || fileSize == 0) {
+                        if NCManageDatabase.shared.isDownloadMetadata(metadata, download: false) {
                             NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorDownloadFile, setFavorite: false)
                         }
                     }

+ 1 - 3
iOSClient/Files/NCFiles.swift

@@ -99,9 +99,7 @@ class NCFiles: NCCollectionViewCommon  {
             if errorCode == 0 {
                 for metadata in metadatas ?? [] {
                     if !metadata.directory {
-                        let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                        let fileSize = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
-                        if localFile != nil && (localFile?.etag != metadata.etag || fileSize == 0) {
+                        if NCManageDatabase.shared.isDownloadMetadata(metadata, download: false) {
                             NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorDownloadFile, setFavorite: false)
                         }
                     }

+ 4 - 12
iOSClient/Networking/NCOperationQueue.swift

@@ -284,9 +284,7 @@ class NCOperationSynchronization: ConcurrentOperation {
                                             if metadata.directory {
                                                 NCOperationQueue.shared.synchronizationMetadata(metadata, selector: self.selector)
                                             } else {
-                                                let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                                                let fileSize = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
-                                                if localFile == nil || localFile?.etag != metadata.etag || fileSize == 0 {
+                                                if NCManageDatabase.shared.isDownloadMetadata(metadata, download: true) {
                                                     NCOperationQueue.shared.download(metadata: metadata, selector: self.selector, setFavorite: false)
                                                 }
                                             }
@@ -325,9 +323,7 @@ class NCOperationSynchronization: ConcurrentOperation {
                             if metadata.directory {
                                 NCOperationQueue.shared.synchronizationMetadata(metadata, selector: self.selector)
                             } else {
-                                let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                                let fileSize = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
-                                if localFile == nil && (localFile?.etag != metadata.etag || fileSize == 0) {
+                                if NCManageDatabase.shared.isDownloadMetadata(metadata, download: self.download) {
                                     NCOperationQueue.shared.download(metadata: metadata, selector: self.selector, setFavorite: false)
                                 }
                             }
@@ -338,12 +334,8 @@ class NCOperationSynchronization: ConcurrentOperation {
                 }
                 
             } else {
-                if self.download {
-                    let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                    let fileSize = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
-                    if localFile == nil || localFile?.etag != metadata.etag || fileSize == 0 {
-                        NCOperationQueue.shared.download(metadata: metadata, selector: self.selector, setFavorite: false)
-                    }
+                if NCManageDatabase.shared.isDownloadMetadata(metadata, download: self.download) {
+                    NCOperationQueue.shared.download(metadata: metadata, selector: self.selector, setFavorite: false)
                 }
                 self.finish()
             }

+ 1 - 3
iOSClient/Offline/NCOffline.swift

@@ -100,9 +100,7 @@ class NCOffline: NCCollectionViewCommon  {
                 if errorCode == 0 {
                     for metadata in metadatas ?? [] {
                         if !metadata.directory {
-                            let localFile = NCManageDatabase.shared.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                            let fileSize = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
-                            if localFile == nil || localFile?.etag != metadata.etag || fileSize == 0 {
+                            if NCManageDatabase.shared.isDownloadMetadata(metadata, download: true) {
                                 NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorDownloadFile, setFavorite: false)
                             }
                         }