|
@@ -23,211 +23,6 @@
|
|
|
|
|
|
import Foundation
|
|
|
import Parchment
|
|
|
-import FSCalendar
|
|
|
-
|
|
|
-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, NCShareUserCellDelegate, NCShareNetworkingDelegate {
|
|
|
|
|
@@ -245,7 +40,8 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
|
|
|
var metadata: tableMetadata?
|
|
|
public var height: CGFloat = 0
|
|
|
private var shareLinkMenuView: NCShareLinkMenuView?
|
|
|
- private var shareLinkMenuViewWindow: UIView?
|
|
|
+ private var shareUserMenuView: NCShareUserMenuView?
|
|
|
+ private var shareMenuViewWindow: UIView?
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
@@ -277,6 +73,8 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
|
|
|
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
|
|
shareLinkMenuView?.unLoad()
|
|
|
shareLinkMenuView = nil
|
|
|
+ shareUserMenuView?.unLoad()
|
|
|
+ shareUserMenuView = nil
|
|
|
}
|
|
|
|
|
|
@IBAction func touchUpInsideButtonCopy(_ sender: Any) {
|
|
@@ -297,6 +95,8 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
|
|
|
@objc func tapLinkMenuViewWindow(gesture: UITapGestureRecognizer) {
|
|
|
shareLinkMenuView?.unLoad()
|
|
|
shareLinkMenuView = nil
|
|
|
+ shareUserMenuView?.unLoad()
|
|
|
+ shareUserMenuView = nil
|
|
|
}
|
|
|
|
|
|
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
|
|
@@ -312,13 +112,25 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
|
|
|
}
|
|
|
|
|
|
func tapMenu(with tableShare: tableShare?, sender: Any) {
|
|
|
- let views = NCShareCommon.sharedInstance.openViewMenuShareLink(view: self.view, tableShare: tableShare, metadata: metadata!)
|
|
|
- shareLinkMenuView = views.shareLinkMenuView
|
|
|
- shareLinkMenuViewWindow = views.viewWindow
|
|
|
-
|
|
|
- let tap = UITapGestureRecognizer(target: self, action: #selector(tapLinkMenuViewWindow))
|
|
|
- tap.delegate = self
|
|
|
- shareLinkMenuViewWindow?.addGestureRecognizer(tap)
|
|
|
+ guard let tableShare = tableShare else { return }
|
|
|
+
|
|
|
+ if tableShare.shareType == Int(shareTypeLink.rawValue) {
|
|
|
+ let views = NCShareCommon.sharedInstance.openViewMenuShareLink(view: self.view, tableShare: tableShare, metadata: metadata!)
|
|
|
+ shareLinkMenuView = views.shareLinkMenuView
|
|
|
+ shareMenuViewWindow = views.viewWindow
|
|
|
+
|
|
|
+ let tap = UITapGestureRecognizer(target: self, action: #selector(tapLinkMenuViewWindow))
|
|
|
+ tap.delegate = self
|
|
|
+ shareMenuViewWindow?.addGestureRecognizer(tap)
|
|
|
+ } else {
|
|
|
+ let views = NCShareCommon.sharedInstance.openViewMenuUser(view: self.view, tableShare: tableShare, metadata: metadata!)
|
|
|
+ shareUserMenuView = views.shareUserMenuView
|
|
|
+ shareMenuViewWindow = views.viewWindow
|
|
|
+
|
|
|
+ let tap = UITapGestureRecognizer(target: self, action: #selector(tapLinkMenuViewWindow))
|
|
|
+ tap.delegate = self
|
|
|
+ shareMenuViewWindow?.addGestureRecognizer(tap)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@objc func reloadData() {
|
|
@@ -389,7 +201,6 @@ extension NCShare: UITableViewDataSource {
|
|
|
cell.delegate = self
|
|
|
cell.labelTitle.text = tableShare.shareWith
|
|
|
NCShareCommon.sharedInstance.downloadAvatar(user: tableShare.shareWith, cell: cell)
|
|
|
-
|
|
|
if UtilsFramework.isAnyPermission(toEdit: tableShare.permissions) {
|
|
|
cell.switchCanEdit.setOn(true, animated: false)
|
|
|
} else {
|
|
@@ -469,504 +280,3 @@ protocol NCShareUserCellDelegate {
|
|
|
func switchCanEdit(with tableShare: tableShare?, switch: Bool, sender: Any)
|
|
|
}
|
|
|
|
|
|
-// MARK: - ShareLinkMenuView
|
|
|
-
|
|
|
-class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkingDelegate, FSCalendarDelegate, FSCalendarDelegateAppearance {
|
|
|
-
|
|
|
- @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 fieldNoteToRecipient: UITextField!
|
|
|
-
|
|
|
- @IBOutlet weak var buttonDeleteShareLink: UIButton!
|
|
|
- @IBOutlet weak var labelDeleteShareLink: UILabel!
|
|
|
- @IBOutlet weak var imageDeleteShareLink: UIImageView!
|
|
|
-
|
|
|
- @IBOutlet weak var buttonAddAnotherLink: UIButton!
|
|
|
- @IBOutlet weak var labelAddAnotherLink: UILabel!
|
|
|
- @IBOutlet weak var imageAddAnotherLink: UIImageView!
|
|
|
-
|
|
|
- private let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
-
|
|
|
- public let width: CGFloat = 250
|
|
|
- public let height: CGFloat = 440
|
|
|
- private var tableShare: tableShare?
|
|
|
- public var metadata: tableMetadata?
|
|
|
-
|
|
|
- public var viewWindow: UIView?
|
|
|
- public var viewWindowCalendar: 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
|
|
|
-
|
|
|
- switchAllowEditing.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
|
|
|
- switchAllowEditing.onTintColor = NCBrandColor.sharedInstance.brand
|
|
|
- switchHideDownload.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
|
|
|
- switchHideDownload.onTintColor = NCBrandColor.sharedInstance.brand
|
|
|
- switchPasswordProtect.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
|
|
|
- switchPasswordProtect.onTintColor = NCBrandColor.sharedInstance.brand
|
|
|
- switchSetExpirationDate.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
|
|
|
- switchSetExpirationDate.onTintColor = NCBrandColor.sharedInstance.brand
|
|
|
-
|
|
|
- fieldSetExpirationDate.inputView = UIView()
|
|
|
-
|
|
|
- imageNoteToRecipient.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "file_txt"), width: 100, height: 100, color: UIColor(red: 76/255, green: 76/255, blue: 76/255, alpha: 1))
|
|
|
- imageDeleteShareLink.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 100, height: 100, color: UIColor(red: 76/255, green: 76/255, blue: 76/255, alpha: 1))
|
|
|
- imageAddAnotherLink.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "add"), width: 100, height: 100, color: UIColor(red: 76/255, green: 76/255, blue: 76/255, alpha: 1))
|
|
|
- }
|
|
|
-
|
|
|
- func unLoad() {
|
|
|
- viewWindowCalendar?.removeFromSuperview()
|
|
|
- viewWindow?.removeFromSuperview()
|
|
|
-
|
|
|
- viewWindowCalendar = nil
|
|
|
- viewWindow = nil
|
|
|
- }
|
|
|
-
|
|
|
- func reloadData(idRemoteShared: Int) {
|
|
|
- tableShare = NCManageDatabase.sharedInstance.getTableShare(account: metadata!.account, idRemoteShared: idRemoteShared)
|
|
|
-
|
|
|
- // Allow editing
|
|
|
- if tableShare != nil && tableShare!.permissions > Int(k_read_share_permission) {
|
|
|
- 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)
|
|
|
- fieldSetExpirationDate.isEnabled = true
|
|
|
-
|
|
|
- let dateFormatter = DateFormatter()
|
|
|
- dateFormatter.formatterBehavior = .behavior10_4
|
|
|
- dateFormatter.dateStyle = .medium
|
|
|
- fieldSetExpirationDate.text = dateFormatter.string(from: tableShare!.expirationDate! as Date)
|
|
|
- } else {
|
|
|
- switchSetExpirationDate.setOn(false, animated: false)
|
|
|
- fieldSetExpirationDate.isEnabled = false
|
|
|
- fieldSetExpirationDate.text = ""
|
|
|
- }
|
|
|
-
|
|
|
- // Note to recipient
|
|
|
- if tableShare != nil {
|
|
|
- fieldNoteToRecipient.text = tableShare!.note
|
|
|
- } else {
|
|
|
- fieldNoteToRecipient.text = ""
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Allow editing
|
|
|
- @IBAction func switchAllowEditingChanged(sender: UISwitch) {
|
|
|
-
|
|
|
- guard let tableShare = self.tableShare else { return }
|
|
|
-
|
|
|
- var permission = 0
|
|
|
- if sender.isOn {
|
|
|
- permission = Int(k_read_share_permission) + Int(k_update_share_permission)
|
|
|
- } else {
|
|
|
- permission = Int(k_read_share_permission)
|
|
|
- }
|
|
|
-
|
|
|
- let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl, view: self, delegate: self)
|
|
|
- networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: nil, permission: permission, note: nil, expirationTime: nil, hideDownload: tableShare.hideDownload)
|
|
|
- }
|
|
|
-
|
|
|
- // Hide download
|
|
|
- @IBAction func switchHideDownloadChanged(sender: UISwitch) {
|
|
|
-
|
|
|
- guard let tableShare = self.tableShare else { return }
|
|
|
-
|
|
|
- let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl, view: self, delegate: self)
|
|
|
- networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: nil, permission: 0, note: nil, expirationTime: nil, hideDownload: sender.isOn)
|
|
|
- }
|
|
|
-
|
|
|
- // Password protect
|
|
|
- @IBAction func switchPasswordProtectChanged(sender: UISwitch) {
|
|
|
-
|
|
|
- guard let tableShare = self.tableShare else { return }
|
|
|
-
|
|
|
- if sender.isOn {
|
|
|
- fieldPasswordProtect.isEnabled = true
|
|
|
- fieldPasswordProtect.text = ""
|
|
|
- fieldPasswordProtect.becomeFirstResponder()
|
|
|
- } else {
|
|
|
- let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl, view: self, delegate: self)
|
|
|
- networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: "", permission: 0, note: nil, expirationTime: nil, hideDownload: tableShare.hideDownload)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @IBAction func fieldPasswordProtectDidEndOnExit(textField: UITextField) {
|
|
|
-
|
|
|
- guard let tableShare = self.tableShare else { return }
|
|
|
-
|
|
|
- let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl, view: self, delegate: self)
|
|
|
- networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: fieldPasswordProtect.text, permission: 0, note: nil, expirationTime: nil, hideDownload: tableShare.hideDownload)
|
|
|
- }
|
|
|
-
|
|
|
- // Set expiration date
|
|
|
- @IBAction func switchSetExpirationDate(sender: UISwitch) {
|
|
|
-
|
|
|
- guard let tableShare = self.tableShare else { return }
|
|
|
-
|
|
|
- if sender.isOn {
|
|
|
- fieldSetExpirationDate.isEnabled = true
|
|
|
- fieldSetExpirationDate(sender: fieldSetExpirationDate)
|
|
|
- } else {
|
|
|
- let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl, view: self, delegate: self)
|
|
|
- networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: nil, permission: 0, note: nil, expirationTime: "", hideDownload: tableShare.hideDownload)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @IBAction func fieldSetExpirationDate(sender: UITextField) {
|
|
|
-
|
|
|
- let calendar = NCShareCommon.sharedInstance.openCalendar(view: self, width: width, height: height)
|
|
|
- calendar.calendarView.delegate = self
|
|
|
- viewWindowCalendar = calendar.viewWindow
|
|
|
- }
|
|
|
-
|
|
|
- // Note to recipient
|
|
|
- @IBAction func fieldNoteToRecipientDidEndOnExit(textField: UITextField) {
|
|
|
-
|
|
|
- guard let tableShare = self.tableShare else { return }
|
|
|
- if fieldNoteToRecipient.text == nil { return }
|
|
|
-
|
|
|
- let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl, view: self, delegate: self)
|
|
|
- networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: nil, permission: 0, note: fieldNoteToRecipient.text, expirationTime: nil, hideDownload: tableShare.hideDownload)
|
|
|
- }
|
|
|
-
|
|
|
- // Delete share link
|
|
|
- @IBAction func buttonDeleteShareLink(sender: UIButton) {
|
|
|
-
|
|
|
- guard let tableShare = self.tableShare else { return }
|
|
|
- let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl, view: self, delegate: self)
|
|
|
-
|
|
|
- networking.unShare(idRemoteShared: tableShare.idRemoteShared)
|
|
|
- }
|
|
|
-
|
|
|
- // Add another link
|
|
|
- @IBAction func buttonAddAnotherLink(sender: UIButton) {
|
|
|
-
|
|
|
- let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl, view: self, delegate: self)
|
|
|
-
|
|
|
- networking.share(metadata: metadata!, password: "", permission: 1, hideDownload: false)
|
|
|
- }
|
|
|
-
|
|
|
- // delegate networking
|
|
|
-
|
|
|
- func readShareCompleted(errorCode: Int) {
|
|
|
- reloadData(idRemoteShared: tableShare?.idRemoteShared ?? 0)
|
|
|
- }
|
|
|
-
|
|
|
- func shareCompleted(errorCode: Int) {
|
|
|
- unLoad()
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadDataNCShare"), object: nil, userInfo: nil)
|
|
|
- }
|
|
|
-
|
|
|
- func unShareCompleted() {
|
|
|
- unLoad()
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadDataNCShare"), object: nil, userInfo: nil)
|
|
|
- }
|
|
|
-
|
|
|
- func updateShareWithError(idRemoteShared: Int) {
|
|
|
- reloadData(idRemoteShared: idRemoteShared)
|
|
|
- }
|
|
|
-
|
|
|
- // delegate/appearance calendar
|
|
|
- func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
|
|
|
-
|
|
|
- if monthPosition == .previous || monthPosition == .next {
|
|
|
- calendar.setCurrentPage(date, animated: true)
|
|
|
- } else {
|
|
|
- let dateFormatter = DateFormatter()
|
|
|
- dateFormatter.formatterBehavior = .behavior10_4
|
|
|
- dateFormatter.dateStyle = .medium
|
|
|
- fieldSetExpirationDate.text = dateFormatter.string(from:date)
|
|
|
- fieldSetExpirationDate.endEditing(true)
|
|
|
-
|
|
|
- viewWindowCalendar?.removeFromSuperview()
|
|
|
-
|
|
|
- guard let tableShare = self.tableShare else { return }
|
|
|
-
|
|
|
- let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl, view: self, delegate: self)
|
|
|
- dateFormatter.dateFormat = "YYYY-MM-dd"
|
|
|
- let expirationTime = dateFormatter.string(from: date)
|
|
|
- networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: nil, permission: 0, note: nil, expirationTime: expirationTime, hideDownload: tableShare.hideDownload)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool {
|
|
|
- return date > Date()
|
|
|
- }
|
|
|
-
|
|
|
- func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, titleDefaultColorFor date: Date) -> UIColor? {
|
|
|
- if date > Date() {
|
|
|
- return UIColor(red: 60/255, green: 60/255, blue: 60/255, alpha: 1)
|
|
|
- } else {
|
|
|
- return UIColor(red: 190/255, green: 190/255, blue: 190/255, alpha: 1)
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// --------------------------------------------------------------------------------------------
|
|
|
-// ===== 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 downloadAvatar(user: String, cell: NCShareUserCell) {
|
|
|
-
|
|
|
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
- let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + user + ".png"
|
|
|
-
|
|
|
- if FileManager.default.fileExists(atPath: fileNameLocalPath) {
|
|
|
- if let image = UIImage(contentsOfFile: fileNameLocalPath) {
|
|
|
- cell.imageItem.image = image
|
|
|
- }
|
|
|
- } else {
|
|
|
- DispatchQueue.global().async {
|
|
|
- let url = appDelegate.activeUrl + k_avatar + user + "/128"
|
|
|
- let encodedString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
|
|
|
- OCNetworking.sharedManager()?.downloadContents(ofUrl: encodedString, completion: { (data, message, errorCode) in
|
|
|
- if errorCode == 0 {
|
|
|
- do {
|
|
|
- try data!.write(to: NSURL(fileURLWithPath: fileNameLocalPath) as URL, options: .atomic)
|
|
|
- } catch { return }
|
|
|
- cell.imageItem.image = UIImage(data: data!)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func openViewMenuShareLink(view: UIView, tableShare: tableShare?, metadata: tableMetadata) -> (shareLinkMenuView: NCShareLinkMenuView, viewWindow: UIView) {
|
|
|
-
|
|
|
- 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.metadata = metadata
|
|
|
- shareLinkMenuView.viewWindow = viewWindow
|
|
|
- shareLinkMenuView.reloadData(idRemoteShared: tableShare?.idRemoteShared ?? 0)
|
|
|
- let shareLinkMenuViewX = view.bounds.width/2 - shareLinkMenuView.frame.width/2 + globalPoint!.x
|
|
|
- let shareLinkMenuViewY = globalPoint!.y + 10
|
|
|
-
|
|
|
- shareLinkMenuView.frame = CGRect(x: shareLinkMenuViewX, y: shareLinkMenuViewY, width: shareLinkMenuView.width, height: shareLinkMenuView.height)
|
|
|
- viewWindow.addSubview(shareLinkMenuView)
|
|
|
-
|
|
|
- return(shareLinkMenuView: shareLinkMenuView, viewWindow: viewWindow)
|
|
|
- }
|
|
|
-
|
|
|
- func openCalendar(view: UIView, width: CGFloat, height: CGFloat) -> (calendarView: FSCalendar, viewWindow: UIView) {
|
|
|
-
|
|
|
- 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 calendar = FSCalendar(frame: CGRect(x: globalPoint!.x + 10, y: globalPoint!.y + 100, width: width - 20, height: 300))
|
|
|
-
|
|
|
- calendar.backgroundColor = .white
|
|
|
- calendar.placeholderType = .none
|
|
|
- calendar.appearance.headerMinimumDissolvedAlpha = 0.0
|
|
|
-
|
|
|
- calendar.layer.borderColor = UIColor.lightGray.cgColor
|
|
|
- calendar.layer.borderWidth = 0.5
|
|
|
- calendar.layer.masksToBounds = false
|
|
|
- calendar.layer.cornerRadius = 5
|
|
|
- calendar.layer.masksToBounds = false
|
|
|
- calendar.layer.shadowOffset = CGSize(width: 2, height: 2)
|
|
|
- calendar.layer.shadowOpacity = 0.2
|
|
|
-
|
|
|
- calendar.appearance.headerTitleColor = .black
|
|
|
- calendar.appearance.headerTitleFont = UIFont.systemFont(ofSize: 13)
|
|
|
-
|
|
|
- calendar.appearance.weekdayTextColor = UIColor(red: 100/255, green: 100/255, blue: 100/255, alpha: 1)
|
|
|
- calendar.appearance.weekdayFont = UIFont.systemFont(ofSize: 12)
|
|
|
-
|
|
|
- calendar.appearance.todayColor = NCBrandColor.sharedInstance.brand
|
|
|
- calendar.appearance.titleFont = UIFont.systemFont(ofSize: 12)
|
|
|
-
|
|
|
- viewWindow.addSubview(calendar)
|
|
|
-
|
|
|
- return(calendarView: calendar, viewWindow: viewWindow)
|
|
|
- }
|
|
|
-
|
|
|
- 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 account: String
|
|
|
- var activeUrl: String
|
|
|
- var delegate: NCShareNetworkingDelegate?
|
|
|
- var view: UIView?
|
|
|
-
|
|
|
- init(account: String, activeUrl: String, view: UIView?, delegate: NCShareNetworkingDelegate?) {
|
|
|
- self.account = account
|
|
|
- self.activeUrl = activeUrl
|
|
|
- self.view = view
|
|
|
- self.delegate = delegate
|
|
|
-
|
|
|
- super.init()
|
|
|
- }
|
|
|
-
|
|
|
- func readShare() {
|
|
|
- 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: self.account, activeUrl: self.activeUrl, items: itemsOCSharedDto)
|
|
|
- } else {
|
|
|
- self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
- self.delegate?.readShareCompleted(errorCode: errorCode)
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- func share(metadata: tableMetadata, 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
|
|
|
- if errorCode == 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: self.account, activeUrl: self.activeUrl, items: itemsOCSharedDto)
|
|
|
- } else {
|
|
|
- self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
- self.delegate?.shareCompleted(errorCode: errorCode)
|
|
|
- })
|
|
|
- } else {
|
|
|
- NCUtility.sharedInstance.stopActivityIndicator()
|
|
|
- self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- func unShare(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 {
|
|
|
- NCManageDatabase.sharedInstance.deleteTableShare(account: account!, idRemoteShared: idRemoteShared)
|
|
|
- self.delegate?.unShareCompleted()
|
|
|
- } else {
|
|
|
- self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- func updateShare(idRemoteShared: Int, password: String?, permission: Int, note: String?, expirationTime: String?, hideDownload: Bool) {
|
|
|
- NCUtility.sharedInstance.startActivityIndicator(view: view, bottom: 0)
|
|
|
- OCNetworking.sharedManager()?.shareUpdateAccount(account, shareID: idRemoteShared, password: password, note:note, permission: permission, expirationTime: expirationTime, hideDownload: hideDownload, completion: { (account, message, errorCode) in
|
|
|
- NCUtility.sharedInstance.stopActivityIndicator()
|
|
|
- if errorCode == 0 {
|
|
|
- self.readShare()
|
|
|
- } else {
|
|
|
- self.appDelegate.messageNotification("_share_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- self.delegate?.updateShareWithError(idRemoteShared: idRemoteShared)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-protocol NCShareNetworkingDelegate {
|
|
|
- func readShareCompleted(errorCode: Int)
|
|
|
- func shareCompleted(errorCode: Int)
|
|
|
- func unShareCompleted()
|
|
|
- func updateShareWithError(idRemoteShared: Int)
|
|
|
-}
|