NCShare.swift 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // NCShare.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 17/07/2019.
  6. // Copyright © 2019 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 Parchment
  25. class NCShare: UIViewController {
  26. private let pagingViewController = NCShareHeaderViewController()
  27. @objc var metadata: tableMetadata?
  28. @objc var shareLink: String = ""
  29. @objc var shareUserAndGroup: String = ""
  30. override func viewDidLoad() {
  31. super.viewDidLoad()
  32. let storyboard = UIStoryboard(name: "NCShare", bundle: nil)
  33. let activityViewController = storyboard.instantiateViewController(withIdentifier: "activity")
  34. let commentsViewController = storyboard.instantiateViewController(withIdentifier: "comments")
  35. let sharingViewController = storyboard.instantiateViewController(withIdentifier: "sharing")
  36. let pagingViewController = FixedPagingViewController(viewControllers: [
  37. activityViewController,
  38. commentsViewController,
  39. sharingViewController
  40. ])
  41. addChild(pagingViewController)
  42. view.addSubview(pagingViewController.view)
  43. pagingViewController.didMove(toParent: self)
  44. pagingViewController.selectedTextColor = .black
  45. pagingViewController.indicatorColor = .black
  46. pagingViewController.indicatorOptions = .visible(
  47. height: 1,
  48. zIndex: Int.max,
  49. spacing: .zero,
  50. insets: .zero
  51. )
  52. // Contrain the paging view to all edges.
  53. pagingViewController.view.translatesAutoresizingMaskIntoConstraints = false
  54. NSLayoutConstraint.activate([
  55. pagingViewController.view.topAnchor.constraint(equalTo: view.topAnchor),
  56. pagingViewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
  57. pagingViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
  58. pagingViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
  59. ])
  60. var image = CCGraphics.changeThemingColorImage(UIImage(named: "exit")!, width: 40, height: 40, color: UIColor.gray)
  61. image = image?.withRenderingMode(.alwaysOriginal)
  62. self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: image, style:.plain, target: self, action: #selector(exitTapped))
  63. let iconFileExists = FileManager.default.fileExists(atPath: CCUtility.getDirectoryProviderStorageIconFileID(metadata?.fileID, fileNameView: metadata?.fileNameView))
  64. /*
  65. if iconFileExists {
  66. cell.file.image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconFileID(metadata.fileID, fileNameView: metadata.fileNameView))
  67. } else {
  68. if metadata.iconName.count > 0 {
  69. cell.file.image = UIImage.init(named: metadata.iconName)
  70. } else {
  71. cell.file.image = UIImage.init(named: "file")
  72. }
  73. }
  74. */
  75. // Set our data source and delegate.
  76. pagingViewController.dataSource = self
  77. pagingViewController.delegate = self
  78. }
  79. @objc func exitTapped() {
  80. self.dismiss(animated: true, completion: nil)
  81. }
  82. }
  83. extension NCShare: PagingViewControllerDataSource {
  84. func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, viewControllerForIndex index: Int) -> UIViewController {
  85. let viewController = TableViewController()
  86. // Inset the table view with the height of the menu height.
  87. let height = pagingViewController.options.menuHeight + CustomPagingView.HeaderHeight
  88. let insets = UIEdgeInsets(top: height, left: 0, bottom: 0, right: 0)
  89. viewController.tableView.contentInset = insets
  90. viewController.tableView.scrollIndicatorInsets = insets
  91. viewController.tableView.delegate = self
  92. return viewController
  93. }
  94. func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, pagingItemForIndex index: Int) -> T {
  95. return PagingIndexItem(index: index, title: "View \(index)") as! T
  96. }
  97. func numberOfViewControllers<T>(in: PagingViewController<T>) -> Int{
  98. return 3
  99. }
  100. }
  101. extension NCShare: PagingViewControllerDelegate {
  102. func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, didScrollToItem pagingItem: T, startingViewController: UIViewController?, destinationViewController: UIViewController, transitionSuccessful: Bool) {
  103. guard let startingViewController = startingViewController as? TableViewController else { return }
  104. guard let destinationViewController = destinationViewController as? TableViewController else { return }
  105. // Set the delegate on the currently selected view so that we can
  106. // listen to the scroll view delegate.
  107. if transitionSuccessful {
  108. startingViewController.tableView.delegate = nil
  109. destinationViewController.tableView.delegate = self
  110. }
  111. }
  112. func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, willScrollToItem pagingItem: T, startingViewController: UIViewController, destinationViewController: UIViewController) {
  113. guard let destinationViewController = destinationViewController as? TableViewController else { return }
  114. // Update the content offset based on the height of the header view.
  115. if let pagingView = pagingViewController.view as? CustomPagingView {
  116. if let headerHeight = pagingView.headerHeightConstraint?.constant {
  117. let offset = headerHeight + pagingViewController.options.menuHeight
  118. destinationViewController.tableView.contentOffset = CGPoint(x: 0, y: -offset)
  119. }
  120. }
  121. }
  122. }
  123. class NCShareHeaderViewController: PagingViewController<PagingIndexItem> {
  124. public var image: UIImage?
  125. func setx() {
  126. }
  127. override func loadView() {
  128. view = NCShareHeader(
  129. options: options,
  130. collectionView: collectionView,
  131. pageView: pageViewController.view
  132. )
  133. }
  134. }
  135. class NCShareHeader: PagingView {
  136. static let HeaderHeight: CGFloat = 200
  137. var image: UIImage?
  138. var headerHeightConstraint: NSLayoutConstraint?
  139. private lazy var headerView: UIImageView = {
  140. let view = UIImageView(image: UIImage(named: "file"))
  141. view.contentMode = .scaleAspectFill
  142. view.clipsToBounds = true
  143. return view
  144. }()
  145. override func setupConstraints() {
  146. addSubview(headerView)
  147. pageView.translatesAutoresizingMaskIntoConstraints = false
  148. collectionView.translatesAutoresizingMaskIntoConstraints = false
  149. headerView.translatesAutoresizingMaskIntoConstraints = false
  150. headerHeightConstraint = headerView.heightAnchor.constraint(
  151. equalToConstant: NCShareHeader.HeaderHeight
  152. )
  153. headerHeightConstraint?.isActive = true
  154. NSLayoutConstraint.activate([
  155. collectionView.leadingAnchor.constraint(equalTo: leadingAnchor),
  156. collectionView.trailingAnchor.constraint(equalTo: trailingAnchor),
  157. collectionView.heightAnchor.constraint(equalToConstant: options.menuHeight),
  158. collectionView.topAnchor.constraint(equalTo: headerView.bottomAnchor),
  159. headerView.topAnchor.constraint(equalTo: topAnchor),
  160. headerView.leadingAnchor.constraint(equalTo: leadingAnchor),
  161. headerView.trailingAnchor.constraint(equalTo: trailingAnchor),
  162. pageView.leadingAnchor.constraint(equalTo: leadingAnchor),
  163. pageView.trailingAnchor.constraint(equalTo: trailingAnchor),
  164. pageView.bottomAnchor.constraint(equalTo: bottomAnchor),
  165. pageView.topAnchor.constraint(equalTo: topAnchor)
  166. ])
  167. }
  168. }