NCViewerRichWorkspace.swift 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // NCViewerRichWorkspace.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 14/01/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. @objc class NCViewerRichWorkspace: UIViewController, UIAdaptivePresentationControllerDelegate {
  26. @IBOutlet weak var viewRichWorkspace: NCViewRichWorkspace!
  27. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  28. @objc public var richWorkspace: String = ""
  29. @objc public var serverUrl: String = ""
  30. override func viewDidLoad() {
  31. super.viewDidLoad()
  32. presentationController?.delegate = self
  33. let closeItem = UIBarButtonItem(title: NSLocalizedString("_back_", comment: ""), style: .plain, target: self, action: #selector(closeItemTapped(_:)))
  34. self.navigationItem.leftBarButtonItem = closeItem
  35. let editItem = UIBarButtonItem(image: UIImage(named: "actionSheetModify"), style: UIBarButtonItem.Style.plain, target: self, action: #selector(editItemAction(_:)))
  36. self.navigationItem.rightBarButtonItem = editItem
  37. viewRichWorkspace.setRichWorkspaceText(richWorkspace, gradient: false)
  38. NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
  39. changeTheming()
  40. }
  41. override func viewWillAppear(_ animated: Bool) {
  42. super.viewWillAppear(animated)
  43. NCCommunication.sharedInstance.readFileOrFolder(serverUrlFileName: serverUrl, depth: "0", account: appDelegate.activeAccount) { (account, files, errorCode, errorMessage) in
  44. if errorCode == 0 && account == self.appDelegate.activeAccount {
  45. var metadataFolder = tableMetadata()
  46. _ = NCNetworking.sharedInstance.convertFiles(files!, urlString: self.appDelegate.activeUrl, serverUrl: self.serverUrl, user: self.appDelegate.activeUser, metadataFolder: &metadataFolder)
  47. NCManageDatabase.sharedInstance.setDirectory(ocId: metadataFolder.ocId, serverUrl: metadataFolder.serverUrl, richWorkspace: metadataFolder.richWorkspace, account: account)
  48. self.richWorkspace = metadataFolder.richWorkspace
  49. self.appDelegate.activeMain.richWorkspace = self.richWorkspace
  50. self.viewRichWorkspace.setRichWorkspaceText(self.richWorkspace, gradient: false)
  51. }
  52. }
  53. }
  54. public func presentationControllerWillDismiss(_ presentationController: UIPresentationController) {
  55. self.viewWillAppear(true)
  56. }
  57. @objc func changeTheming() {
  58. appDelegate.changeTheming(self, tableView: nil, collectionView: nil, form: false)
  59. }
  60. @objc func closeItemTapped(_ sender: UIBarButtonItem) {
  61. self.dismiss(animated: false, completion: nil)
  62. }
  63. @IBAction func editItemAction(_ sender: Any) {
  64. let richWorkspaceTextCommon = NCRichWorkspaceTextCommon()
  65. richWorkspaceTextCommon.openViewerNextcloudText(serverUrl: serverUrl, viewController: self)
  66. }
  67. }