NCShare.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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 UIKit
  24. import Parchment
  25. import DropDown
  26. import NCCommunication
  27. import MarqueeLabel
  28. class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDelegate, NCShareUserCellDelegate, NCShareNetworkingDelegate {
  29. @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint!
  30. @IBOutlet weak var sharedWithYouByView: UIView!
  31. @IBOutlet weak var sharedWithYouByImage: UIImageView!
  32. @IBOutlet weak var sharedWithYouByLabel: UILabel!
  33. @IBOutlet weak var sharedWithYouByNoteImage: UIImageView!
  34. @IBOutlet weak var sharedWithYouByNote: MarqueeLabel!
  35. @IBOutlet weak var searchFieldTopConstraint: NSLayoutConstraint!
  36. @IBOutlet weak var searchField: UITextField!
  37. @IBOutlet weak var shareLinkImage: UIImageView!
  38. @IBOutlet weak var shareLinkLabel: UILabel!
  39. @IBOutlet weak var shareInternalLinkImage: UIImageView!
  40. @IBOutlet weak var shareInternalLinkLabel: UILabel!
  41. @IBOutlet weak var shareInternalLinkDescription: UILabel!
  42. @IBOutlet weak var buttonInternalCopy: UIButton!
  43. @IBOutlet weak var buttonCopy: UIButton!
  44. @IBOutlet weak var buttonMenu: UIButton!
  45. @IBOutlet weak var tableView: UITableView!
  46. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  47. public var metadata: tableMetadata?
  48. public var sharingEnabled = true
  49. public var height: CGFloat = 0
  50. private var shareLinkMenuView: NCShareLinkMenuView?
  51. private var shareUserMenuView: NCShareUserMenuView?
  52. private var shareMenuViewWindow: UIView?
  53. private var dropDown = DropDown()
  54. private var networking: NCShareNetworking?
  55. // MARK: - View Life Cycle
  56. override func viewDidLoad() {
  57. super.viewDidLoad()
  58. view.backgroundColor = NCBrandColor.shared.systemBackground
  59. viewContainerConstraint.constant = height
  60. searchFieldTopConstraint.constant = 10
  61. searchField.placeholder = NSLocalizedString("_shareLinksearch_placeholder_", comment: "")
  62. shareLinkImage.image = NCShareCommon.shared.createLinkAvatar(imageName: "sharebylink", colorCircle: NCBrandColor.shared.brandElement)
  63. shareLinkLabel.text = NSLocalizedString("_share_link_", comment: "")
  64. shareLinkLabel.textColor = NCBrandColor.shared.label
  65. buttonCopy.setImage(UIImage.init(named: "shareCopy")?.image(color: .gray, size: 50), for: .normal)
  66. shareInternalLinkImage.image = NCShareCommon.shared.createLinkAvatar(imageName: "shareInternalLink", colorCircle: .gray)
  67. shareInternalLinkLabel.text = NSLocalizedString("_share_internal_link_", comment: "")
  68. shareInternalLinkDescription.text = NSLocalizedString("_share_internal_link_des_", comment: "")
  69. buttonInternalCopy.setImage(UIImage.init(named: "shareCopy")?.image(color: .gray, size: 50), for: .normal)
  70. tableView.dataSource = self
  71. tableView.delegate = self
  72. tableView.allowsSelection = false
  73. tableView.backgroundColor = NCBrandColor.shared.systemBackground
  74. tableView.register(UINib.init(nibName: "NCShareLinkCell", bundle: nil), forCellReuseIdentifier: "cellLink")
  75. tableView.register(UINib.init(nibName: "NCShareUserCell", bundle: nil), forCellReuseIdentifier: "cellUser")
  76. NotificationCenter.default.addObserver(self, selector: #selector(reloadData), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterReloadDataNCShare), object: nil)
  77. // Shared with you by ...
  78. if metadata!.ownerId != "" && metadata!.ownerId != self.appDelegate.userId {
  79. searchFieldTopConstraint.constant = 65
  80. sharedWithYouByView.isHidden = false
  81. //TODO: implement open profile dialoge
  82. sharedWithYouByLabel.text = NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata!.ownerDisplayName
  83. sharedWithYouByImage.image = UIImage(named: "avatar")?.imageColor(NCBrandColor.shared.label)
  84. let shareAction = UITapGestureRecognizer(target: self, action: #selector(openShareProfile))
  85. sharedWithYouByView.addGestureRecognizer(shareAction)
  86. if metadata?.note.count ?? 0 > 0 {
  87. searchFieldTopConstraint.constant = 95
  88. sharedWithYouByNoteImage.isHidden = false
  89. sharedWithYouByNoteImage.image = NCUtility.shared.loadImage(named: "note.text", color: .gray)
  90. sharedWithYouByNote.isHidden = false
  91. sharedWithYouByNote.text = metadata?.note
  92. sharedWithYouByNote.textColor = NCBrandColor.shared.label
  93. sharedWithYouByNote.trailingBuffer = sharedWithYouByNote.frame.width
  94. } else {
  95. sharedWithYouByNoteImage.isHidden = true
  96. sharedWithYouByNote.isHidden = true
  97. }
  98. let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + metadata!.ownerId + ".png"
  99. if let image = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) {
  100. sharedWithYouByImage.image = image
  101. } else {
  102. let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
  103. let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
  104. NCCommunication.shared.downloadAvatar(user: metadata!.ownerId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag) { (account, imageAvatar, imageOriginal, etag, errorCode, errorMessage) in
  105. if errorCode == 0, let etag = etag, let imageAvatar = imageAvatar {
  106. NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
  107. self.sharedWithYouByImage.image = imageAvatar
  108. } else if errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = NCManageDatabase.shared.setAvatarLoaded(fileName: fileName) {
  109. self.sharedWithYouByImage.image = imageAvatar
  110. }
  111. }
  112. }
  113. }
  114. reloadData()
  115. networking = NCShareNetworking.init(metadata: metadata!, urlBase: appDelegate.urlBase, view: self.view, delegate: self)
  116. if sharingEnabled {
  117. networking?.readShare()
  118. }
  119. // changeTheming
  120. NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
  121. NotificationCenter.default.addObserver(self, selector: #selector(changePermissions(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShareChangePermissions), object: nil)
  122. changeTheming()
  123. }
  124. // MARK: - Notification Center
  125. @objc func openShareProfile() {
  126. print("Show share profile")
  127. }
  128. @objc func changeTheming() {
  129. tableView.reloadData()
  130. }
  131. @objc func changePermissions(_ notification: NSNotification) {
  132. if let userInfo = notification.userInfo as NSDictionary? {
  133. if let idShare = userInfo["idShare"] as? Int, let permissions = userInfo["permissions"] as? Int, let hideDownload = userInfo["hideDownload"] as? Bool {
  134. networking?.updateShare(idShare: idShare, password: nil, permissions: permissions, note: nil, label: nil, expirationDate: nil, hideDownload: hideDownload)
  135. }
  136. }
  137. }
  138. // MARK: -
  139. @objc func reloadData() {
  140. let shares = NCManageDatabase.shared.getTableShares(metadata: metadata!)
  141. if shares.firstShareLink == nil {
  142. buttonMenu.setImage(UIImage.init(named: "shareAdd")?.image(color: .gray, size: 50), for: .normal)
  143. buttonCopy.isHidden = true
  144. } else {
  145. buttonMenu.setImage(UIImage.init(named: "shareMenu")?.image(color: .gray, size: 50), for: .normal)
  146. buttonCopy.isHidden = false
  147. shareLinkLabel.text = NSLocalizedString("_share_link_", comment: "")
  148. if shares.firstShareLink?.label.count ?? 0 > 0 {
  149. if let shareLinkLabel = shareLinkLabel {
  150. if let label = shares.firstShareLink?.label {
  151. shareLinkLabel.text = NSLocalizedString("_share_link_", comment: "") + " (" + label + ")"
  152. }
  153. }
  154. }
  155. }
  156. tableView.reloadData()
  157. }
  158. // MARK: - IBAction
  159. @IBAction func searchFieldDidEndOnExit(textField: UITextField) {
  160. guard let searchString = textField.text else { return }
  161. networking?.getSharees(searchString: searchString)
  162. }
  163. @IBAction func touchUpInsideButtonCopy(_ sender: Any) {
  164. guard let metadata = self.metadata else { return }
  165. let shares = NCManageDatabase.shared.getTableShares(metadata: metadata)
  166. tapCopy(with: shares.firstShareLink, sender: sender)
  167. }
  168. @IBAction func touchUpInsideButtonCopyInernalLink(_ sender: Any) {
  169. guard let metadata = self.metadata else { return }
  170. let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
  171. NCNetworking.shared.readFile(serverUrlFileName: serverUrlFileName, account: metadata.account) { (account, metadata, errorCode, errorDescription) in
  172. if errorCode == 0 && metadata != nil {
  173. let internalLink = self.appDelegate.urlBase + "/index.php/f/" + metadata!.fileId
  174. NCShareCommon.shared.copyLink(link: internalLink, viewController: self, sender: sender)
  175. } else {
  176. NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
  177. }
  178. }
  179. }
  180. @IBAction func touchUpInsideButtonMenu(_ sender: Any) {
  181. guard let metadata = self.metadata else { return }
  182. let isFilesSharingPublicPasswordEnforced = NCManageDatabase.shared.getCapabilitiesServerBool(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesFileSharingPubPasswdEnforced, exists: false)
  183. let shares = NCManageDatabase.shared.getTableShares(metadata: metadata)
  184. if isFilesSharingPublicPasswordEnforced && shares.firstShareLink == nil {
  185. let alertController = UIAlertController(title: NSLocalizedString("_enforce_password_protection_", comment: ""), message: "", preferredStyle: .alert)
  186. alertController.addTextField { (textField) in
  187. textField.isSecureTextEntry = true
  188. }
  189. alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default) { (action:UIAlertAction) in })
  190. let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { (action:UIAlertAction) in
  191. let password = alertController.textFields?.first?.text
  192. self.networking?.createShareLink(password: password ?? "")
  193. }
  194. alertController.addAction(okAction)
  195. self.present(alertController, animated: true, completion:nil)
  196. } else if shares.firstShareLink == nil {
  197. networking?.createShareLink(password: "")
  198. } else {
  199. tapMenu(with: shares.firstShareLink!, sender: sender)
  200. }
  201. }
  202. @objc func tapLinkMenuViewWindow(gesture: UITapGestureRecognizer) {
  203. shareLinkMenuView?.unLoad()
  204. shareLinkMenuView = nil
  205. shareUserMenuView?.unLoad()
  206. shareUserMenuView = nil
  207. }
  208. func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
  209. return gestureRecognizer.view == touch.view
  210. }
  211. func tapCopy(with tableShare: tableShare?, sender: Any) {
  212. if let link = tableShare?.url {
  213. NCShareCommon.shared.copyLink(link: link, viewController: self, sender: sender)
  214. }
  215. }
  216. func tapMenu(with tableShare: tableShare?, sender: Any) {
  217. guard let tableShare = tableShare else { return }
  218. if tableShare.shareType == 3 {
  219. let views = NCShareCommon.shared.openViewMenuShareLink(shareViewController: self, tableShare: tableShare, metadata: metadata!)
  220. shareLinkMenuView = views.shareLinkMenuView
  221. shareMenuViewWindow = views.viewWindow
  222. let tap = UITapGestureRecognizer(target: self, action: #selector(tapLinkMenuViewWindow))
  223. tap.delegate = self
  224. shareMenuViewWindow?.addGestureRecognizer(tap)
  225. } else {
  226. let views = NCShareCommon.shared.openViewMenuUser(shareViewController: self, tableShare: tableShare, metadata: metadata!)
  227. shareUserMenuView = views.shareUserMenuView
  228. shareMenuViewWindow = views.viewWindow
  229. let tap = UITapGestureRecognizer(target: self, action: #selector(tapLinkMenuViewWindow))
  230. tap.delegate = self
  231. shareMenuViewWindow?.addGestureRecognizer(tap)
  232. }
  233. }
  234. func quickStatus(with tableShare: tableShare?, sender: Any) {
  235. guard let tableShare = tableShare else { return }
  236. if tableShare.shareType != NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption {
  237. //self.quickStatusTableShare = tableShare
  238. let quickStatusMenu = NCShareQuickStatusMenu()
  239. quickStatusMenu.toggleMenu(viewController: self, directory: metadata!.directory, tableShare: tableShare)
  240. }
  241. }
  242. // MARK: - NCShareNetworkingDelegate
  243. func readShareCompleted() {
  244. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataNCShare)
  245. }
  246. func shareCompleted() {
  247. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataNCShare)
  248. }
  249. func unShareCompleted() { }
  250. func updateShareWithError(idShare: Int) {
  251. self.reloadData()
  252. }
  253. func getSharees(sharees: [NCCommunicationSharee]?) {
  254. guard let sharees = sharees else { return }
  255. dropDown = DropDown()
  256. let appearance = DropDown.appearance()
  257. appearance.backgroundColor = NCBrandColor.shared.systemBackground
  258. appearance.cornerRadius = 10
  259. appearance.shadowColor = UIColor(white: 0.5, alpha: 1)
  260. appearance.shadowOpacity = 0.9
  261. appearance.shadowRadius = 25
  262. appearance.animationduration = 0.25
  263. appearance.textColor = .darkGray
  264. appearance.setupMaskedCorners([.layerMaxXMaxYCorner, .layerMinXMaxYCorner])
  265. for sharee in sharees {
  266. var label = sharee.label
  267. if sharee.shareType == NCShareCommon.shared.SHARE_TYPE_CIRCLE {
  268. label = label + " (" + sharee.circleInfo + ", " + sharee.circleOwner + ")"
  269. }
  270. dropDown.dataSource.append(label)
  271. }
  272. dropDown.anchorView = searchField
  273. dropDown.bottomOffset = CGPoint(x: 0, y: searchField.bounds.height)
  274. dropDown.width = searchField.bounds.width
  275. dropDown.direction = .bottom
  276. dropDown.cellNib = UINib(nibName: "NCShareUserDropDownCell", bundle: nil)
  277. dropDown.customCellConfiguration = { (index: Index, item: String, cell: DropDownCell) -> Void in
  278. guard let cell = cell as? NCShareUserDropDownCell else { return }
  279. let sharee = sharees[index]
  280. cell.imageItem.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
  281. cell.imageShareeType.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
  282. let status = NCUtility.shared.getUserStatus(userIcon: sharee.userIcon, userStatus: sharee.userStatus, userMessage: sharee.userMessage)
  283. cell.imageStatus.image = status.onlineStatus
  284. cell.status.text = status.statusMessage
  285. if cell.status.text?.count ?? 0 > 0 {
  286. cell.centerTitle.constant = -5
  287. } else {
  288. cell.centerTitle.constant = 0
  289. }
  290. let fileName = String(CCUtility.getUserUrlBase(self.appDelegate.user, urlBase: self.appDelegate.urlBase)) + "-" + sharee.shareWith + ".png"
  291. if let image = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) {
  292. cell.imageItem.image = image
  293. } else {
  294. let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
  295. let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
  296. NCCommunication.shared.downloadAvatar(user: sharee.shareWith, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag) { (account, imageAvatar, imageOriginal, etag, errorCode, errorMessage) in
  297. if errorCode == 0, let etag = etag, let imageAvatar = imageAvatar {
  298. NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
  299. cell.imageItem.image = imageAvatar
  300. } else if errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = NCManageDatabase.shared.setAvatarLoaded(fileName: fileName) {
  301. cell.imageItem.image = imageAvatar
  302. }
  303. }
  304. }
  305. }
  306. dropDown.selectionAction = { [weak self] (index, item) in
  307. let sharee = sharees[index]
  308. self!.networking?.createShare(shareWith: sharee.shareWith, shareType: sharee.shareType, metadata: self!.metadata!)
  309. }
  310. dropDown.show()
  311. }
  312. }
  313. // MARK: - UITableViewDelegate
  314. extension NCShare: UITableViewDelegate {
  315. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  316. return 70
  317. }
  318. }
  319. // MARK: - UITableViewDataSource
  320. extension NCShare: UITableViewDataSource {
  321. func numberOfSections(in tableView: UITableView) -> Int {
  322. return 1
  323. }
  324. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  325. var numOfRows = 0
  326. let shares = NCManageDatabase.shared.getTableShares(metadata: metadata!)
  327. if shares.share != nil {
  328. numOfRows = shares.share!.count
  329. }
  330. return numOfRows
  331. }
  332. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  333. let shares = NCManageDatabase.shared.getTableShares(metadata: metadata!)
  334. let tableShare = shares.share![indexPath.row]
  335. // LINK
  336. if tableShare.shareType == 3 {
  337. if let cell = tableView.dequeueReusableCell(withIdentifier: "cellLink", for: indexPath) as? NCShareLinkCell {
  338. cell.tableShare = tableShare
  339. cell.delegate = self
  340. cell.labelTitle.text = NSLocalizedString("_share_link_", comment: "")
  341. if tableShare.label.count > 0 {
  342. cell.labelTitle.text = NSLocalizedString("_share_link_", comment: "") + " (" + tableShare.label + ")"
  343. }
  344. cell.labelTitle.textColor = NCBrandColor.shared.label
  345. return cell
  346. }
  347. } else {
  348. // USER
  349. if let cell = tableView.dequeueReusableCell(withIdentifier: "cellUser", for: indexPath) as? NCShareUserCell {
  350. cell.tableShare = tableShare
  351. cell.delegate = self
  352. cell.labelTitle.text = tableShare.shareWithDisplayname
  353. cell.labelTitle.textColor = NCBrandColor.shared.label
  354. cell.isUserInteractionEnabled = true
  355. cell.labelQuickStatus.isHidden = false
  356. cell.imageDownArrow.isHidden = false
  357. cell.buttonMenu.isHidden = false
  358. cell.imageItem.image = NCShareCommon.shared.getImageShareType(shareType: tableShare.shareType)
  359. let status = NCUtility.shared.getUserStatus(userIcon: tableShare.userIcon, userStatus: tableShare.userStatus, userMessage: tableShare.userMessage)
  360. cell.imageStatus.image = status.onlineStatus
  361. cell.status.text = status.statusMessage
  362. let fileName = String(CCUtility.getUserUrlBase(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + tableShare.shareWith + ".png"
  363. NCOperationQueue.shared.downloadAvatar(user: tableShare.shareWith, fileName: fileName, placeholder: UIImage(named: "avatar"), cell: cell, view: tableView)
  364. // If the initiator or the recipient is not the current user, show the list of sharees without any options to edit it.
  365. if tableShare.uidOwner != self.appDelegate.userId && tableShare.uidFileOwner != self.appDelegate.userId {
  366. cell.isUserInteractionEnabled = false
  367. cell.labelQuickStatus.isHidden = true
  368. cell.imageDownArrow.isHidden = true
  369. cell.buttonMenu.isHidden = true
  370. }
  371. cell.btnQuickStatus.setTitle("", for: .normal)
  372. cell.btnQuickStatus.contentHorizontalAlignment = .left
  373. if tableShare.permissions == NCGlobal.shared.permissionCreateShare {
  374. cell.labelQuickStatus.text = NSLocalizedString("_share_file_drop_", comment: "")
  375. } else {
  376. // Read Only
  377. if CCUtility.isAnyPermission(toEdit: tableShare.permissions) {
  378. cell.labelQuickStatus.text = NSLocalizedString("_share_editing_", comment: "")
  379. } else {
  380. cell.labelQuickStatus.text = NSLocalizedString("_share_read_only_", comment: "")
  381. }
  382. }
  383. return cell
  384. }
  385. }
  386. return UITableViewCell()
  387. }
  388. }
  389. // MARK: - NCShareLinkCell
  390. class NCShareLinkCell: UITableViewCell {
  391. @IBOutlet weak var imageItem: UIImageView!
  392. @IBOutlet weak var labelTitle: UILabel!
  393. @IBOutlet weak var buttonCopy: UIButton!
  394. @IBOutlet weak var buttonMenu: UIButton!
  395. private let iconShare: CGFloat = 200
  396. var tableShare: tableShare?
  397. var delegate: NCShareLinkCellDelegate?
  398. override func awakeFromNib() {
  399. super.awakeFromNib()
  400. imageItem.image = NCShareCommon.shared.createLinkAvatar(imageName: "sharebylink", colorCircle: NCBrandColor.shared.brandElement)
  401. buttonCopy.setImage(UIImage.init(named: "shareCopy")!.image(color: .gray, size: 50), for: .normal)
  402. buttonMenu.setImage(UIImage.init(named: "shareMenu")!.image(color: .gray, size: 50), for: .normal)
  403. }
  404. @IBAction func touchUpInsideCopy(_ sender: Any) {
  405. delegate?.tapCopy(with: tableShare, sender: sender)
  406. }
  407. @IBAction func touchUpInsideMenu(_ sender: Any) {
  408. delegate?.tapMenu(with: tableShare, sender: sender)
  409. }
  410. }
  411. protocol NCShareLinkCellDelegate {
  412. func tapCopy(with tableShare: tableShare?, sender: Any)
  413. func tapMenu(with tableShare: tableShare?, sender: Any)
  414. }
  415. // MARK: - NCShareUserCell
  416. class NCShareUserCell: UITableViewCell, NCCellProtocol {
  417. @IBOutlet weak var imageItem: UIImageView!
  418. @IBOutlet weak var labelTitle: UILabel!
  419. @IBOutlet weak var buttonMenu: UIButton!
  420. @IBOutlet weak var imageStatus: UIImageView!
  421. @IBOutlet weak var status: UILabel!
  422. @IBOutlet weak var btnQuickStatus: UIButton!
  423. @IBOutlet weak var labelQuickStatus: UILabel!
  424. @IBOutlet weak var imageDownArrow: UIImageView!
  425. var tableShare: tableShare?
  426. var delegate: NCShareUserCellDelegate?
  427. var fileAvatarImageView: UIImageView? {
  428. get{
  429. return imageItem
  430. }
  431. }
  432. var fileObjectId: String? {
  433. get {
  434. return nil
  435. }
  436. }
  437. var filePreviewImageView : UIImageView? {
  438. get{
  439. return nil
  440. }
  441. }
  442. var fileUser: String? {
  443. get{
  444. return tableShare?.shareWith
  445. }
  446. }
  447. override func awakeFromNib() {
  448. super.awakeFromNib()
  449. buttonMenu.setImage(UIImage.init(named: "shareMenu")!.image(color: .gray, size: 50), for: .normal)
  450. labelQuickStatus.textColor = NCBrandColor.shared.customer
  451. imageDownArrow.image = NCUtility.shared.loadImage(named: "arrowtriangle.down.fill", color: NCBrandColor.shared.customer)
  452. }
  453. @IBAction func touchUpInsideMenu(_ sender: Any) {
  454. delegate?.tapMenu(with: tableShare, sender: sender)
  455. }
  456. @IBAction func quickStatusClicked(_ sender: Any) {
  457. delegate?.quickStatus(with: tableShare, sender: sender)
  458. }
  459. }
  460. protocol NCShareUserCellDelegate {
  461. func tapMenu(with tableShare: tableShare?, sender: Any)
  462. func quickStatus(with tableShare: tableShare?, sender: Any)
  463. }
  464. // MARK: - NCShareUserDropDownCell
  465. class NCShareUserDropDownCell: DropDownCell, NCCellProtocol {
  466. @IBOutlet weak var imageItem: UIImageView!
  467. @IBOutlet weak var imageStatus: UIImageView!
  468. @IBOutlet weak var status: UILabel!
  469. @IBOutlet weak var imageShareeType: UIImageView!
  470. @IBOutlet weak var centerTitle: NSLayoutConstraint!
  471. private var user: String = ""
  472. var fileAvatarImageView: UIImageView? {
  473. get {
  474. return imageItem
  475. }
  476. }
  477. var fileObjectId: String? {
  478. get {
  479. return nil
  480. }
  481. }
  482. var filePreviewImageView: UIImageView? {
  483. get {
  484. return nil
  485. }
  486. }
  487. var fileUser: String? {
  488. get {
  489. return user
  490. }
  491. set {
  492. user = newValue ?? ""
  493. }
  494. }
  495. }