NCFiles.swift 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // NCFiles.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 26/09/2020.
  6. // Copyright © 2020 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. import NCCommunication
  25. class NCFiles: NCCollectionViewCommon {
  26. required init?(coder aDecoder: NSCoder) {
  27. super.init(coder: aDecoder)
  28. appDelegate.activeFiles = self
  29. titleCurrentFolder = NCBrandOptions.sharedInstance.brand
  30. layoutKey = k_layout_view_files
  31. enableSearchBar = true
  32. DZNimage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 300, height: 300, color: NCBrandColor.sharedInstance.brandElement)
  33. DZNtitle = "_files_no_files_"
  34. DZNdescription = "_no_file_pull_down_"
  35. }
  36. override func viewWillAppear(_ animated: Bool) {
  37. appDelegate.activeServerUrl = serverUrl
  38. super.viewWillAppear(animated)
  39. }
  40. // MARK: - DataSource + NC Endpoint
  41. override func reloadDataSource() {
  42. super.reloadDataSource()
  43. var sort: String
  44. var ascending: Bool
  45. var directoryOnTop: Bool
  46. (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey)
  47. if !isSearching {
  48. metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl))
  49. }
  50. self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, filterLivePhoto: true)
  51. refreshControl.endRefreshing()
  52. collectionView.reloadData()
  53. }
  54. override func reloadDataSourceNetwork(forced: Bool = false) {
  55. super.reloadDataSourceNetwork(forced: forced)
  56. if isSearching {
  57. networkSearch()
  58. return
  59. }
  60. isReloadDataSourceNetworkInProgress = true
  61. collectionView?.reloadData()
  62. networkReadFolder(forced: forced) { (metadatas, errorCode, errorDescription) in
  63. if errorCode == 0 {
  64. for metadata in metadatas ?? [] {
  65. if !metadata.directory {
  66. let localFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  67. if (CCUtility.getFavoriteOffline() && localFile == nil) || (localFile != nil && localFile?.etag != metadata.etag) {
  68. NCOperationQueue.shared.download(metadata: metadata, selector: selectorDownloadFile, setFavorite: false)
  69. }
  70. }
  71. }
  72. }
  73. self.isReloadDataSourceNetworkInProgress = false
  74. self.reloadDataSource()
  75. }
  76. }
  77. }