NCShareUserCell.swift 7.5 KB

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