NCShareUserCell.swift 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. //
  2. // NCShareUserCell.swift
  3. // Nextcloud
  4. //
  5. // Created by Henrik Storch on 15.11.2021.
  6. // Copyright © 2021 Henrik Storch. All rights reserved.
  7. //
  8. // Author Henrik Storch <henrik.storch@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. import UIKit
  23. import DropDown
  24. import NCCommunication
  25. class NCShareUserCell: UITableViewCell, NCCellProtocol {
  26. @IBOutlet weak var imageItem: UIImageView!
  27. @IBOutlet weak var labelTitle: UILabel!
  28. @IBOutlet weak var buttonMenu: UIButton!
  29. @IBOutlet weak var imageStatus: UIImageView!
  30. @IBOutlet weak var status: UILabel!
  31. @IBOutlet weak var btnQuickStatus: UIButton!
  32. @IBOutlet weak var labelQuickStatus: UILabel!
  33. @IBOutlet weak var imageDownArrow: UIImageView!
  34. var tableShare: tableShare?
  35. weak var delegate: NCShareUserCellDelegate?
  36. var filePreviewImageView: UIImageView? {
  37. get { return nil }
  38. set {}
  39. }
  40. var fileAvatarImageView: UIImageView? {
  41. return imageItem
  42. }
  43. var fileUser: String? {
  44. get { return tableShare?.shareWith }
  45. set {}
  46. }
  47. var fileObjectId: String? {
  48. get { return nil }
  49. set {}
  50. }
  51. var fileTitleLabel: UILabel? {
  52. get { return nil }
  53. set {}
  54. }
  55. var fileInfoLabel: UILabel? {
  56. get { return nil }
  57. set { }
  58. }
  59. var fileProgressView: UIProgressView? {
  60. get { return nil }
  61. set { }
  62. }
  63. var fileSelectImage: UIImageView? {
  64. get { return nil }
  65. set {}
  66. }
  67. var fileStatusImage: UIImageView? {
  68. get { return nil }
  69. set {}
  70. }
  71. var fileLocalImage: UIImageView? {
  72. get { return nil }
  73. set {}
  74. }
  75. var fileFavoriteImage: UIImageView? {
  76. get { return nil }
  77. set {}
  78. }
  79. var fileSharedImage: UIImageView? {
  80. get { return nil }
  81. set {}
  82. }
  83. var fileMoreImage: UIImageView? {
  84. get { return nil }
  85. set {}
  86. }
  87. func setupCellUI(userId: String) {
  88. guard let tableShare = tableShare else {
  89. return
  90. }
  91. self.accessibilityCustomActions = [UIAccessibilityCustomAction(
  92. name: NSLocalizedString("_show_profile_", comment: ""),
  93. target: self,
  94. selector: #selector(tapAvatarImage))]
  95. labelTitle.text = tableShare.shareWithDisplayname
  96. labelTitle.textColor = NCBrandColor.shared.label
  97. isUserInteractionEnabled = true
  98. labelQuickStatus.isHidden = false
  99. imageDownArrow.isHidden = false
  100. buttonMenu.isHidden = false
  101. buttonMenu.accessibilityLabel = NSLocalizedString("_more_", comment: "")
  102. imageItem.image = NCShareCommon.shared.getImageShareType(shareType: tableShare.shareType)
  103. let status = NCUtility.shared.getUserStatus(userIcon: tableShare.userIcon, userStatus: tableShare.userStatus, userMessage: tableShare.userMessage)
  104. imageStatus.image = status.onlineStatus
  105. self.status.text = status.statusMessage
  106. // If the initiator or the recipient is not the current user, show the list of sharees without any options to edit it.
  107. if tableShare.uidOwner != userId && tableShare.uidFileOwner != userId {
  108. isUserInteractionEnabled = false
  109. labelQuickStatus.isHidden = true
  110. imageDownArrow.isHidden = true
  111. buttonMenu.isHidden = true
  112. }
  113. btnQuickStatus.accessibilityHint = NSLocalizedString("_user_sharee_footer_", comment: "")
  114. btnQuickStatus.setTitle("", for: .normal)
  115. btnQuickStatus.contentHorizontalAlignment = .left
  116. if tableShare.permissions == NCGlobal.shared.permissionCreateShare {
  117. labelQuickStatus.text = NSLocalizedString("_share_file_drop_", comment: "")
  118. } else {
  119. // Read Only
  120. if CCUtility.isAnyPermission(toEdit: tableShare.permissions) {
  121. labelQuickStatus.text = NSLocalizedString("_share_editing_", comment: "")
  122. } else {
  123. labelQuickStatus.text = NSLocalizedString("_share_read_only_", comment: "")
  124. }
  125. }
  126. }
  127. override func awakeFromNib() {
  128. super.awakeFromNib()
  129. let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapAvatarImage))
  130. imageItem?.addGestureRecognizer(tapGesture)
  131. buttonMenu.setImage(UIImage(named: "shareMenu")?.image(color: .gray, size: 50), for: .normal)
  132. labelQuickStatus.textColor = NCBrandColor.shared.customer
  133. imageDownArrow.image = NCUtility.shared.loadImage(named: "arrowtriangle.down.fill", color: NCBrandColor.shared.customer)
  134. }
  135. @objc func tapAvatarImage(_ sender: UITapGestureRecognizer) {
  136. delegate?.showProfile(with: tableShare, sender: sender)
  137. }
  138. @IBAction func touchUpInsideMenu(_ sender: Any) {
  139. delegate?.tapMenu(with: tableShare, sender: sender)
  140. }
  141. @IBAction func quickStatusClicked(_ sender: Any) {
  142. delegate?.quickStatus(with: tableShare, sender: sender)
  143. }
  144. }
  145. protocol NCShareUserCellDelegate: AnyObject {
  146. func tapMenu(with tableShare: tableShare?, sender: Any)
  147. func showProfile(with tableComment: tableShare?, sender: Any)
  148. func quickStatus(with tableShare: tableShare?, sender: Any)
  149. }
  150. // MARK: - NCSearchUserDropDownCell
  151. class NCSearchUserDropDownCell: DropDownCell, NCCellProtocol {
  152. @IBOutlet weak var imageItem: UIImageView!
  153. @IBOutlet weak var imageStatus: UIImageView!
  154. @IBOutlet weak var status: UILabel!
  155. @IBOutlet weak var imageShareeType: UIImageView!
  156. @IBOutlet weak var centerTitle: NSLayoutConstraint!
  157. private var user: String = ""
  158. var filePreviewImageView: UIImageView? {
  159. get { return nil }
  160. set {}
  161. }
  162. var fileAvatarImageView: UIImageView? {
  163. return imageItem
  164. }
  165. var fileObjectId: String? {
  166. get { return nil }
  167. set {}
  168. }
  169. var fileUser: String? {
  170. get { return user }
  171. set { user = newValue ?? "" }
  172. }
  173. var fileTitleLabel: UILabel? {
  174. get { return nil }
  175. set {}
  176. }
  177. var fileInfoLabel: UILabel? {
  178. get { return nil }
  179. set { }
  180. }
  181. var fileProgressView: UIProgressView? {
  182. get { return nil }
  183. set { }
  184. }
  185. var fileSelectImage: UIImageView? {
  186. get { return nil }
  187. set {}
  188. }
  189. var fileStatusImage: UIImageView? {
  190. get { return nil }
  191. set {}
  192. }
  193. var fileLocalImage: UIImageView? {
  194. get { return nil }
  195. set {}
  196. }
  197. var fileFavoriteImage: UIImageView? {
  198. get { return nil }
  199. set {}
  200. }
  201. var fileSharedImage: UIImageView? {
  202. get { return nil }
  203. set {}
  204. }
  205. var fileMoreImage: UIImageView? {
  206. get { return nil }
  207. set {}
  208. }
  209. func setupCell(sharee: NCCommunicationSharee, baseUrl: NCUserBaseUrl) {
  210. imageItem.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
  211. imageShareeType.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
  212. let status = NCUtility.shared.getUserStatus(userIcon: sharee.userIcon, userStatus: sharee.userStatus, userMessage: sharee.userMessage)
  213. imageStatus.image = status.onlineStatus
  214. self.status.text = status.statusMessage
  215. if self.status.text?.count ?? 0 > 0 {
  216. centerTitle.constant = -5
  217. } else {
  218. centerTitle.constant = 0
  219. }
  220. imageItem.image = NCUtility.shared.loadUserImage(
  221. for: sharee.shareWith,
  222. displayName: nil,
  223. userBaseUrl: baseUrl)
  224. let fileName = baseUrl.userBaseUrl + "-" + sharee.shareWith + ".png"
  225. if NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) == nil {
  226. let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
  227. let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
  228. NCCommunication.shared.downloadAvatar(
  229. user: sharee.shareWith,
  230. fileNameLocalPath: fileNameLocalPath,
  231. sizeImage: NCGlobal.shared.avatarSize,
  232. avatarSizeRounded: NCGlobal.shared.avatarSizeRounded,
  233. etag: etag) { _, imageAvatar, _, etag, errorCode, _ in
  234. if errorCode == 0, let etag = etag, let imageAvatar = imageAvatar {
  235. NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
  236. self.imageItem.image = imageAvatar
  237. } else if errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = NCManageDatabase.shared.setAvatarLoaded(fileName: fileName) {
  238. self.imageItem.image = imageAvatar
  239. }
  240. }
  241. }
  242. }
  243. }