diff options
author | marinofaggiana <marino@marinofaggiana.com> | 2020-10-03 09:28:59 +0300 |
---|---|---|
committer | marinofaggiana <marino@marinofaggiana.com> | 2020-10-03 09:28:59 +0300 |
commit | e24bac152eec0501b5bc2b9282de638309ddf39d (patch) | |
tree | 0c81feb90bdf98b2b900219e2319aa6314b9f5e3 /iOSClient | |
parent | 0e0d51379fc567173dbf22daea62177142b77b68 (diff) |
coding
Diffstat (limited to 'iOSClient')
-rw-r--r-- | iOSClient/Favorites/NCFavorite.swift | 33 | ||||
-rw-r--r-- | iOSClient/FileViewInFolder/NCFileViewInFolder.swift | 56 | ||||
-rw-r--r-- | iOSClient/Files/NCFiles.swift | 10 | ||||
-rw-r--r-- | iOSClient/Main/NCCollectionViewCommon.swift | 7 | ||||
-rw-r--r-- | iOSClient/Offline/NCOffline.swift | 60 | ||||
-rw-r--r-- | iOSClient/Recent/NCRecent.swift | 17 | ||||
-rw-r--r-- | iOSClient/Transfers/NCTransfers.swift | 4 |
7 files changed, 94 insertions, 93 deletions
diff --git a/iOSClient/Favorites/NCFavorite.swift b/iOSClient/Favorites/NCFavorite.swift index d56d483f2..b18c223a2 100644 --- a/iOSClient/Favorites/NCFavorite.swift +++ b/iOSClient/Favorites/NCFavorite.swift @@ -43,25 +43,24 @@ class NCFavorite: NCCollectionViewCommon { override func reloadDataSource() { super.reloadDataSource() - var sort: String - var ascending: Bool - var directoryOnTop: Bool - - (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl) - - if !isSearching { - - if serverUrl == "" { - metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND favorite == true", appDelegate.account), page: 0, limit: 0, sorted: sort, ascending: ascending) - } else { - metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl), page: 0, limit: 0, sorted: sort, ascending: ascending) + DispatchQueue.global().async { + + if !self.isSearching { + + if self.serverUrl == "" { + self.metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND favorite == true", self.appDelegate.account), page: 0, limit: 0, sorted: self.sort, ascending: self.ascending) + } else { + self.metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl), page: 0, limit: 0, sorted: self.sort, ascending: self.ascending) + } + } + + self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) + + DispatchQueue.main.async { + self.refreshControl.endRefreshing() + self.collectionView.reloadData() } } - - self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, directoryOnTop: directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) - - refreshControl.endRefreshing() - collectionView.reloadData() } override func reloadDataSourceNetwork(forced: Bool = false) { diff --git a/iOSClient/FileViewInFolder/NCFileViewInFolder.swift b/iOSClient/FileViewInFolder/NCFileViewInFolder.swift index c3aebaab6..055ecec0c 100644 --- a/iOSClient/FileViewInFolder/NCFileViewInFolder.swift +++ b/iOSClient/FileViewInFolder/NCFileViewInFolder.swift @@ -76,35 +76,35 @@ class NCFileViewInFolder: NCCollectionViewCommon { override func reloadDataSource() { super.reloadDataSource() - var sort: String - var ascending: Bool - var directoryOnTop: Bool - - (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), page: 0, limit: 0, sorted: sort, ascending: ascending) - if metadataFolder == nil { - metadataFolder = NCManageDatabase.sharedInstance.getMetadataFolder(account: appDelegate.account, urlBase: appDelegate.urlBase, serverUrl: serverUrl) + DispatchQueue.global().async { + + if !self.isSearching { + self.metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl), page: 0, limit: 0, sorted: self.sort, ascending: self.ascending) + if self.metadataFolder == nil { + self.metadataFolder = NCManageDatabase.sharedInstance.getMetadataFolder(account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, serverUrl: self.serverUrl) + } } - } - - dataSource = NCDataSource.init(metadatasSource: metadatasSource, directoryOnTop: directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) - - refreshControl.endRefreshing() - collectionView.reloadData() - - // Blink file - if fileName != nil { - if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", appDelegate.account, serverUrl, fileName!)) { - if let row = dataSource.getIndexMetadata(ocId: metadata.ocId) { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { - UIView.animate(withDuration: 0.3) { - self.collectionView.scrollToItem(at: IndexPath(row: row, section: 0), at: .centeredVertically, animated: false) - } completion: { (_) in - if let cell = self.collectionView.cellForItem(at: IndexPath(row: row, section: 0)) { - NCUtility.shared.blink(cell: cell) - self.fileName = nil + + self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) + + DispatchQueue.main.async { + + self.refreshControl.endRefreshing() + self.collectionView.reloadData() + + // Blink file + if self.fileName != nil { + if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", self.appDelegate.account, self.serverUrl, self.fileName!)) { + if let row = self.dataSource.getIndexMetadata(ocId: metadata.ocId) { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + UIView.animate(withDuration: 0.3) { + self.collectionView.scrollToItem(at: IndexPath(row: row, section: 0), at: .centeredVertically, animated: false) + } completion: { (_) in + if let cell = self.collectionView.cellForItem(at: IndexPath(row: row, section: 0)) { + NCUtility.shared.blink(cell: cell) + self.fileName = nil + } + } } } } diff --git a/iOSClient/Files/NCFiles.swift b/iOSClient/Files/NCFiles.swift index d78827567..ce4eef911 100644 --- a/iOSClient/Files/NCFiles.swift +++ b/iOSClient/Files/NCFiles.swift @@ -66,22 +66,16 @@ class NCFiles: NCCollectionViewCommon { override func reloadDataSource() { super.reloadDataSource() - var sort: String - var ascending: Bool - var directoryOnTop: Bool - - (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl) - DispatchQueue.global().async { if !self.isSearching { - self.metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl), page: 0, limit: 0, sorted: sort, ascending: ascending) + self.metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl), page: 0, limit: 0, sorted: self.sort, ascending: self.ascending) if self.metadataFolder == nil { self.metadataFolder = NCManageDatabase.sharedInstance.getMetadataFolder(account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, serverUrl: self.serverUrl) } } - self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, directoryOnTop: directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) + self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, 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 c3ded82a2..28bd1d80b 100644 --- a/iOSClient/Main/NCCollectionViewCommon.swift +++ b/iOSClient/Main/NCCollectionViewCommon.swift @@ -44,6 +44,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS internal var richWorkspaceText: String? internal var layout = "" + internal var sort: String = "" + internal var ascending: Bool = true + internal var directoryOnTop: Bool = true internal var groupBy = "" internal var titleButton = "" internal var itemForLine = 0 @@ -918,6 +921,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS @objc func reloadDataSource() { if appDelegate.account.count == 0 { return } + // Get richWorkspace Text let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl)) richWorkspaceText = directory?.richWorkspace @@ -927,6 +931,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS // get auto upload folder autoUploadFileName = NCManageDatabase.sharedInstance.getAccountAutoUploadFileName() autoUploadDirectory = NCManageDatabase.sharedInstance.getAccountAutoUploadDirectory(urlBase: appDelegate.urlBase, account: appDelegate.account) + + // get layout for view + (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl) } @objc func reloadDataSourceNetwork(forced: Bool = false) { } @objc func reloadDataSourceNetworkRefreshControl() { diff --git a/iOSClient/Offline/NCOffline.swift b/iOSClient/Offline/NCOffline.swift index 7fe5ef202..82e04c3fe 100644 --- a/iOSClient/Offline/NCOffline.swift +++ b/iOSClient/Offline/NCOffline.swift @@ -42,41 +42,41 @@ class NCOffline: NCCollectionViewCommon { override func reloadDataSource() { super.reloadDataSource() - - var ocIds: [String] = [] - var sort: String - var ascending: Bool - var directoryOnTop: Bool - - (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl) - - if !isSearching { + + DispatchQueue.global().async { - 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) + var ocIds: [String] = [] + + if !self.isSearching { + + if self.serverUrl == "" { + + if let directories = NCManageDatabase.sharedInstance.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", self.appDelegate.account), sorted: "serverUrl", ascending: true) { + for directory: tableDirectory in directories { + ocIds.append(directory.ocId) + } } + + let files = NCManageDatabase.sharedInstance.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", self.appDelegate.account), sorted: "fileName", ascending: true) + for file: tableLocalFile in files { + ocIds.append(file.ocId) + } + + self.metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND ocId IN %@", self.appDelegate.account, ocIds), page: 0, limit: 0, sorted: self.sort, ascending: self.ascending) + + } else { + + self.metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl), page: 0, limit: 0, sorted: self.sort, ascending: self.ascending) } - - 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) - } - - 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), page: 0, limit: 0, sorted: sort, ascending: ascending) + } + + self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) + + DispatchQueue.main.async { + self.refreshControl.endRefreshing() + self.collectionView.reloadData() } } - - self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, directoryOnTop: directoryOnTop, favoriteOnTop: true, filterLivePhoto: true) - - refreshControl.endRefreshing() - collectionView.reloadData() } override func reloadDataSourceNetwork(forced: Bool = false) { diff --git a/iOSClient/Recent/NCRecent.swift b/iOSClient/Recent/NCRecent.swift index 70d1719f2..77a6d5bb5 100644 --- a/iOSClient/Recent/NCRecent.swift +++ b/iOSClient/Recent/NCRecent.swift @@ -49,13 +49,16 @@ class NCRecent: NCCollectionViewCommon { override func reloadDataSource() { super.reloadDataSource() - (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, directoryOnTop: false, favoriteOnTop: false, filterLivePhoto: true) - - refreshControl.endRefreshing() - collectionView.reloadData() + 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) + + DispatchQueue.main.async { + self.refreshControl.endRefreshing() + self.collectionView.reloadData() + } + } } override func reloadDataSourceNetwork(forced: Bool = false) { diff --git a/iOSClient/Transfers/NCTransfers.swift b/iOSClient/Transfers/NCTransfers.swift index 672ac6037..d47f9c0b8 100644 --- a/iOSClient/Transfers/NCTransfers.swift +++ b/iOSClient/Transfers/NCTransfers.swift @@ -203,9 +203,7 @@ class NCTransfers: NCCollectionViewCommon { override func reloadDataSource() { super.reloadDataSource() - - (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, directoryOnTop: false, favoriteOnTop: false, filterLivePhoto: false) |