marinofaggiana 4 years ago
parent
commit
dec73fe6ee

+ 1 - 1
iOSClient/Favorites/NCFavorite.swift

@@ -65,7 +65,7 @@ class NCFavorite: NCCollectionViewCommon  {
             }
         }
         
-        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, sorting: false, directoryOnTop: directoryOnTop, filterLivePhoto: true)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, directoryOnTop: directoryOnTop, filterLivePhoto: true)
         
         refreshControl.endRefreshing()
         collectionView.reloadData()

+ 2 - 2
iOSClient/Files/NCFiles.swift

@@ -76,10 +76,10 @@ class NCFiles: NCCollectionViewCommon  {
         (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
         
         if !isSearching {
-            metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl))
+            metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl), page: 0, limit: 0, sorted: sort, ascending: ascending)
         }
         
-        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, sorting: true, directoryOnTop: directoryOnTop, filterLivePhoto: true)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, directoryOnTop: directoryOnTop, filterLivePhoto: true)
         
         refreshControl.endRefreshing()
         collectionView.reloadData()

+ 2 - 46
iOSClient/Main/NCDataSource.swift

@@ -28,9 +28,6 @@ class NCDataSource: NSObject {
     public var metadatas: [tableMetadata] = []
     public var metadataLocalImage: [String:String] = [:]
     
-    private var sort: String = ""
-    private var ascending: Bool = true
-    private var sorting: Bool = true
     private var directoryOnTop: Bool = true
     private var filterLivePhoto: Bool = true
     
@@ -38,12 +35,9 @@ class NCDataSource: NSObject {
         super.init()
     }
     
-    init(metadatasSource: [tableMetadata], sort: String, ascending: Bool, sorting: Bool, directoryOnTop: Bool, filterLivePhoto: Bool) {
+    init(metadatasSource: [tableMetadata], directoryOnTop: Bool, filterLivePhoto: Bool) {
         super.init()
         
-        self.sort = sort
-        self.ascending = ascending
-        self.sorting = sorting
         self.directoryOnTop = directoryOnTop
         self.filterLivePhoto = filterLivePhoto
         
@@ -54,54 +48,16 @@ class NCDataSource: NSObject {
     
     private func createMetadatas(metadatasSource: [tableMetadata]) {
         
-        var metadatasSourceSorted: [tableMetadata] = []
         var metadatasFavorite: [tableMetadata] = []
         var metadatasTemp: [tableMetadata] = []
         var numDirectory: Int = 0
         var numDirectoryFavorite:Int = 0
 
-        /*
-        Metadata order
-        */
-        
-        if sorting {
-            metadatasSourceSorted = metadatasSource.sorted { (obj1:tableMetadata, obj2:tableMetadata) -> Bool in
-                if sort == "date" {
-                    if ascending {
-                        return obj1.date.compare(obj2.date as Date) == ComparisonResult.orderedAscending
-                    } else {
-                        return obj1.date.compare(obj2.date as Date) == ComparisonResult.orderedDescending
-                    }
-                } else if sort == "sessionTaskIdentifier" {
-                    if ascending {
-                        return obj1.sessionTaskIdentifier > obj2.sessionTaskIdentifier
-                    } else {
-                        return obj1.sessionTaskIdentifier < obj2.sessionTaskIdentifier
-                    }
-                } else if sort == "size" {
-                    if ascending {
-                        return obj1.size > obj2.size
-                    } else {
-                        return obj1.size < obj2.size
-                    }
-                } else {
-                    let range = Range(NSMakeRange(0, obj1.fileNameView.count), in: obj1.fileNameView)
-                    if ascending {
-                        return obj1.fileNameView.compare(obj2.fileNameView, options: .caseInsensitive, range: range, locale: .current) == ComparisonResult.orderedAscending
-                    } else {
-                        return obj1.fileNameView.compare(obj2.fileNameView, options: .caseInsensitive, range: range, locale: .current) == ComparisonResult.orderedDescending
-                    }
-                }
-            }
-        } else {
-            metadatasSourceSorted = metadatasSource
-        }
-        
         /*
         Initialize datasource
         */
         
-        for metadata in metadatasSourceSorted {
+        for metadata in metadatasSource {
             
             // skipped livePhoto
             if metadata.ext == "mov" && metadata.livePhoto && filterLivePhoto {

+ 3 - 3
iOSClient/Offline/NCOffline.swift

@@ -72,15 +72,15 @@ class NCOffline: NCCollectionViewCommon  {
                     ocIds.append(file.ocId)
                 }
                
-                metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND ocId IN %@", appDelegate.account, ocIds))
+                metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND ocId IN %@", appDelegate.account, ocIds), page: 0, limit: 0, sorted: sort, ascending: ascending)
                 
             } else {
                
-                metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl))
+                metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl), page: 0, limit: 0, sorted: sort, ascending: ascending)
             }
         }
         
-        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, sorting: true, directoryOnTop: directoryOnTop, filterLivePhoto: true)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, directoryOnTop: directoryOnTop, filterLivePhoto: true)
         
         refreshControl.endRefreshing()
         collectionView.reloadData()

+ 1 - 1
iOSClient/Recent/NCRecent.swift

@@ -52,7 +52,7 @@ class NCRecent: NCCollectionViewCommon  {
         (layout, _, _, groupBy, _, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: "")
 
         metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@", appDelegate.account), page: 1, limit: 100, sorted: "date", ascending: false)
-        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: "", ascending: false, sorting: false, directoryOnTop: false, filterLivePhoto: true)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, directoryOnTop: false, filterLivePhoto: true)
         
         refreshControl.endRefreshing()
         collectionView.reloadData()

+ 2 - 2
iOSClient/Select/NCSelect.swift

@@ -529,8 +529,8 @@ extension NCSelect {
             }
         }
         
-        let metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: predicate!)
-        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, sorting: true, directoryOnTop: directoryOnTop, filterLivePhoto: true)
+        let metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: predicate!, page: 0, limit: 0, sorted: sort, ascending: ascending)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, directoryOnTop: directoryOnTop, filterLivePhoto: true)
         
         if withLoadFolder {
             loadFolder()

+ 1 - 1
iOSClient/Transfers/NCTransfers.swift

@@ -207,7 +207,7 @@ class NCTransfers: NCCollectionViewCommon  {
         (layout, _, _, groupBy, _, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: "")
         
         metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "(session CONTAINS 'upload') OR (session CONTAINS 'download')"), page: 1, limit: 100, sorted: "sessionTaskIdentifier", ascending: false)
-        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: "sessionTaskIdentifier", ascending: true, sorting: false, directoryOnTop: false, filterLivePhoto: false)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, directoryOnTop: false, filterLivePhoto: false)
         
         refreshControl.endRefreshing()
         collectionView.reloadData()