NCRichWorkspace.swift 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // NCRichWorkspace.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 09/01/2020.
  6. // Copyright © 2020 TWS. All rights reserved.
  7. //
  8. import Foundation
  9. @objc class NCViewRichWorkspace: UIView {
  10. @IBOutlet weak var webView: WKWebView!
  11. var richWorkspace: String?
  12. required init?(coder: NSCoder) {
  13. super.init(coder: coder)
  14. NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
  15. self.backgroundColor = NCBrandColor.sharedInstance.brand;
  16. }
  17. @objc func changeTheming() {
  18. self.backgroundColor = NCBrandColor.sharedInstance.brand;
  19. }
  20. @objc func setRichWorkspaceText(_ richWorkspace: String?) {
  21. var html = ""
  22. if richWorkspace != nil && richWorkspace!.count > 0 {
  23. html = "<h2><span style=\"color: #000000;\">" + richWorkspace! + "</span></h2>"
  24. } else {
  25. html = "<h2><span style=\"color: #000000;\">" + NSLocalizedString("_add_notes_readme_md_", comment: "") + "</span></h2>"
  26. }
  27. self.richWorkspace = richWorkspace
  28. webView.loadHTMLString(html, baseURL: Bundle.main.bundleURL)
  29. webView.isUserInteractionEnabled = false
  30. }
  31. }
  32. @objc class NCRichWorkspaceViewTouch: UIView {
  33. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  34. var startPosition: CGPoint?
  35. var originalHeight: CGFloat = 0
  36. let minHeight: CGFloat = 0
  37. let maxHeight: CGFloat = UIScreen.main.bounds.size.height/3
  38. required init?(coder: NSCoder) {
  39. super.init(coder: coder)
  40. self.backgroundColor = NCBrandColor.sharedInstance.separator
  41. }
  42. /*
  43. override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
  44. return false
  45. }
  46. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  47. let touch = touches.first
  48. startPosition = touch?.location(in: self)
  49. originalHeight = self.frame.height
  50. }
  51. override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
  52. let touch = touches.first
  53. let endPosition = touch?.location(in: self)
  54. let difference = endPosition!.y - startPosition!.y
  55. if let viewRichWorkspace = appDelegate.activeMain.tableView.tableHeaderView {
  56. let differenceHeight = viewRichWorkspace.frame.height + difference
  57. if differenceHeight <= minHeight {
  58. CCUtility.setRichWorkspaceHeight(minHeight)
  59. } else if differenceHeight >= maxHeight {
  60. CCUtility.setRichWorkspaceHeight(maxHeight)
  61. } else {
  62. CCUtility.setRichWorkspaceHeight(differenceHeight)
  63. }
  64. appDelegate.activeMain.setTableViewHeader()
  65. }
  66. }
  67. override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
  68. // appDelegate.activeMain.tableView.reloadData()
  69. }
  70. */
  71. }