marinofaggiana пре 4 година
родитељ
комит
b2ab422cf7

+ 7 - 23
iOSClient/Favorites/NCFavorite.swift

@@ -103,28 +103,15 @@ class NCFavorite: NCCollectionViewCommon  {
     override func reloadDataSourceNetwork() {
        
         if isSearching {
+            networkSearch()
+            return
+        }
         
-            if literalSearch == nil || literalSearch?.count ?? 0 < 2 {
-                self.reloadDataSource()
-                return
-            }
-            
-            isReloadDataSourceNetworkInProgress = true
-            collectionView?.reloadData()
-            
-            NCNetworking.shared.searchFiles(urlBase: appDelegate.urlBase, user: appDelegate.user, literal: literalSearch!) { (account, metadatas, errorCode, errorDescription) in
-                if self.searchController?.isActive ?? false && errorCode == 0 {
-                    self.metadatasSource = metadatas!
-                }
-                self.isReloadDataSourceNetworkInProgress = false
-                self.reloadDataSource()
-            }
-            
-        } else if serverUrl == "" {
+        isReloadDataSourceNetworkInProgress = true
+        collectionView?.reloadData()
+        
+        if serverUrl == "" {
             
-            isReloadDataSourceNetworkInProgress = true
-            collectionView?.reloadData()
-
             NCNetworking.shared.listingFavoritescompletion(selector: selectorListingFavorite) { (account, metadatas, errorCode, errorDescription) in
                 if errorCode == 0 {
                     for metadata in metadatas ?? [] {
@@ -144,9 +131,6 @@ class NCFavorite: NCCollectionViewCommon  {
             
         } else {
             
-            isReloadDataSourceNetworkInProgress = true
-            collectionView?.reloadData()
-
             NCNetworking.shared.readFolder(serverUrl: serverUrl, account: appDelegate.account) { (account, metadataFolder, metadatas, metadatasUpdate, metadatasLocalUpdate, errorCode, errorDescription) in
                 if errorCode == 0 {
                     for metadata in metadatas ?? [] {

+ 15 - 0
iOSClient/Main/NCCollectionCommon.swift

@@ -1086,6 +1086,21 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     
     @objc func reloadDataSource() { }
     @objc func reloadDataSourceNetwork() { }
+    @objc func networkSearch() {
+        if literalSearch?.count ?? 0 > 1 {
+        
+            isReloadDataSourceNetworkInProgress = true
+            collectionView?.reloadData()
+            
+            NCNetworking.shared.searchFiles(urlBase: appDelegate.urlBase, user: appDelegate.user, literal: literalSearch!) { (account, metadatas, errorCode, errorDescription) in
+                if self.searchController?.isActive ?? false && errorCode == 0 {
+                    self.metadatasSource = metadatas!
+                }
+                self.isReloadDataSourceNetworkInProgress = false
+                self.reloadDataSource()
+            }
+        }
+    }
 }
 
 // MARK: - 3D Touch peek and pop

+ 60 - 74
iOSClient/Offline/NCOffline.swift

@@ -22,6 +22,7 @@
 //
 
 import Foundation
+import NCCommunication
 
 class NCOffline: NCCollectionViewCommon  {
     
@@ -31,37 +32,10 @@ class NCOffline: NCCollectionViewCommon  {
         appDelegate.activeOffline = self
         titleCurrentFolder = NSLocalizedString("_manage_file_offline_", comment: "")
         layoutKey = k_layout_view_offline
-    }
-    
-    // MARK: DZNEmpty
-    
-    override func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
-        return CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 300, height: 300, color: NCBrandColor.sharedInstance.brandElement)
-    }
-    
-    override func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
-        let text = "\n"+NSLocalizedString("_files_no_files_", comment: "")
-        let attributes = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 20), NSAttributedString.Key.foregroundColor: UIColor.lightGray]
-        return NSAttributedString.init(string: text, attributes: attributes)
-    }
-        
-    // MARK: SEGUE
-    
-    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
-        
-        let photoDataSource: NSMutableArray = []
-        
-        for metadata in (dataSource?.metadatas ?? [tableMetadata]()) {
-            if metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video {
-                photoDataSource.add(metadata)
-            }
-        }
-        
-        if let segueNavigationController = segue.destination as? UINavigationController {
-            if let segueViewController = segueNavigationController.topViewController as? NCDetailViewController {
-                segueViewController.metadata = metadataPush
-            }
-        }
+        enableSearchBar = true
+        DZNimage = "folder"
+        DZNtitle = "_files_no_files_"
+        DZNdescription = "_tutorial_offline_view_"
     }
     
     // MARK: - Collection View
@@ -109,56 +83,68 @@ class NCOffline: NCCollectionViewCommon  {
 
     override func reloadDataSource() {
            
-           var ocIds: [String] = []
-           var sort: String
-           var ascending: Bool
-           var directoryOnTop: Bool
+        var ocIds: [String] = []
+        var sort: String
+        var ascending: Bool
+        var directoryOnTop: Bool
            
-           (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: k_layout_view_offline)
+        (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: k_layout_view_offline)
 
-           if serverUrl == "" {
-               
-               if let directories = NCManageDatabase.sharedInstance.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", appDelegate.account), sorted: "serverUrl", ascending: true) {
-                   for directory: tableDirectory in directories {
-                       ocIds.append(directory.ocId)
-                   }
-               }
+        if !isSearching {
+            
+            if serverUrl == "" {
                
-               let files = NCManageDatabase.sharedInstance.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", appDelegate.account), sorted: "fileName", ascending: true)
-               for file: tableLocalFile in files {
-                   ocIds.append(file.ocId)
-               }
+                if let directories = NCManageDatabase.sharedInstance.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", appDelegate.account), sorted: "serverUrl", ascending: true) {
+                    for directory: tableDirectory in directories {
+                        ocIds.append(directory.ocId)
+                    }
+                }
                
-               let metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND ocId IN %@", appDelegate.account, ocIds))
-               self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, filterLivePhoto: true)
+                let files = NCManageDatabase.sharedInstance.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", appDelegate.account), sorted: "fileName", ascending: true)
+                for file: tableLocalFile in files {
+                    ocIds.append(file.ocId)
+                }
                
-           } else {
+                metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND ocId IN %@", appDelegate.account, ocIds))
+                
+            } else {
                
-               let metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl))
-               self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, filterLivePhoto: true)
-           }
-           
-           refreshControl.endRefreshing()
-           collectionView.reloadData()
-       }
+                metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl))
+            }
+        }
+        
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, filterLivePhoto: true)
+        
+        refreshControl.endRefreshing()
+        collectionView.reloadData()
+    }
        
