NCShareUserCell.swift 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. func writeInfoDateSize(date: NSDate, totalBytes: Int64) {}
  145. func setButtonMore(named: String, image: UIImage) {}
  146. func hideButtonShare(_ status: Bool) {}
  147. func hideButtonMore(_ status: Bool) {}
  148. }
  149. protocol NCShareUserCellDelegate: AnyObject {
  150. func tapMenu(with tableShare: tableShare?, sender: Any)
  151. func showProfile(with tableComment: tableShare?, sender: Any)
  152. func quickStatus(with tableShare: tableShare?, sender: Any)
  153. }
  154. // MARK: - NCSearchUserDropDownCell
  155. class NCSearchUserDropDownCell: DropDownCell, NCCellProtocol {
  156. @IBOutlet weak var imageItem: UIImageView!
  157. @IBOutlet weak var imageStatus: UIImageView!
  158. @IBOutlet weak var status: UILabel!
  159. @IBOutlet weak var imageShareeType: UIImageView!
  160. @IBOutlet weak var centerTitle: NSLayoutConstraint!
  161. private var user: String = ""
  162. var filePreviewImageView: UIImageView? {
  163. get { return imageItem }
  164. set {}
  165. }
  166. var fileAvatarImageView: UIImageView? {
  167. get { return nil }
  168. }
  169. var fileObjectId: String? {
  170. get { return nil }
  171. set {}
  172. }
  173. var fileUser: String? {
  174. get { return user }
  175. set { user = newValue ?? "" }
  176. }
  177. var fileTitleLabel: UILabel? {
  178. get { return nil }
  179. set {}
  180. }
  181. var fileInfoLabel: UILabel? {
  182. get { return nil }
  183. set { }
  184. }
  185. var fileProgressView: UIProgressView? {
  186. get { return nil }
  187. set { }
  188. }
  189. var fileSelectImage: UIImageView? {
  190. get { return nil }
  191. set {}
  192. }
  193. var fileStatusImage: UIImageView? {
  194. get { return nil }
  195. set {}
  196. }
  197. var fileLocalImage: UIImageView? {
  198. get { return nil }
  199. set {}
  200. }
  201. var fileFavoriteImage: UIImageView? {
  202. get { return nil }
  203. set {}
  204. }
  205. var fileSharedImage: UIImageView? {
  206. get { return nil }
  207. set {}
  208. }
  209. var fileMoreImage: UIImageView? {
  210. get { return nil }
  211. set {}
  212. }
  213. func setupCell(sharee: NCCommunicationSharee, baseUrl: NCUserBaseUrl) {
  214. imageItem.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
  215. imageShareeType.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
  216. let status = NCUtility.shared.getUserStatus(userIcon: sharee.userIcon, userStatus: sharee.userStatus, userMessage: sharee.userMessage)
  217. imageStatus.image = status.onlineStatus
  218. self.status.text = status.statusMessage
  219. if self.status.text?.count ?? 0 > 0 {
  220. centerTitle.constant = -5
  221. } else {
  222. centerTitle.constant = 0
  223. }
  224. imageItem.image = NCUtility.shared.loadUserImage(
  225. for: sharee.shareWith,
  226. displayName: nil,
  227. userBaseUrl: baseUrl)
  228. let fileName = baseUrl.userBaseUrl + "-" + sharee.shareWith + ".png"
  229. if NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) == nil {
  230. let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
  231. let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
  232. NCCommunication.shared.downloadAvatar(
  233. user: sharee.shareWith,
  234. fileNameLocalPath: fileNameLocalPath,
  235. sizeImage: NCGlobal.shared.avatarSize,
  236. avatarSizeRounded: NCGlobal.shared.avatarSizeRounded,
  237. etag: etag) { _, imageAvatar, _, etag, errorCode, _ in
  238. if errorCode == 0, let etag = etag, let imageAvatar = imageAvatar {
  239. NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
  240. self.imageItem.image = imageAvatar
  241. } else if errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = NCManageDatabase.shared.setAvatarLoaded(fileName: fileName) {
  242. self.imageItem.image = imageAvatar
  243. }
  244. }
  245. }
  246. }
  247. func writeInfoDateSize(date: NSDate, totalBytes: Int64) {}
  248. func setButtonMore(named: String, image: UIImage) {}
  249. func hideButtonShare(_ status: Bool) {}
  250. func hideButtonMore(_ status: Bool) {}
  251. }