NCRichWorkspaceCommon.swift 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // NCRichWorkspaceCommon.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 17/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 NCRichWorkspaceCommon: NSObject {
  26. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  27. @objc func createViewerNextcloudText(serverUrl: String,viewController: UIViewController) {
  28. if !appDelegate.reachability.isReachable() {
  29. NCContentPresenter.shared.messageNotification("_error_", description: "_go_online_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: 0)
  30. return;
  31. }
  32. NCUtility.sharedInstance.startActivityIndicator(view: viewController.view, bottom: 0)
  33. let fileNamePath = CCUtility.returnFileNamePath(fromFileName: k_fileNameRichWorkspace, serverUrl: serverUrl, activeUrl: appDelegate.activeUrl)!
  34. NCCommunication.sharedInstance.NCTextCreateFile(urlString: appDelegate.activeUrl, fileNamePath: fileNamePath, editorId: "text", creatorId: "" ,templateId: "", customUserAgent: nil, account: appDelegate.activeAccount) { (account, url, errorCode, errorMessage) in
  35. NCUtility.sharedInstance.stopActivityIndicator()
  36. if errorCode == 0 && account == self.appDelegate.activeAccount {
  37. if let viewerRichWorkspaceWebView = UIStoryboard.init(name: "NCViewerRichWorkspace", bundle: nil).instantiateViewController(withIdentifier: "NCViewerRichWorkspaceWebView") as? NCViewerRichWorkspaceWebView {
  38. viewerRichWorkspaceWebView.url = url!
  39. viewerRichWorkspaceWebView.presentationController?.delegate = viewController as? UIAdaptivePresentationControllerDelegate
  40. viewController.present(viewerRichWorkspaceWebView, animated: true, completion: nil)
  41. }
  42. } else if errorCode != 0 {
  43. NCContentPresenter.shared.messageNotification("_error_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: errorCode)
  44. }
  45. }
  46. }
  47. @objc func openViewerNextcloudText(serverUrl: String, viewController: UIViewController) {
  48. if !appDelegate.reachability.isReachable() {
  49. NCContentPresenter.shared.messageNotification("_error_", description: "_go_online_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: 0)
  50. return;
  51. }
  52. if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", appDelegate.activeAccount, serverUrl, k_fileNameRichWorkspace.lowercased())) {
  53. if metadata.url == "" {
  54. NCUtility.sharedInstance.startActivityIndicator(view: viewController.view, bottom: 0)
  55. let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: appDelegate.activeUrl)!
  56. NCCommunication.sharedInstance.NCTextOpenFile(urlString: appDelegate.activeUrl, fileNamePath: fileNamePath, editor: "text", customUserAgent: nil, account: appDelegate.activeAccount) { (account, url, errorCode, errorMessage) in
  57. NCUtility.sharedInstance.stopActivityIndicator()
  58. if errorCode == 0 && account == self.appDelegate.activeAccount {
  59. if let viewerRichWorkspaceWebView = UIStoryboard.init(name: "NCViewerRichWorkspace", bundle: nil).instantiateViewController(withIdentifier: "NCViewerRichWorkspaceWebView") as? NCViewerRichWorkspaceWebView {
  60. viewerRichWorkspaceWebView.url = url!
  61. viewerRichWorkspaceWebView.metadata = metadata
  62. viewerRichWorkspaceWebView.presentationController?.delegate = viewController as? UIAdaptivePresentationControllerDelegate
  63. viewController.present(viewerRichWorkspaceWebView, animated: true, completion: nil)
  64. }
  65. } else if errorCode != 0 {
  66. NCContentPresenter.shared.messageNotification("_error_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: errorCode)
  67. }
  68. }
  69. } else {
  70. if let viewerRichWorkspaceWebView = UIStoryboard.init(name: "NCViewerRichWorkspace", bundle: nil).instantiateViewController(withIdentifier: "NCViewerRichWorkspaceWebView") as? NCViewerRichWorkspaceWebView {
  71. viewerRichWorkspaceWebView.url = metadata.url
  72. viewerRichWorkspaceWebView.metadata = metadata
  73. viewerRichWorkspaceWebView.presentationController?.delegate = viewController as? UIAdaptivePresentationControllerDelegate
  74. viewController.present(viewerRichWorkspaceWebView, animated: true, completion: nil)
  75. }
  76. }
  77. }
  78. }
  79. }