diff options
author | marinofaggiana <marino@marinofaggiana.com> | 2020-10-04 12:20:45 +0300 |
---|---|---|
committer | marinofaggiana <marino@marinofaggiana.com> | 2020-10-04 12:20:45 +0300 |
commit | c3b76f9b8e14e22efcfee1647bf286b99fd2880f (patch) | |
tree | 8345246501f05f1ddb92792ad082f0c02f3e0c04 /iOSClient | |
parent | e6028104013dacbe222e6e93cf52a047ae1d213c (diff) |
coding
Diffstat (limited to 'iOSClient')
-rw-r--r-- | iOSClient/Favorites/NCFavorite.swift | 2 | ||||
-rw-r--r-- | iOSClient/FileViewInFolder/NCFileViewInFolder.swift | 4 | ||||
-rw-r--r-- | iOSClient/Files/NCFiles.swift | 2 | ||||
-rw-r--r-- | iOSClient/Main/NCCollectionViewCommon.swift | 2 | ||||
-rw-r--r-- | iOSClient/Main/NCDataSource.swift | 21 | ||||
-rw-r--r-- | iOSClient/Offline/NCOffline.swift | 2 | ||||
-rw-r--r-- | iOSClient/Recent/NCRecent.swift | 2 | ||||
-rw-r--r-- | iOSClient/Select/NCSelect.swift | 10 | ||||
-rw-r--r-- | iOSClient/Transfers/NCTransfers.swift | 2 | ||||
-rw-r--r-- | iOSClient/Trash/NCTrash.swift | 10 |
10 files changed, 37 insertions, 20 deletions
diff --git a/iOSClient/Favorites/NCFavorite.swift b/iOSClient/Favorites/NCFavorite.swift index b18c223a2..b0d267096 100644 --- a/iOSClient/Favorites/NCFavorite.swift +++ b/iOSClient/Favorites/NCFavorite.swift @@ -54,7 +54,7 @@ class NCFavorite: NCCollectionViewCommon { } } - self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) + self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort:self.sort, ascending: self.ascending, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) DispatchQueue.main.async { self.refreshControl.endRefreshing() diff --git a/iOSClient/FileViewInFolder/NCFileViewInFolder.swift b/iOSClient/FileViewInFolder/NCFileViewInFolder.swift index 055ecec0c..c495459df 100644 --- a/iOSClient/FileViewInFolder/NCFileViewInFolder.swift +++ b/iOSClient/FileViewInFolder/NCFileViewInFolder.swift @@ -50,7 +50,7 @@ class NCFileViewInFolder: NCCollectionViewCommon { presentationController?.delegate = self appDelegate.activeViewController = self - (layout, _, _, groupBy, _, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl) + (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl) gridLayout.itemForLine = CGFloat(itemForLine) if layout == k_layout_list { @@ -85,7 +85,7 @@ class NCFileViewInFolder: NCCollectionViewCommon { } } - self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) + self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.sort, ascending: self.ascending, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) DispatchQueue.main.async { diff --git a/iOSClient/Files/NCFiles.swift b/iOSClient/Files/NCFiles.swift index ce4eef911..bc85d8fe1 100644 --- a/iOSClient/Files/NCFiles.swift +++ b/iOSClient/Files/NCFiles.swift @@ -75,7 +75,7 @@ class NCFiles: NCCollectionViewCommon { } } - self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) + self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.sort, ascending: self.ascending, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) DispatchQueue.main.async { self.refreshControl.endRefreshing() diff --git a/iOSClient/Main/NCCollectionViewCommon.swift b/iOSClient/Main/NCCollectionViewCommon.swift index 28bd1d80b..1586b3fc9 100644 --- a/iOSClient/Main/NCCollectionViewCommon.swift +++ b/iOSClient/Main/NCCollectionViewCommon.swift @@ -170,7 +170,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS self.navigationItem.title = titleCurrentFolder - (layout, _, _, groupBy, _, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl) + (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl) gridLayout.itemForLine = CGFloat(itemForLine) if layout == k_layout_list { diff --git a/iOSClient/Main/NCDataSource.swift b/iOSClient/Main/NCDataSource.swift index 788864f18..8e0824739 100644 --- a/iOSClient/Main/NCDataSource.swift +++ b/iOSClient/Main/NCDataSource.swift @@ -29,6 +29,8 @@ class NCDataSource: NSObject { public var metadataShare: [String:tableShare] = [:] public var metadataLocalImage: [String:String] = [:] + private var ascending: Bool = true + private var sort: String = "" private var directoryOnTop: Bool = true private var favoriteOnTop: Bool = true private var filterLivePhoto: Bool = true @@ -37,9 +39,11 @@ class NCDataSource: NSObject { super.init() } - init(metadatasSource: [tableMetadata], directoryOnTop: Bool, favoriteOnTop: Bool, filterLivePhoto: Bool) { + init(metadatasSource: [tableMetadata], sort: String, ascending: Bool, directoryOnTop: Bool, favoriteOnTop: Bool, filterLivePhoto: Bool) { super.init() + self.sort = sort + self.ascending = ascending self.directoryOnTop = directoryOnTop self.favoriteOnTop = favoriteOnTop self.filterLivePhoto = filterLivePhoto @@ -51,12 +55,25 @@ class NCDataSource: NSObject { private func createMetadatas(metadatasSource: [tableMetadata]) { + var metadatasSourceSorted: [tableMetadata] = [] var metadataFavoriteDirectory: [tableMetadata] = [] var metadataFavoriteFile: [tableMetadata] = [] var metadataDirectory: [tableMetadata] = [] var metadataFile: [tableMetadata] = [] - for metadata in metadatasSource { + if sort == "fileName" || sort == "fileNameView" { + metadatasSourceSorted = metadatasSource.sorted { (metadata1:tableMetadata, metadata2:tableMetadata) -> Bool in + if ascending { + return metadata1.fileNameView.localizedStandardCompare(metadata2.fileNameView) == ComparisonResult.orderedAscending + } else { + return metadata1.fileNameView.localizedStandardCompare(metadata2.fileNameView) == ComparisonResult.orderedDescending + } + } + } else { + metadatasSourceSorted = metadatasSource + } + + for metadata in metadatasSourceSorted { // skipped the root file if metadata.fileName == "." || metadata.serverUrl == ".." { diff --git a/iOSClient/Offline/NCOffline.swift b/iOSClient/Offline/NCOffline.swift index 82e04c3fe..48af01939 100644 --- a/iOSClient/Offline/NCOffline.swift +++ b/iOSClient/Offline/NCOffline.swift @@ -70,7 +70,7 @@ class NCOffline: NCCollectionViewCommon { } } - self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) + self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.sort, ascending: self.ascending, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) DispatchQueue.main.async { self.refreshControl.endRefreshing() diff --git a/iOSClient/Recent/NCRecent.swift b/iOSClient/Recent/NCRecent.swift index 77a6d5bb5..f0abace7f 100644 --- a/iOSClient/Recent/NCRecent.swift +++ b/iOSClient/Recent/NCRecent.swift @@ -52,7 +52,7 @@ class NCRecent: NCCollectionViewCommon { DispatchQueue.global().async { self.metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@", self.appDelegate.account), page: 1, limit: 100, sorted: "date", ascending: false) - self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, directoryOnTop: false, favoriteOnTop: false, filterLivePhoto: true) + self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort: self.sort, ascending: self.ascending, directoryOnTop: false, favoriteOnTop: false, filterLivePhoto: true) DispatchQueue.main.async { self.refreshControl.endRefreshing() diff --git a/iOSClient/Select/NCSelect.swift b/iOSClient/Select/NCSelect.swift index 61ed70e42..a0a5a9938 100644 --- a/iOSClient/Select/NCSelect.swift +++ b/iOSClient/Select/NCSelect.swift @@ -77,6 +77,9 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, NCListCellDelegat private var dataSource = NCDataSource() internal var richWorkspaceText: String? + private var sort: String = "" + private var ascending: Bool = true + private var directoryOnTop: Bool = true private var layout = "" private var groupBy = "" private var titleButton = "" @@ -182,7 +185,7 @@ class NCSelect: UIViewController, UIGestureRecognizerDelegate, NCListCellDelegat autoUploadFileName = NCManageDatabase.sharedInstance.getAccountAutoUploadFileName() autoUploadDirectory = NCManageDatabase.sharedInstance.getAccountAutoUploadDirectory(urlBase: appDelegate.urlBase, account: appDelegate.account) - (layout, _, _, groupBy, _, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: keyLayout,serverUrl: serverUrl) + (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: keyLayout,serverUrl: serverUrl) gridLayout.itemForLine = CGFloat(itemForLine) if layout == k_layout_list { @@ -723,9 +726,6 @@ extension NCSelect { @objc func loadDatasource(withLoadFolder: Bool) { var predicate: NSPredicate? - var sort: String - var ascending: Bool - var directoryOnTop: Bool (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: keyLayout, serverUrl: serverUrl) @@ -747,7 +747,7 @@ extension NCSelect { } let metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: predicate!, page: 0, limit: 0, sorted: sort, ascending: ascending) - self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, directoryOnTop: directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) + self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) if withLoadFolder { loadFolder() diff --git a/iOSClient/Transfers/NCTransfers.swift b/iOSClient/Transfers/NCTransfers.swift index d47f9c0b8..6361dd930 100644 --- a/iOSClient/Transfers/NCTransfers.swift +++ b/iOSClient/Transfers/NCTransfers.swift @@ -205,7 +205,7 @@ class NCTransfers: NCCollectionViewCommon { super.reloadDataSource() 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, directoryOnTop: false, favoriteOnTop: false, filterLivePhoto: false) + self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: false, favoriteOnTop: false, filterLivePhoto: false) refreshControl.endRefreshing() collectionView.reloadData() diff --git a/iOSClient/Trash/NCTrash.swift b/iOSClient/Trash/NCTrash.swift index 0f67566b7..08cb40e80 100644 --- a/iOSClient/Trash/NCTrash.swift +++ b/iOSClient/Trash/NCTrash.swift @@ -39,6 +39,9 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel private var datasource: [tableTrash] = [] + private var sort: String = "" + private var ascending: Bool = true + private var directoryOnTop: Bool = true private var layout = "" private var groupBy = "none" private var titleButton = "" @@ -95,7 +98,7 @@ class NCTrash: UIViewController, UIGestureRecognizerDelegate, NCTrashListCellDel self.navigationItem.title = titleCurrentFolder - (layout, _, _, groupBy, _, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: k_layout_view_trash, serverUrl: "") + (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: k_layout_view_trash, serverUrl: "") gridLayout.itemForLine = CGFloat(itemForLine) if layout == k_layout_list { @@ -567,10 +570,7 @@ extension NCTrash { @objc func reloadDataSource() { - var sort: String - var ascending: Bool - - (layout, sort, ascending, groupBy, _, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: k_layout_view_trash, serverUrl: "") + (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: k_layout_view_trash, serverUrl: "") datasource.removeAll() |