NCRichWorkspace.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. @IBOutlet weak var viewTouch: NCRichWorkspaceViewTouch!
  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. }
  21. @objc class NCRichWorkspaceViewTouch: UIView {
  22. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  23. var startPosition: CGPoint?
  24. var originalHeight: CGFloat = 0
  25. let minHeight: CGFloat = 10
  26. let maxHeight: CGFloat = UIScreen.main.bounds.size.height/3
  27. @IBOutlet weak var imageDrag: UIImageView!
  28. required init?(coder: NSCoder) {
  29. super.init(coder: coder)
  30. NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
  31. }
  32. @objc func changeTheming() {
  33. imageDrag.image = CCGraphics.changeThemingColorImage(UIImage(named: "dragHorizontal"), width: 20, height: 10, color: NCBrandColor.sharedInstance.brandText)
  34. }
  35. override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
  36. return false
  37. }
  38. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  39. let touch = touches.first
  40. startPosition = touch?.location(in: self)
  41. originalHeight = self.frame.height
  42. }
  43. override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
  44. let touch = touches.first
  45. let endPosition = touch?.location(in: self)
  46. let difference = endPosition!.y - startPosition!.y
  47. if let viewRichWorkspace = appDelegate.activeMain.tableView.tableHeaderView {
  48. let differenceHeight = viewRichWorkspace.frame.height + difference
  49. if differenceHeight <= minHeight {
  50. CCUtility.setRichWorkspaceHeight(Int(minHeight))
  51. } else if differenceHeight >= maxHeight {
  52. CCUtility.setRichWorkspaceHeight(Int(maxHeight))
  53. } else {
  54. CCUtility.setRichWorkspaceHeight(Int(differenceHeight))
  55. }
  56. appDelegate.activeMain.setTableViewHeader()
  57. }
  58. }
  59. }