-       override func reloadDataSourceNetwork() {
+    override func reloadDataSourceNetwork() {
            
-           if serverUrl != "" {
+        if isSearching {
+            networkSearch()
+            return
+        }
+                    
+        if serverUrl != "" {
            
-               NCNetworking.shared.readFolder(serverUrl: serverUrl, account: appDelegate.account) { (account, metadataFolder, metadatas, metadatasUpdate, metadatasLocalUpdate, errorCode, errorDescription) in
-                   if errorCode == 0 {
-                       for metadata in metadatas ?? [] {
-                           if !metadata.directory {
-                               let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                               if localFile == nil || localFile?.etag != metadata.etag {
-                                   NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false)
-                               }
-                           }
-                       }
-                   }
-                   self.reloadDataSource()
-               }
-           }
-       }
+            isReloadDataSourceNetworkInProgress = true
+            collectionView?.reloadData()
+            
+            NCNetworking.shared.readFolder(serverUrl: serverUrl, account: appDelegate.account) { (account, metadataFolder, metadatas, metadatasUpdate, metadatasLocalUpdate, errorCode, errorDescription) in
+                if errorCode == 0 {
+                    for metadata in metadatas ?? [] {
+                        if !metadata.directory {
+                            let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                            if localFile == nil || localFile?.etag != metadata.etag {
+                                NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false)
+                            }
+                        }
+                    }
+                }
+                self.isReloadDataSourceNetworkInProgress = false
+                self.reloadDataSource()
+            }
+        }
+    }
 }