DocumentPickerViewController.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // DocumentPickerViewController.swift
  3. // Picker
  4. //
  5. // Created by Marino Faggiana on 27/12/16.
  6. // Copyright © 2016 TWS. All rights reserved.
  7. //
  8. import UIKit
  9. class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCNetworkingDelegate {
  10. // MARK: - Properties
  11. var metadata : CCMetadata?
  12. var sectionDataSource = [CCSectionDataSource]()
  13. let dirGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: capabilitiesGroups)
  14. var activeAccount : String?
  15. var activeUrl : String?
  16. var activeUser : String?
  17. var activePassword : String?
  18. var activeUID : String?
  19. var activeAccessToken : String?
  20. var directoryUser : String?
  21. var typeCloud : String?
  22. var serverUrl : String?
  23. var localServerUrl : String?
  24. lazy var networkingOperationQueue : OperationQueue = {
  25. var queue = OperationQueue()
  26. queue.name = "it.twsweb.cryptocloud.queue"
  27. queue.maxConcurrentOperationCount = 1
  28. return queue
  29. }()
  30. // MARK: - IBOutlets
  31. @IBOutlet weak var tableView: UITableView!
  32. // MARK: - View Life Cycle
  33. override func viewDidLoad() {
  34. let pathDB = dirGroup?.appendingPathComponent(appDatabase).appendingPathComponent("cryptocloud")
  35. MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStore(at: pathDB!)
  36. MagicalRecord.setLoggingLevel(MagicalRecordLoggingLevel.off)
  37. if let record = CCCoreData.getActiveAccount() {
  38. activeAccount = record.account!
  39. activePassword = record.password!
  40. activeUrl = record.url!
  41. typeCloud = record.typeCloud!
  42. localServerUrl = CCUtility.getHomeServerUrlActiveUrl(activeUrl!, typeCloud: typeCloud!)
  43. } else {
  44. // Close return nil
  45. let deadlineTime = DispatchTime.now() + 0.1
  46. DispatchQueue.main.asyncAfter(deadline: deadlineTime) {
  47. let alert = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_message_", comment: ""), preferredStyle: .alert)
  48. alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { action in
  49. self.dismissGrantingAccess(to: nil)
  50. })
  51. self.present(alert, animated: true, completion: nil)
  52. }
  53. return
  54. }
  55. CCNetworking.shared().settingDelegate(self)
  56. }
  57. override func viewWillAppear(_ animated: Bool) {
  58. super.viewWillAppear(animated)
  59. let directoryID : String? = CCCoreData.getDirectoryID(fromServerUrl: localServerUrl!, activeAccount: activeAccount!)
  60. let predicate = NSPredicate(format: "(account == %@) AND (directoryID == %@)", activeAccount!, directoryID!)
  61. let recordsTableMetadata = CCCoreData.getTableMetadata(with: predicate, fieldOrder: CCUtility.getOrderSettings()!, ascending: CCUtility.getAscendingSettings())
  62. sectionDataSource = [CCSection.creataDataSourseSectionTableMetadata(recordsTableMetadata, listProgressMetadata: nil, groupByField: "none", replaceDateToExifDate: false, activeAccount: activeAccount)]
  63. tableView.reloadData()
  64. }
  65. /*
  66. @IBAction func openDocument(_ sender: AnyObject?) {
  67. let documentURL = self.documentStorageURL!.appendingPathComponent("Untitled.txt")
  68. // TODO: if you do not have a corresponding file provider, you must ensure that the URL returned here is backed by a file
  69. self.dismissGrantingAccess(to: documentURL)
  70. }
  71. override func prepareForPresentation(in mode: UIDocumentPickerMode) {
  72. // TODO: present a view controller appropriate for picker mode here
  73. }
  74. */
  75. }
  76. /*
  77. // MARK: - UITableViewDataSource
  78. extension DocumentPickerViewController: UITableViewDataSource {
  79. // MARK: - CellIdentifiers
  80. fileprivate enum CellIdentifier: String {
  81. case NoteCell = "noteCell"
  82. }
  83. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  84. return notes.count
  85. }
  86. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  87. let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier.NoteCell.rawValue, for: indexPath)
  88. let note = notes[(indexPath as NSIndexPath).row]
  89. cell.textLabel?.text = note.title
  90. return cell
  91. }
  92. }
  93. */