NCOffline.swift 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // NCOffline.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/10/2018.
  6. // Copyright © 2018 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 UIKit
  24. import NextcloudKit
  25. class NCOffline: NCCollectionViewCommon {
  26. required init?(coder aDecoder: NSCoder) {
  27. super.init(coder: aDecoder)
  28. titleCurrentFolder = NSLocalizedString("_manage_file_offline_", comment: "")
  29. layoutKey = NCGlobal.shared.layoutViewOffline
  30. enableSearchBar = false
  31. headerRichWorkspaceDisable = true
  32. emptyImage = UIImage(named: "folder")?.image(color: NCBrandColor.shared.brandElement, size: UIScreen.main.bounds.width)
  33. emptyTitle = "_files_no_files_"
  34. emptyDescription = "_tutorial_offline_view_"
  35. emptyDataPortaitOffset = 30
  36. emptyDataLandscapeOffset = 20
  37. }
  38. // MARK: - View Life Cycle
  39. override func viewWillAppear(_ animated: Bool) {
  40. super.viewWillAppear(animated)
  41. reloadDataSource()
  42. }
  43. // MARK: - DataSource + NC Endpoint
  44. override func queryDB() {
  45. super.queryDB()
  46. var ocIds: [String] = []
  47. var metadatas: [tableMetadata] = []
  48. if self.serverUrl.isEmpty {
  49. if let directories = NCManageDatabase.shared.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", self.appDelegate.account), sorted: "serverUrl", ascending: true) {
  50. for directory: tableDirectory in directories {
  51. ocIds.append(directory.ocId)
  52. }
  53. }
  54. let files = NCManageDatabase.shared.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", self.appDelegate.account), sorted: "fileName", ascending: true)
  55. for file in files {
  56. ocIds.append(file.ocId)
  57. }
  58. metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND ocId IN %@", self.appDelegate.account, ocIds))
  59. } else {
  60. metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl))
  61. }
  62. self.dataSource = NCDataSource(
  63. metadatas: metadatas,
  64. account: self.appDelegate.account,
  65. sort: self.layoutForView?.sort,
  66. ascending: self.layoutForView?.ascending,
  67. directoryOnTop: self.layoutForView?.directoryOnTop,
  68. favoriteOnTop: true,
  69. groupByField: self.groupByField,
  70. providers: self.providers,
  71. searchResults: self.searchResults)
  72. }
  73. override func reloadDataSourceNetwork() {
  74. super.reloadDataSourceNetwork()
  75. reloadDataSource()
  76. }
  77. }