NCShare.swift 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 NCSharePaging: 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. pagingViewController.metadata = metadata
  33. // Navigation Controller
  34. var image = CCGraphics.changeThemingColorImage(UIImage(named: "exit")!, width: 40, height: 40, color: UIColor.gray)
  35. image = image?.withRenderingMode(.alwaysOriginal)
  36. self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: image, style:.plain, target: self, action: #selector(exitTapped))
  37. // Pagination
  38. addChild(pagingViewController)
  39. view.addSubview(pagingViewController.view)
  40. pagingViewController.didMove(toParent: self)
  41. pagingViewController.selectedTextColor = .black
  42. pagingViewController.indicatorColor = .black
  43. pagingViewController.indicatorOptions = .visible(
  44. height: 1,
  45. zIndex: Int.max,
  46. spacing: .zero,
  47. insets: .zero
  48. )
  49. // Contrain the paging view to all edges.
  50. pagingViewController.view.translatesAutoresizingMaskIntoConstraints = false
  51. NSLayoutConstraint.activate([
  52. pagingViewController.view.topAnchor.constraint(equalTo: view.topAnchor),
  53. pagingViewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
  54. pagingViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
  55. pagingViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
  56. ])
  57. // Set our data source and delegate.
  58. pagingViewController.dataSource = self
  59. }
  60. @objc func exitTapped() {
  61. self.dismiss(animated: true, completion: nil)
  62. }
  63. }
  64. extension NCSharePaging: PagingViewControllerDataSource {
  65. func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, viewControllerForIndex index: Int) -> UIViewController {
  66. let height = pagingViewController.options.menuHeight + NCSharePagingView.HeaderHeight
  67. switch index {
  68. case 0:
  69. let viewController = UIStoryboard(name: "NCActivity", bundle: nil).instantiateInitialViewController() as! NCActivity
  70. viewController.insets = UIEdgeInsets(top: height, left: 0, bottom: 0, right: 0)
  71. viewController.refreshControlEnable = false
  72. viewController.didSelectItemEnable = false
  73. viewController.filterFileID = metadata!.fileID
  74. return viewController
  75. case 1:
  76. let viewController = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "comments") as! NCShareComments
  77. viewController.metadata = metadata!
  78. return viewController
  79. case 2:
  80. return UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "sharing")
  81. default:
  82. return UIViewController()
  83. }
  84. }
  85. func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, pagingItemForIndex index: Int) -> T {
  86. switch index {
  87. case 0:
  88. return PagingIndexItem(index: index, title: NSLocalizedString("_activity_", comment: "")) as! T
  89. case 1:
  90. return PagingIndexItem(index: index, title: NSLocalizedString("_comments_", comment: "")) as! T
  91. case 2:
  92. return PagingIndexItem(index: index, title: NSLocalizedString("_sharing_", comment: "")) as! T
  93. default:
  94. return PagingIndexItem(index: index, title: "") as! T
  95. }
  96. }
  97. func numberOfViewControllers<T>(in: PagingViewController<T>) -> Int{
  98. return 3
  99. }
  100. }
  101. class NCShareHeaderViewController: PagingViewController<PagingIndexItem> {
  102. public var image: UIImage?
  103. public var metadata: tableMetadata?
  104. override func loadView() {
  105. view = NCSharePagingView(
  106. options: options,
  107. collectionView: collectionView,
  108. pageView: pageViewController.view,
  109. metadata: metadata
  110. )
  111. }
  112. }
  113. class NCSharePagingView: PagingView {
  114. static let HeaderHeight: CGFloat = 200
  115. var metadata: tableMetadata?
  116. var headerHeightConstraint: NSLayoutConstraint?
  117. public init(options: Parchment.PagingOptions, collectionView: UICollectionView, pageView: UIView, metadata: tableMetadata?) {
  118. super.init(options: options, collectionView: collectionView, pageView: pageView)
  119. self.metadata = metadata
  120. }
  121. required init?(coder: NSCoder) {
  122. fatalError("init(coder:) has not been implemented")
  123. }
  124. override func setupConstraints() {
  125. let headerView = Bundle.main.loadNibNamed("NCShareHeaderView", owner: self, options: nil)?.first as! NCShareHeaderView
  126. if FileManager.default.fileExists(atPath: CCUtility.getDirectoryProviderStorageIconFileID(metadata!.fileID, fileNameView: metadata!.fileNameView)) {
  127. headerView.imageView.image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconFileID(metadata!.fileID, fileNameView: metadata!.fileNameView))
  128. } else {
  129. if metadata!.iconName.count > 0 {
  130. headerView.imageView.image = UIImage.init(named: metadata!.iconName)
  131. } else if metadata!.directory {
  132. let image = UIImage.init(named: "folder")!
  133. headerView.imageView.image = CCGraphics.changeThemingColorImage(image, width: image.size.width*2, height: image.size.height*2, color: NCBrandColor.sharedInstance.brandElement)
  134. } else {
  135. headerView.imageView.image = UIImage.init(named: "file")
  136. }
  137. }
  138. headerView.fileName.text = metadata?.fileNameView
  139. if metadata!.favorite {
  140. headerView.favorite.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 40, height: 40, color: NCBrandColor.sharedInstance.yellowFavorite), for: .normal)
  141. } else {
  142. headerView.favorite.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 40, height: 40, color: NCBrandColor.sharedInstance.textInfo), for: .normal)
  143. }
  144. headerView.info.text = CCUtility.transformedSize(metadata!.size) + ", " + CCUtility.dateDiff(metadata!.date as Date)
  145. addSubview(headerView)
  146. pageView.translatesAutoresizingMaskIntoConstraints = false
  147. collectionView.translatesAutoresizingMaskIntoConstraints = false
  148. headerView.translatesAutoresizingMaskIntoConstraints = false
  149. headerHeightConstraint = headerView.heightAnchor.constraint(
  150. equalToConstant: NCSharePagingView.HeaderHeight
  151. )
  152. headerHeightConstraint?.isActive = true
  153. NSLayoutConstraint.activate([
  154. collectionView.leadingAnchor.constraint(equalTo: leadingAnchor),
  155. collectionView.trailingAnchor.constraint(equalTo: trailingAnchor),
  156. collectionView.heightAnchor.constraint(equalToConstant: options.menuHeight),
  157. collectionView.topAnchor.constraint(equalTo: headerView.bottomAnchor),
  158. headerView.topAnchor.constraint(equalTo: topAnchor),
  159. headerView.leadingAnchor.constraint(equalTo: leadingAnchor),
  160. headerView.trailingAnchor.constraint(equalTo: trailingAnchor),
  161. pageView.leadingAnchor.constraint(equalTo: leadingAnchor),
  162. pageView.trailingAnchor.constraint(equalTo: trailingAnchor),
  163. pageView.bottomAnchor.constraint(equalTo: bottomAnchor),
  164. pageView.topAnchor.constraint(equalTo: topAnchor)
  165. ])
  166. }
  167. }
  168. class NCShareHeaderView: UIView {
  169. @IBOutlet weak var imageView: UIImageView!
  170. @IBOutlet weak var fileName: UILabel!
  171. @IBOutlet weak var info: UILabel!
  172. @IBOutlet weak var favorite: UIButton!
  173. }
  174. // MARK: - Comments
  175. class NCShareComments: UIViewController {
  176. var metadata: tableMetadata?
  177. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  178. override func viewDidLoad() {
  179. super.viewDidLoad()
  180. OCNetworking.sharedManager()?.getCommentsWithAccount(appDelegate.activeAccount, fileID: metadata?.fileID, completion: { (account, list, message, errorCode) in
  181. print("ciao")
  182. })
  183. }
  184. }
  185. // MARK: - Share
  186. class NCShare: UIViewController {
  187. var metadata: tableMetadata?
  188. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  189. override func viewDidLoad() {
  190. super.viewDidLoad()
  191. }
  192. }