NCShare.swift 26 KB

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