marinofaggiana 4 years ago
parent
commit
a7fa7597ae

+ 1 - 1
iOSClient/Favorites/NCFavorite.swift

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

+ 1 - 1
iOSClient/Files/NCFiles.swift

@@ -74,7 +74,7 @@ class NCFiles: NCCollectionViewCommon  {
             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)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, sorting: true, directoryOnTop: directoryOnTop, filterLivePhoto: true)
         
         refreshControl.endRefreshing()
         collectionView.reloadData()

+ 32 - 25
iOSClient/Main/NCDataSource.swift

@@ -30,6 +30,7 @@ class NCDataSource: NSObject {
     
     private var sort: String = ""
     private var ascending: Bool = true
+    private var sorting: Bool = true
     private var directoryOnTop: Bool = true
     private var filterLivePhoto: Bool = true
     
@@ -37,11 +38,12 @@ class NCDataSource: NSObject {
         super.init()
     }
     
-    init(metadatasSource: [tableMetadata], sort: String, ascending: Bool, directoryOnTop: Bool, filterLivePhoto: Bool) {
+    init(metadatasSource: [tableMetadata], sort: String, ascending: Bool, sorting: Bool, directoryOnTop: Bool, filterLivePhoto: Bool) {
         super.init()
         
         self.sort = sort
         self.ascending = ascending
+        self.sorting = sorting
         self.directoryOnTop = directoryOnTop
         self.filterLivePhoto = filterLivePhoto
         
@@ -52,6 +54,7 @@ class NCDataSource: NSObject {
     
     private func createMetadatas(metadatasSource: [tableMetadata]) {
         
+        var metadatasSourceSorted: [tableMetadata] = []
         var metadatasFavorite: [tableMetadata] = []
         var metadatasTemp: [tableMetadata] = []
         var numDirectory: Int = 0
@@ -61,33 +64,37 @@ class NCDataSource: NSObject {
         Metadata order
         */
         
-        let 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
+        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 {
-                    return obj1.fileNameView.compare(obj2.fileNameView, options: .caseInsensitive, range: range, locale: .current) == ComparisonResult.orderedDescending
+                    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
         }
         
         /*

+ 1 - 1
iOSClient/Offline/NCOffline.swift

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

+ 2 - 2
iOSClient/Recent/NCRecent.swift

@@ -51,8 +51,8 @@ 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: true)
-        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: "date", ascending: false, directoryOnTop: false, filterLivePhoto: true)
+        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)
         
         refreshControl.endRefreshing()
         collectionView.reloadData()

+ 1 - 1
iOSClient/Select/NCSelect.swift

@@ -530,7 +530,7 @@ extension NCSelect {
         }
         
         let metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: predicate!)
-        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, filterLivePhoto: true)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, sorting: true, 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, directoryOnTop: false, filterLivePhoto: false)
+        self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: "sessionTaskIdentifier", ascending: true, sorting: false, directoryOnTop: false, filterLivePhoto: false)
         
         refreshControl.endRefreshing()
         collectionView.reloadData()