123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- //
- // NCShare.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 17/07/2019.
- // Copyright © 2019 Marino Faggiana. All rights reserved.
- //
- // Author Marino Faggiana <marino.faggiana@nextcloud.com>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- import Foundation
- import Parchment
- class NCShare: UIViewController {
-
- private let pagingViewController = NCShareHeaderViewController()
-
- @objc var metadata: tableMetadata?
- @objc var shareLink: String = ""
- @objc var shareUserAndGroup: String = ""
- override func viewDidLoad() {
- super.viewDidLoad()
-
- let storyboard = UIStoryboard(name: "NCShare", bundle: nil)
-
- let activityViewController = storyboard.instantiateViewController(withIdentifier: "activity")
- let commentsViewController = storyboard.instantiateViewController(withIdentifier: "comments")
- let sharingViewController = storyboard.instantiateViewController(withIdentifier: "sharing")
-
- let pagingViewController = FixedPagingViewController(viewControllers: [
- activityViewController,
- commentsViewController,
- sharingViewController
- ])
-
- addChild(pagingViewController)
- view.addSubview(pagingViewController.view)
- pagingViewController.didMove(toParent: self)
-
- pagingViewController.selectedTextColor = .black
- pagingViewController.indicatorColor = .black
- pagingViewController.indicatorOptions = .visible(
- height: 1,
- zIndex: Int.max,
- spacing: .zero,
- insets: .zero
- )
-
- // Contrain the paging view to all edges.
- pagingViewController.view.translatesAutoresizingMaskIntoConstraints = false
- NSLayoutConstraint.activate([
- pagingViewController.view.topAnchor.constraint(equalTo: view.topAnchor),
- pagingViewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
- pagingViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
- pagingViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
- ])
-
- var image = CCGraphics.changeThemingColorImage(UIImage(named: "exit")!, width: 40, height: 40, color: UIColor.gray)
- image = image?.withRenderingMode(.alwaysOriginal)
- self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: image, style:.plain, target: self, action: #selector(exitTapped))
-
- let iconFileExists = FileManager.default.fileExists(atPath: CCUtility.getDirectoryProviderStorageIconFileID(metadata?.fileID, fileNameView: metadata?.fileNameView))
-
-
-
- /*
- if iconFileExists {
-
- cell.file.image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconFileID(metadata.fileID, fileNameView: metadata.fileNameView))
- } else {
- if metadata.iconName.count > 0 {
- cell.file.image = UIImage.init(named: metadata.iconName)
- } else {
- cell.file.image = UIImage.init(named: "file")
- }
- }
- */
-
- // Set our data source and delegate.
- pagingViewController.dataSource = self
- pagingViewController.delegate = self
- }
-
- @objc func exitTapped() {
- self.dismiss(animated: true, completion: nil)
- }
- }
- extension NCShare: PagingViewControllerDataSource {
-
- func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, viewControllerForIndex index: Int) -> UIViewController {
- let viewController = TableViewController()
-
- // Inset the table view with the height of the menu height.
- let height = pagingViewController.options.menuHeight + CustomPagingView.HeaderHeight
- let insets = UIEdgeInsets(top: height, left: 0, bottom: 0, right: 0)
- viewController.tableView.contentInset = insets
- viewController.tableView.scrollIndicatorInsets = insets
- viewController.tableView.delegate = self
-
- return viewController
- }
-
- func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, pagingItemForIndex index: Int) -> T {
- return PagingIndexItem(index: index, title: "View \(index)") as! T
- }
-
- func numberOfViewControllers<T>(in: PagingViewController<T>) -> Int{
- return 3
- }
-
- }
- extension NCShare: PagingViewControllerDelegate {
-
- func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, didScrollToItem pagingItem: T, startingViewController: UIViewController?, destinationViewController: UIViewController, transitionSuccessful: Bool) {
- guard let startingViewController = startingViewController as? TableViewController else { return }
- guard let destinationViewController = destinationViewController as? TableViewController else { return }
-
- // Set the delegate on the currently selected view so that we can
- // listen to the scroll view delegate.
- if transitionSuccessful {
- startingViewController.tableView.delegate = nil
- destinationViewController.tableView.delegate = self
- }
- }
-
- func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, willScrollToItem pagingItem: T, startingViewController: UIViewController, destinationViewController: UIViewController) {
- guard let destinationViewController = destinationViewController as? TableViewController else { return }
-
- // Update the content offset based on the height of the header view.
- if let pagingView = pagingViewController.view as? CustomPagingView {
- if let headerHeight = pagingView.headerHeightConstraint?.constant {
- let offset = headerHeight + pagingViewController.options.menuHeight
- destinationViewController.tableView.contentOffset = CGPoint(x: 0, y: -offset)
- }
- }
- }
-
- }
- class NCShareHeaderViewController: PagingViewController<PagingIndexItem> {
-
- public var image: UIImage?
- func setx() {
-
- }
-
- override func loadView() {
- view = NCShareHeader(
- options: options,
- collectionView: collectionView,
- pageView: pageViewController.view
- )
- }
- }
- class NCShareHeader: PagingView {
-
- static let HeaderHeight: CGFloat = 200
- var image: UIImage?
-
- var headerHeightConstraint: NSLayoutConstraint?
-
- private lazy var headerView: UIImageView = {
- let view = UIImageView(image: UIImage(named: "file"))
- view.contentMode = .scaleAspectFill
- view.clipsToBounds = true
- return view
- }()
-
- override func setupConstraints() {
- addSubview(headerView)
-
- pageView.translatesAutoresizingMaskIntoConstraints = false
- collectionView.translatesAutoresizingMaskIntoConstraints = false
- headerView.translatesAutoresizingMaskIntoConstraints = false
-
- headerHeightConstraint = headerView.heightAnchor.constraint(
- equalToConstant: NCShareHeader.HeaderHeight
- )
- headerHeightConstraint?.isActive = true
-
- NSLayoutConstraint.activate([
- collectionView.leadingAnchor.constraint(equalTo: leadingAnchor),
- collectionView.trailingAnchor.constraint(equalTo: trailingAnchor),
- collectionView.heightAnchor.constraint(equalToConstant: options.menuHeight),
- collectionView.topAnchor.constraint(equalTo: headerView.bottomAnchor),
-
- headerView.topAnchor.constraint(equalTo: topAnchor),
- headerView.leadingAnchor.constraint(equalTo: leadingAnchor),
- headerView.trailingAnchor.constraint(equalTo: trailingAnchor),
-
- pageView.leadingAnchor.constraint(equalTo: leadingAnchor),
- pageView.trailingAnchor.constraint(equalTo: trailingAnchor),
- pageView.bottomAnchor.constraint(equalTo: bottomAnchor),
- pageView.topAnchor.constraint(equalTo: topAnchor)
- ])
- }
- }
|