NCShareUserCell.swift 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 fileAvatarImageView: UIImageView? { return imageItem }
  37. var fileObjectId: String? { return nil }
  38. var filePreviewImageView: UIImageView? { return nil }
  39. var fileUser: String? { return tableShare?.shareWith }
  40. var title: String? {
  41. get {
  42. return labelTitle.text
  43. }
  44. set {
  45. labelTitle.text = newValue ?? ""
  46. }
  47. }
  48. var info: String? {
  49. get {
  50. return status.text
  51. }
  52. set {
  53. status.text = newValue ?? ""
  54. }
  55. }
  56. var progress: UIProgressView? {
  57. get {
  58. return nil
  59. }
  60. set { }
  61. }
  62. func setupCellUI(userId: String) {
  63. guard let tableShare = tableShare else {
  64. return
  65. }
  66. self.accessibilityCustomActions = [UIAccessibilityCustomAction(
  67. name: NSLocalizedString("_show_profile_", comment: ""),
  68. target: self,
  69. selector: #selector(tapAvatarImage))]
  70. labelTitle.text = tableShare.shareWithDisplayname
  71. labelTitle.textColor = NCBrandColor.shared.label
  72. isUserInteractionEnabled = true
  73. labelQuickStatus.isHidden = false
  74. imageDownArrow.isHidden = false
  75. buttonMenu.isHidden = false
  76. buttonMenu.accessibilityLabel = NSLocalizedString("_more_", comment: "")
  77. imageItem.image = NCShareCommon.shared.getImageShareType(shareType: tableShare.shareType)
  78. let status = NCUtility.shared.getUserStatus(userIcon: tableShare.userIcon, userStatus: tableShare.userStatus, userMessage: tableShare.userMessage)
  79. imageStatus.image = status.onlineStatus
  80. self.status.text = status.statusMessage
  81. // If the initiator or the recipient is not the current user, show the list of sharees without any options to edit it.
  82. if tableShare.uidOwner != userId && tableShare.uidFileOwner != userId {
  83. isUserInteractionEnabled = false
  84. labelQuickStatus.isHidden = true
  85. imageDownArrow.isHidden = true
  86. buttonMenu.isHidden = true
  87. }
  88. btnQuickStatus.accessibilityHint = NSLocalizedString("_user_sharee_footer_", comment: "")
  89. btnQuickStatus.setTitle("", for: .normal)
  90. btnQuickStatus.contentHorizontalAlignment = .left
  91. if tableShare.permissions == NCGlobal.shared.permissionCreateShare {
  92. labelQuickStatus.text = NSLocalizedString("_share_file_drop_", comment: "")
  93. } else {
  94. // Read Only
  95. if CCUtility.isAnyPermission(toEdit: tableShare.permissions) {
  96. labelQuickStatus.text = NSLocalizedString("_share_editing_", comment: "")
  97. } else {
  98. labelQuickStatus.text = NSLocalizedString("_share_read_only_", comment: "")
  99. }
  100. }
  101. }
  102. override func awakeFromNib() {
  103. super.awakeFromNib()
  104. let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapAvatarImage))
  105. imageItem?.addGestureRecognizer(tapGesture)
  106. buttonMenu.setImage(UIImage(named: "shareMenu")?.image(color: .gray, size: 50), for: .normal)
  107. labelQuickStatus.textColor = NCBrandColor.shared.customer
  108. imageDownArrow.image = NCUtility.shared.loadImage(named: "arrowtriangle.down.fill", color: NCBrandColor.shared.customer)
  109. }
  110. @objc func tapAvatarImage(_ sender: UITapGestureRecognizer) {
  111. delegate?.showProfile(with: tableShare, sender: sender)
  112. }
  113. @IBAction func touchUpInsideMenu(_ sender: Any) {
  114. delegate?.tapMenu(with: tableShare, sender: sender)
  115. }
  116. @IBAction func quickStatusClicked(_ sender: Any) {
  117. delegate?.quickStatus(with: tableShare, sender: sender)
  118. }
  119. func writeInfoDateSize(date: NSDate, totalBytes: Int64) {}
  120. func setButtonMore(named: String, image: UIImage) {}
  121. }
  122. protocol NCShareUserCellDelegate: AnyObject {
  123. func tapMenu(with tableShare: tableShare?, sender: Any)
  124. func showProfile(with tableComment: tableShare?, sender: Any)
  125. func quickStatus(with tableShare: tableShare?, sender: Any)
  126. }
  127. // MARK: - NCSearchUserDropDownCell
  128. class NCSearchUserDropDownCell: DropDownCell, NCCellProtocol {
  129. @IBOutlet weak var imageItem: UIImageView!
  130. @IBOutlet weak var imageStatus: UIImageView!
  131. @IBOutlet weak var status: UILabel!
  132. @IBOutlet weak var imageShareeType: UIImageView!
  133. @IBOutlet weak var centerTitle: NSLayoutConstraint!
  134. private var user: String = ""
  135. var fileAvatarImageView: UIImageView? { return imageItem }
  136. var fileObjectId: String? { return nil }
  137. var filePreviewImageView: UIImageView? { return nil }
  138. var fileUser: String? {
  139. get {
  140. return user
  141. }
  142. set {
  143. user = newValue ?? ""
  144. }
  145. }
  146. var title: String? {
  147. get {
  148. return nil
  149. }
  150. set { }
  151. }
  152. var info: String? {
  153. get {
  154. return nil
  155. }
  156. set { }
  157. }
  158. var progress: UIProgressView? {
  159. get {
  160. return nil
  161. }
  162. set { }
  163. }
  164. func setupCell(sharee: NCCommunicationSharee, baseUrl: NCUserBaseUrl) {
  165. imageItem.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
  166. imageShareeType.image = NCShareCommon.shared.getImageShareType(shareType: sharee.shareType)
  167. let status = NCUtility.shared.getUserStatus(userIcon: sharee.userIcon, userStatus: sharee.userStatus, userMessage: sharee.userMessage)
  168. imageStatus.image = status.onlineStatus
  169. self.status.text = status.statusMessage
  170. if self.status.text?.count ?? 0 > 0 {
  171. centerTitle.constant = -5
  172. } else {
  173. centerTitle.constant = 0
  174. }
  175. imageItem.image = NCUtility.shared.loadUserImage(
  176. for: sharee.shareWith,
  177. displayName: nil,
  178. userBaseUrl: baseUrl)
  179. let fileName = baseUrl.userBaseUrl + "-" + sharee.shareWith + ".png"
  180. if NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) == nil {
  181. let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
  182. let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
  183. NCCommunication.shared.downloadAvatar(
  184. user: sharee.shareWith,
  185. fileNameLocalPath: fileNameLocalPath,
  186. sizeImage: NCGlobal.shared.avatarSize,
  187. avatarSizeRounded: NCGlobal.shared.avatarSizeRounded,
  188. etag: etag) { _, imageAvatar, _, etag, errorCode, _ in
  189. if errorCode == 0, let etag = etag, let imageAvatar = imageAvatar {
  190. NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
  191. self.imageItem.image = imageAvatar
  192. } else if errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = NCManageDatabase.shared.setAvatarLoaded(fileName: fileName) {
  193. self.imageItem.image = imageAvatar
  194. }
  195. }
  196. }
  197. }
  198. func writeInfoDateSize(date: NSDate, totalBytes: Int64) {}
  199. func setButtonMore(named: String, image: UIImage) {}
  200. }