NCRichWorkspace.swift 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 == self.richWorkspace { return }
  23. if richWorkspace != nil || richWorkspace!.count > 0 {
  24. html = "<h2><span style=\"color: #000000;\">" + richWorkspace! + "</span></h2>"
  25. } else {
  26. html = "<h2><span style=\"color: #000000;\">" + NSLocalizedString("_add_notes_readme_md_", comment: "") + "</span></h2>"
  27. }
  28. self.richWorkspace = richWorkspace
  29. webView.loadHTMLString(html, baseURL: Bundle.main.bundleURL)
  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. @IBOutlet weak var imageDrag: UIImageView!
  39. required init?(coder: NSCoder) {
  40. super.init(coder: coder)
  41. NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
  42. }
  43. @objc func changeTheming() {
  44. imageDrag.image = CCGraphics.changeThemingColorImage(UIImage(named: "dragHorizontal"), width: 20, height: 10, color: NCBrandColor.sharedInstance.brandText)
  45. }
  46. override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
  47. return false
  48. }
  49. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  50. let touch = touches.first
  51. startPosition = touch?.location(in: self)
  52. originalHeight = self.frame.height
  53. }
  54. override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
  55. let touch = touches.first
  56. let endPosition = touch?.location(in: self)
  57. let difference = endPosition!.y - startPosition!.y
  58. if let viewRichWorkspace = appDelegate.activeMain.tableView.tableHeaderView {
  59. let differenceHeight = viewRichWorkspace.frame.height + difference
  60. if differenceHeight <= minHeight {
  61. CCUtility.setRichWorkspaceHeight(minHeight)
  62. } else if differenceHeight >= maxHeight {
  63. CCUtility.setRichWorkspaceHeight(maxHeight)
  64. } else {
  65. CCUtility.setRichWorkspaceHeight(differenceHeight)
  66. }
  67. appDelegate.activeMain.setTableViewHeader()
  68. }
  69. }
  70. override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
  71. // appDelegate.activeMain.tableView.reloadData()
  72. }
  73. }