RaiseHandApplicationCell.swift 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // RaiseHandApplicationCell.swift
  3. // TUIRoomKit
  4. //
  5. // Created by janejntang on 2024/5/7.
  6. //
  7. import Foundation
  8. class RaiseHandApplicationCell: UITableViewCell {
  9. let attendeeModel: RequestEntity
  10. let viewModel: RaiseHandApplicationListViewModel
  11. let avatarImageView: UIImageView = {
  12. let img = UIImageView()
  13. img.layer.cornerRadius = 20
  14. img.layer.masksToBounds = true
  15. return img
  16. }()
  17. let userLabel: UILabel = {
  18. let label = UILabel()
  19. label.textColor = UIColor(0xD5E0F2)
  20. label.backgroundColor = UIColor.clear
  21. label.textAlignment = isRTL ? .right : .left
  22. label.font = UIFont.systemFont(ofSize: 16, weight: .regular)
  23. label.numberOfLines = 1
  24. return label
  25. }()
  26. let applyLabel: UILabel = {
  27. let label = UILabel()
  28. label.text = .applyText
  29. label.textColor = UIColor(0x8F9AB2)
  30. label.backgroundColor = UIColor.clear
  31. label.textAlignment = isRTL ? .right : .left
  32. label.font = UIFont.systemFont(ofSize: 12)
  33. return label
  34. }()
  35. let disagreeStageButton: UIButton = {
  36. let button = UIButton(type: .custom)
  37. button.backgroundColor = UIColor(0x6B758A).withAlphaComponent(0.3)
  38. button.setTitle(.disagreeSeatText, for: .normal)
  39. button.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .regular)
  40. button.titleLabel?.adjustsFontSizeToFitWidth = true
  41. button.setTitleColor(UIColor(0xB2BBD1), for: .normal)
  42. button.layer.cornerRadius = 6
  43. button.clipsToBounds = true
  44. return button
  45. }()
  46. let agreeStageButton: UIButton = {
  47. let button = UIButton(type: .custom)
  48. button.backgroundColor = UIColor(0x1C66E5)
  49. button.setTitle(.agreeSeatText, for: .normal)
  50. button.setTitleColor(.white, for: .normal)
  51. button.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .regular)
  52. button.titleLabel?.adjustsFontSizeToFitWidth = true
  53. button.layer.cornerRadius = 6
  54. button.clipsToBounds = true
  55. return button
  56. }()
  57. let downLineView : UIView = {
  58. let view = UIView()
  59. view.backgroundColor = UIColor(0x4F586B).withAlphaComponent(0.3)
  60. return view
  61. }()
  62. init(attendeeModel: RequestEntity ,viewModel: RaiseHandApplicationListViewModel) {
  63. self.attendeeModel = attendeeModel
  64. self.viewModel = viewModel
  65. super.init(style: .default, reuseIdentifier: "RaiseHandCell")
  66. }
  67. private var isViewReady: Bool = false
  68. override func didMoveToWindow() {
  69. super.didMoveToWindow()
  70. guard !isViewReady else { return }
  71. constructViewHierarchy()
  72. activateConstraints()
  73. bindInteraction()
  74. isViewReady = true
  75. }
  76. required init?(coder: NSCoder) {
  77. fatalError("init(coder:) has not been implemented")
  78. }
  79. func constructViewHierarchy() {
  80. contentView.addSubview(avatarImageView)
  81. contentView.addSubview(userLabel)
  82. contentView.addSubview(applyLabel)
  83. contentView.addSubview(agreeStageButton)
  84. contentView.addSubview(disagreeStageButton)
  85. contentView.addSubview(downLineView)
  86. }
  87. func activateConstraints() {
  88. avatarImageView.snp.makeConstraints { make in
  89. make.width.height.equalTo(40.scale375())
  90. make.leading.equalToSuperview()
  91. make.top.equalToSuperview().offset(10.scale375Height())
  92. }
  93. agreeStageButton.snp.makeConstraints { make in
  94. make.width.equalTo(48.scale375())
  95. make.height.equalTo(28.scale375Height())
  96. make.trailing.equalToSuperview()
  97. make.centerY.equalToSuperview()
  98. }
  99. disagreeStageButton.snp.makeConstraints { make in
  100. make.trailing.equalTo(agreeStageButton.snp.leading).offset(-10)
  101. make.centerY.equalTo(agreeStageButton)
  102. make.width.height.equalTo(agreeStageButton)
  103. }
  104. userLabel.snp.makeConstraints { make in
  105. make.top.equalToSuperview().offset(14.scale375Height())
  106. make.leading.equalTo(avatarImageView.snp.trailing).offset(12.scale375())
  107. make.width.equalTo(150.scale375())
  108. make.height.equalTo(22.scale375())
  109. }
  110. applyLabel.snp.makeConstraints { make in
  111. make.top.equalTo(userLabel.snp.bottom).offset(2.scale375Height())
  112. make.leading.equalTo(userLabel)
  113. }
  114. downLineView.snp.makeConstraints { make in
  115. make.leading.equalTo(userLabel)
  116. make.trailing.equalToSuperview()
  117. make.bottom.equalToSuperview()
  118. make.height.equalTo(1.scale375())
  119. }
  120. }
  121. func bindInteraction() {
  122. setupViewState(item: attendeeModel)
  123. agreeStageButton.addTarget(self, action: #selector(agreeStageAction(sender:)), for: .touchUpInside)
  124. disagreeStageButton.addTarget(self, action: #selector(disagreeStageAction(sender:)), for: .touchUpInside)
  125. }
  126. func setupViewState(item: RequestEntity) {
  127. let placeholder = UIImage(named: "room_default_user", in: tuiRoomKitBundle(), compatibleWith: nil)
  128. if let url = URL(string: item.avatarUrl) {
  129. avatarImageView.sd_setImage(with: url, placeholderImage: placeholder)
  130. } else {
  131. avatarImageView.image = placeholder
  132. }
  133. userLabel.text = item.userName
  134. backgroundColor = .clear
  135. }
  136. @objc func agreeStageAction(sender: UIButton) {
  137. viewModel.respondRequest(isAgree: true, request: attendeeModel)
  138. }
  139. @objc func disagreeStageAction(sender: UIButton) {
  140. viewModel.respondRequest(isAgree: false, request: attendeeModel)
  141. }
  142. deinit {
  143. debugPrint("deinit \(self)")
  144. }
  145. }
  146. private extension String {
  147. static var applyText: String {
  148. localized("Apply to be on stage")
  149. }
  150. static var disagreeSeatText: String {
  151. localized("Reject")
  152. }
  153. static var agreeSeatText: String {
  154. localized("Agree")
  155. }
  156. }