NCOffline.swift 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. import RealmSwift
  26. class NCOffline: NCCollectionViewCommon {
  27. required init?(coder aDecoder: NSCoder) {
  28. super.init(coder: aDecoder)
  29. titleCurrentFolder = NSLocalizedString("_manage_file_offline_", comment: "")
  30. layoutKey = NCGlobal.shared.layoutViewOffline
  31. enableSearchBar = false
  32. headerRichWorkspaceDisable = true
  33. emptyImageName = "icloud.and.arrow.down"
  34. emptyTitle = "_files_no_files_"
  35. emptyDescription = "_tutorial_offline_view_"
  36. emptyDataPortaitOffset = 30
  37. emptyDataLandscapeOffset = 20
  38. }
  39. // MARK: - View Life Cycle
  40. override func viewWillAppear(_ animated: Bool) {
  41. super.viewWillAppear(animated)
  42. reloadDataSource()
  43. }
  44. // MARK: - DataSource
  45. override func reloadDataSource() {
  46. var ocIds: [String] = []
  47. var metadatas: [tableMetadata] = []
  48. if self.serverUrl.isEmpty {
  49. if let directories = self.database.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", session.account), sorted: "serverUrl", ascending: true) {
  50. for directory: tableDirectory in directories {
  51. ocIds.append(directory.ocId)
  52. }
  53. }
  54. let files = self.database.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", session.account), sorted: "fileName", ascending: true)
  55. for file in files {
  56. ocIds.append(file.ocId)
  57. }
  58. if let results = self.database.getResultsMetadatas(predicate: NSPredicate(format: "account == %@ AND ocId IN %@ AND NOT (status IN %@)", session.account, ocIds, global.metadataStatusHideInView)) {
  59. metadatas = Array(results.freeze())
  60. }
  61. } else {
  62. metadatas = self.database.getResultsMetadatasPredicate(self.defaultPredicate, layoutForView: layoutForView)
  63. }
  64. self.dataSource = NCCollectionViewDataSource(metadatas: metadatas, layoutForView: layoutForView)
  65. super.reloadDataSource()
  66. }
  67. override func getServerData() {
  68. reloadDataSource()
  69. }
  70. }