NCShare.swift 26 KB

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