NCShareUserCell.swift 7.3 KB

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