123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658 |
- //
- // 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 NCSharePaging: UIViewController {
-
- private let pagingViewController = NCShareHeaderViewController()
-
- @objc var metadata: tableMetadata?
- override func viewDidLoad() {
- super.viewDidLoad()
-
- pagingViewController.metadata = metadata
-
- // Navigation Controller
- 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))
- // Pagination
- 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),
- ])
-
- // Set our data source and delegate.
- pagingViewController.dataSource = self
- }
-
- @objc func exitTapped() {
- self.dismiss(animated: true, completion: nil)
- }
- }
- extension NCSharePaging: PagingViewControllerDataSource {
-
- func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, viewControllerForIndex index: Int) -> UIViewController {
-
- let height = pagingViewController.options.menuHeight + NCSharePagingView.HeaderHeight
-
- switch index {
- case 0:
- let viewController = UIStoryboard(name: "NCActivity", bundle: nil).instantiateInitialViewController() as! NCActivity
- viewController.insets = UIEdgeInsets(top: height, left: 0, bottom: 0, right: 0)
- viewController.refreshControlEnable = false
- viewController.didSelectItemEnable = false
- viewController.filterFileID = metadata!.fileID
- return viewController
- case 1:
- let viewController = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "comments") as! NCShareComments
- viewController.metadata = metadata!
- return viewController
- case 2:
- let viewController = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "sharing") as! NCShare
- viewController.metadata = metadata!
- viewController.height = height
- return viewController
- default:
- return UIViewController()
- }
- }
-
- func pagingViewController<T>(_ pagingViewController: PagingViewController<T>, pagingItemForIndex index: Int) -> T {
- switch index {
- case 0:
- return PagingIndexItem(index: index, title: NSLocalizedString("_activity_", comment: "")) as! T
- case 1:
- return PagingIndexItem(index: index, title: NSLocalizedString("_comments_", comment: "")) as! T
- case 2:
- return PagingIndexItem(index: index, title: NSLocalizedString("_sharing_", comment: "")) as! T
- default:
- return PagingIndexItem(index: index, title: "") as! T
- }
- }
-
- func numberOfViewControllers<T>(in: PagingViewController<T>) -> Int{
- return 3
- }
- }
- class NCShareHeaderViewController: PagingViewController<PagingIndexItem> {
-
- public var image: UIImage?
- public var metadata: tableMetadata?
- override func loadView() {
- view = NCSharePagingView(
- options: options,
- collectionView: collectionView,
- pageView: pageViewController.view,
- metadata: metadata
- )
- }
- }
- class NCSharePagingView: PagingView {
-
- static let HeaderHeight: CGFloat = 200
- var metadata: tableMetadata?
-
- var headerHeightConstraint: NSLayoutConstraint?
-
- public init(options: Parchment.PagingOptions, collectionView: UICollectionView, pageView: UIView, metadata: tableMetadata?) {
- super.init(options: options, collectionView: collectionView, pageView: pageView)
-
- self.metadata = metadata
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- override func setupConstraints() {
-
- let headerView = Bundle.main.loadNibNamed("NCShareHeaderView", owner: self, options: nil)?.first as! NCShareHeaderView
-
- if FileManager.default.fileExists(atPath: CCUtility.getDirectoryProviderStorageIconFileID(metadata!.fileID, fileNameView: metadata!.fileNameView)) {
- headerView.imageView.image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconFileID(metadata!.fileID, fileNameView: metadata!.fileNameView))
- } else {
- if metadata!.iconName.count > 0 {
- headerView.imageView.image = UIImage.init(named: metadata!.iconName)
- } else if metadata!.directory {
- let image = UIImage.init(named: "folder")!
- headerView.imageView.image = CCGraphics.changeThemingColorImage(image, width: image.size.width*2, height: image.size.height*2, color: NCBrandColor.sharedInstance.brandElement)
- } else {
- headerView.imageView.image = UIImage.init(named: "file")
- }
- }
- headerView.fileName.text = metadata?.fileNameView
- if metadata!.favorite {
- headerView.favorite.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 40, height: 40, color: NCBrandColor.sharedInstance.yellowFavorite), for: .normal)
- } else {
- headerView.favorite.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 40, height: 40, color: NCBrandColor.sharedInstance.textInfo), for: .normal)
- }
- headerView.info.text = CCUtility.transformedSize(metadata!.size) + ", " + CCUtility.dateDiff(metadata!.date as Date)
- addSubview(headerView)
-
- pageView.translatesAutoresizingMaskIntoConstraints = false
- collectionView.translatesAutoresizingMaskIntoConstraints = false
- headerView.translatesAutoresizingMaskIntoConstraints = false
-
- headerHeightConstraint = headerView.heightAnchor.constraint(
- equalToConstant: NCSharePagingView.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)
- ])
- }
- }
- class NCShareHeaderView: UIView {
- @IBOutlet weak var imageView: UIImageView!
- @IBOutlet weak var fileName: UILabel!
- @IBOutlet weak var info: UILabel!
- @IBOutlet weak var favorite: UIButton!
- }
- // MARK: - Comments
- class NCShareComments: UIViewController {
-
- var metadata: tableMetadata?
- private let appDelegate = UIApplication.shared.delegate as! AppDelegate
- override func viewDidLoad() {
- super.viewDidLoad()
-
- OCNetworking.sharedManager()?.getCommentsWithAccount(appDelegate.activeAccount, fileID: metadata?.fileID, completion: { (account, list, message, errorCode) in
- print("ciao")
- })
- }
- }
- // MARK: - Share
- class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDelegate {
-
- var metadata: tableMetadata?
- private let appDelegate = UIApplication.shared.delegate as! AppDelegate
- public var height: CGFloat = 0
-
- private var viewMenuShareLink: UIView?
- private var shareLinkMenuView: NCShareLinkMenuView?
- @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint!
- @IBOutlet weak var searchField: UITextField!
- @IBOutlet weak var returnSearchButton: UIButton!
- @IBOutlet weak var shareLinkImage: UIImageView!
- @IBOutlet weak var shareLinkLabel: UILabel!
- @IBOutlet weak var buttonCopy: UIButton!
- @IBOutlet weak var buttonMenu: UIButton!
- @IBOutlet weak var tableView: UITableView!
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- viewContainerConstraint.constant = height
-
- searchField.placeholder = NSLocalizedString("_shareLinksearch_placeholder_", comment: "")
-
- returnSearchButton.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "arrowRight"), width: 100, height: 100, color: UIColor.gray), for: .normal)
- shareLinkLabel.text = NSLocalizedString("_share_link_", comment: "")
- shareLinkImage.image = NCShareCommon.sharedInstance.createLinkAvatar()
- buttonCopy.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareCopy"), width: 100, height: 100, color: UIColor.gray), for: .normal)
- tableView.dataSource = self
- tableView.delegate = self
- tableView.allowsSelection = false
-
- tableView.register(UINib.init(nibName: "NCShareLinkCell", bundle: nil), forCellReuseIdentifier: "cellLink")
-
- reloadData()
- }
-
- override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
- viewMenuShareLink?.removeFromSuperview()
- }
-
- @IBAction func touchUpInsideButtonCopy(_ sender: Any) {
- let shares = NCManageDatabase.sharedInstance.getTableShares(metadata: metadata!)
- tapCopy(with: shares.firstShareLink, sender: sender)
- }
-
- @IBAction func touchUpInsideButtonMenu(_ sender: Any) {
- let shares = NCManageDatabase.sharedInstance.getTableShares(metadata: metadata!)
- if shares.firstShareLink != nil {
- tapMenu(with: shares.firstShareLink!, sender: sender)
- } else {
- tapMenu(with: nil, sender: sender)
- }
- }
-
- func tapCopy(with tableShare: tableShare?, sender: Any) {
- NCShareCommon.sharedInstance.copyLink(tableShare: tableShare, viewController: self)
- }
-
- func tapMenu(with tableShare: tableShare?, sender: Any) {
- NCShareCommon.sharedInstance.openViewMenuShareLink(view: self.view, height: height, tableShare: tableShare)
- }
-
- func reloadData() {
- let shares = NCManageDatabase.sharedInstance.getTableShares(metadata: metadata!)
- if shares.firstShareLink == nil {
- buttonMenu.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareAdd"), width: 100, height: 100, color: UIColor.gray), for: .normal)
- buttonCopy.isHidden = true
- } else {
- buttonMenu.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareMenu"), width: 100, height: 100, color: UIColor.gray), for: .normal)
- buttonCopy.isHidden = false
- }
- }
- }
- extension NCShare: UITableViewDelegate {
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 60
- }
- }
- extension NCShare: UITableViewDataSource {
-
- func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-
- var numOfRows = 0
- let shares = NCManageDatabase.sharedInstance.getTableShares(metadata: metadata!)
-
- if shares.share != nil {
- numOfRows = shares.share!.count
- }
-
- return numOfRows
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-
- let shares = NCManageDatabase.sharedInstance.getTableShares(metadata: metadata!)
- let tableShare = shares.share![indexPath.row]
-
- if tableShare.shareType == Int(shareTypeLink.rawValue) {
- if let cell = tableView.dequeueReusableCell(withIdentifier: "cellLink", for: indexPath) as? NCShareLinkCell {
- cell.tableShare = tableShare
- cell.delegate = self
- return cell
- }
- }
-
- return UITableViewCell()
- }
- }
- class NCShareLinkCell: UITableViewCell {
-
- private let iconShare: CGFloat = 200
-
- var tableShare: tableShare?
- var delegate: NCShareLinkCellDelegate?
- @IBOutlet weak var imageItem: UIImageView!
- @IBOutlet weak var labelTitle: UILabel!
- @IBOutlet weak var buttonCopy: UIButton!
- @IBOutlet weak var buttonMenu: UIButton!
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- imageItem.image = NCShareCommon.sharedInstance.createLinkAvatar()
- labelTitle.text = NSLocalizedString("_share_link_", comment: "")
- buttonCopy.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareCopy"), width:100, height: 100, color: UIColor.gray), for: .normal)
- buttonMenu.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareMenu"), width:100, height: 100, color: UIColor.gray), for: .normal)
- }
-
- @IBAction func touchUpInsideCopy(_ sender: Any) {
- delegate?.tapCopy(with: tableShare, sender: sender)
- }
-
- @IBAction func touchUpInsideMenu(_ sender: Any) {
- delegate?.tapMenu(with: tableShare, sender: sender)
- }
- }
- protocol NCShareLinkCellDelegate {
- func tapCopy(with tableShare: tableShare?, sender: Any)
- func tapMenu(with tableShare: tableShare?, sender: Any)
- }
- // MARK: - ShareLinkMenuView
- class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate {
-
- @IBOutlet weak var switchAllowEditing: UISwitch!
- @IBOutlet weak var labelAllowEditing: UILabel!
-
- @IBOutlet weak var switchHideDownload: UISwitch!
- @IBOutlet weak var labelHideDownload: UILabel!
-
- @IBOutlet weak var switchPasswordProtect: UISwitch!
- @IBOutlet weak var labelPasswordProtect: UILabel!
- @IBOutlet weak var fieldPasswordProtect: UITextField!
-
- @IBOutlet weak var switchSetExpirationDate: UISwitch!
- @IBOutlet weak var labelSetExpirationDate: UILabel!
- @IBOutlet weak var fieldSetExpirationDate: UITextField!
-
- @IBOutlet weak var imageNoteToRecipient: UIImageView!
- @IBOutlet weak var labelNoteToRecipient: UILabel!
- @IBOutlet weak var textViewNoteToRecipient: UITextView!
-
- @IBOutlet weak var buttonDeleteShareLink: UIButton!
- @IBOutlet weak var labelDeleteShareLink: UILabel!
-
- @IBOutlet weak var buttonAddAnotherLink: UIButton!
- @IBOutlet weak var labelAddAnotherLink: UILabel!
-
- private let appDelegate = UIApplication.shared.delegate as! AppDelegate
- public let width: CGFloat = 250
- public let height: CGFloat = 470
- public var tableShare: tableShare?
- public var metadata: tableMetadata?
- public var viewWindow: UIView?
-
- override func awakeFromNib() {
-
- self.frame.size.width = width
- self.frame.size.height = height
- layer.borderColor = UIColor.lightGray.cgColor
- layer.borderWidth = 0.5
- layer.cornerRadius = 5
- layer.masksToBounds = false
- layer.shadowOffset = CGSize(width: 2, height: 2)
- layer.shadowOpacity = 0.2
- layer.cornerRadius = 5
-
- switchAllowEditing.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
- switchHideDownload.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
- switchPasswordProtect.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
- switchSetExpirationDate.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
-
- imageNoteToRecipient.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "file_txt"), width: 100, height: 100, color: UIColor.black)
- buttonDeleteShareLink.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 100, height: 100, color: UIColor.black), for: .normal)
- buttonAddAnotherLink.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "add"), width: 100, height: 100, color: UIColor.black), for: .normal)
- }
-
- func addTap(view: UIView) {
- self.viewWindow = view
-
- let tap = UITapGestureRecognizer(target: self, action: #selector(tapHandler))
- tap.delegate = self
- viewWindow?.addGestureRecognizer(tap)
- }
-
- @objc func tapHandler(gesture: UITapGestureRecognizer) {
- viewWindow?.removeFromSuperview()
- }
-
- func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
- return gestureRecognizer.view == touch.view
- }
-
- func loadData(_ tableShare: tableShare?) {
- self.tableShare = tableShare
-
- // Allow editing
- if tableShare != nil && tableShare!.permissions > 1 {
- switchAllowEditing.setOn(true, animated: false)
- } else {
- switchAllowEditing.setOn(false, animated: false)
- }
-
- // Hide download
- if tableShare != nil && tableShare!.hideDownload {
- switchHideDownload.setOn(true, animated: false)
- } else {
- switchHideDownload.setOn(false, animated: false)
- }
-
- // Password protect
- if tableShare != nil && tableShare!.shareWith.count > 0 {
- switchPasswordProtect.setOn(true, animated: false)
- fieldPasswordProtect.isEnabled = true
- fieldPasswordProtect.text = tableShare!.shareWith
- } else {
- switchPasswordProtect.setOn(false, animated: false)
- fieldPasswordProtect.isEnabled = false
- fieldPasswordProtect.text = ""
- }
-
- // Set expiration date
- if tableShare != nil && tableShare!.expirationDate != nil {
- switchSetExpirationDate.setOn(true, animated: false)
- switchSetExpirationDate.isEnabled = true
- let dateFormatter = DateFormatter()
- dateFormatter.formatterBehavior = .behavior10_4
- dateFormatter.dateStyle = .short
- fieldSetExpirationDate.text = dateFormatter.string(from: tableShare!.expirationDate! as Date)
- } else {
- switchSetExpirationDate.setOn(false, animated: false)
- switchSetExpirationDate.isEnabled = false
- fieldSetExpirationDate.text = ""
- }
-
- // Note to recipient
- if tableShare != nil {
- textViewNoteToRecipient.text = tableShare!.note
- } else {
- textViewNoteToRecipient.text = ""
- }
- }
- }
- // --------------------------------------------------------------------------------------------
- // ===== Common =====
- // --------------------------------------------------------------------------------------------
- class NCShareCommon: NSObject {
- @objc static let sharedInstance: NCShareCommon = {
- let instance = NCShareCommon()
- return instance
- }()
-
- func createLinkAvatar() -> UIImage? {
-
- let size: CGFloat = 200
-
- let bottomImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "circle"), width: size, height: size, color: NCBrandColor.sharedInstance.brand)
- let topImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: size, height: size, color: UIColor.white)
- UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, 0.0)
- bottomImage?.draw(in: CGRect(origin: CGPoint.zero, size: CGSize(width: size, height: size)))
- topImage?.draw(in: CGRect(origin: CGPoint(x: size/4, y: size/4), size: CGSize(width: size/2, height: size/2)))
- let image = UIGraphicsGetImageFromCurrentImageContext()
- UIGraphicsEndImageContext()
-
- return image
- }
-
- func openViewMenuShareLink(view: UIView, height: CGFloat, tableShare: tableShare?) {
-
- let globalPoint = view.superview?.convert(view.frame.origin, to: nil)
-
- let window = UIApplication.shared.keyWindow!
- let viewWindow = UIView(frame: window.bounds)
- window.addSubview(viewWindow)
-
- let shareLinkMenuView = Bundle.main.loadNibNamed("NCShareLinkMenuView", owner: self, options: nil)?.first as? NCShareLinkMenuView
- shareLinkMenuView?.addTap(view: viewWindow)
- shareLinkMenuView?.loadData(tableShare)
- let shareLinkMenuViewX = view.bounds.width - (shareLinkMenuView?.frame.width)! - 40 + globalPoint!.x
- var shareLinkMenuViewY = height + 10 + globalPoint!.y
- if (view.bounds.height - (height + 10)) < shareLinkMenuView!.height {
- shareLinkMenuViewY = shareLinkMenuViewY - height
- }
- shareLinkMenuView?.frame = CGRect(x: shareLinkMenuViewX, y: shareLinkMenuViewY, width: shareLinkMenuView!.width, height: shareLinkMenuView!.height)
- viewWindow.addSubview(shareLinkMenuView!)
- }
-
- func copyLink(tableShare: tableShare?, viewController: UIViewController) {
-
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- var url: String = ""
-
- guard let tableShare = tableShare else { return }
-
- if tableShare.token.hasPrefix("http://") || tableShare.token.hasPrefix("https://") {
- url = tableShare.token
- } else if tableShare.url != "" {
- url = tableShare.url
- } else {
- url = appDelegate.activeUrl + "/" + k_share_link_middle_part_url_after_version_8 + tableShare.token
- }
-
- if let name = URL(string: url), !name.absoluteString.isEmpty {
- let objectsToShare = [name]
-
- let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
- viewController.present(activityVC, animated: true, completion: nil)
- }
- }
- }
- // --------------------------------------------------------------------------------------------
- // ===== Networking =====
- // --------------------------------------------------------------------------------------------
- class NCShareNetworking: NSObject {
- private let appDelegate = UIApplication.shared.delegate as! AppDelegate
-
- var delegate: NCShareNetworkingDelegate?
- var view: UIView?
-
- init(view: UIView?, delegate: NCShareNetworkingDelegate?) {
- self.view = view
- self.delegate = delegate
-
- super.init()
- }
-
- func readShare(account: String, activeUrl: String) {
- NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
- OCNetworking.sharedManager()?.readShare(withAccount: account, completion: { (account, items, message, errorCode) in
- NCUtility.sharedInstance.stopActivityIndicator()
- if errorCode == 0 {
- let itemsOCSharedDto = items as! [OCSharedDto]
- NCManageDatabase.sharedInstance.addShare(account: account!, activeUrl: activeUrl, items: itemsOCSharedDto)
- } else {
- self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
- }
- self.delegate?.readShareCompleted(account: account!, errorCode: errorCode)
- })
- }
-
- func share(metadata: tableMetadata, activeUrl: String, password: String, permission: Int, hideDownload: Bool) {
- NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
- let fileName = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: activeUrl)!
- OCNetworking.sharedManager()?.share(withAccount: metadata.account, fileName: fileName, password: password, permission: permission, hideDownload: hideDownload, completion: { (account, message, errorCode) in
- NCUtility.sharedInstance.stopActivityIndicator()
- if errorCode == 0 {
- } else {
- self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
- }
- self.delegate?.shareCompleted(metadata: metadata, errorCode: errorCode)
- })
- }
-
- func unShare(account: String, idRemoteShared: Int) {
- NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
- OCNetworking.sharedManager()?.unshareAccount(account, shareID: idRemoteShared, completion: { (account, message, errorCode) in
- NCUtility.sharedInstance.stopActivityIndicator()
- if errorCode == 0 {
-
- } else {
- self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
- }
- self.delegate?.unShareCompleted(account: account!, idRemoteShared: idRemoteShared, errorCode: errorCode)
- })
- }
-
- func updateShare(account: String, idRemoteShared: Int, password: String?, permission: Int, expirationTime: String?, hideDownload: Bool) {
- NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
- OCNetworking.sharedManager()?.shareUpdateAccount(account, shareID: idRemoteShared, password: password, permission: permission, expirationTime: expirationTime, hideDownload: hideDownload, completion: { (account, message, errorCode) in
- NCUtility.sharedInstance.stopActivityIndicator()
- if errorCode == 0 {
-
- } else {
- self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
- }
- self.delegate?.updateShareCompleted(account: account!, idRemoteShared: idRemoteShared, errorCode: errorCode)
- })
- }
- }
- protocol NCShareNetworkingDelegate {
- func readShareCompleted(account: String, errorCode: Int)
- func shareCompleted(metadata: tableMetadata, errorCode: Int)
- func unShareCompleted(account: String, idRemoteShared: Int, errorCode: Int)
- func updateShareCompleted(account: String, idRemoteShared: Int, errorCode: Int)
- }
|