RaiseHandApplicationListView.swift 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. //
  2. // RaiseHandApplicationListView.swift
  3. // TUIRoomKit
  4. //
  5. // Created by janejntang on 2023/1/13.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. import Foundation
  9. class RaiseHandApplicationListView: UIView {
  10. let viewModel: RaiseHandApplicationListViewModel
  11. let titleLabel: UILabel = {
  12. let label = UILabel()
  13. label.text = .takeSeatApplyTitle
  14. label.font = UIFont.systemFont(ofSize: 16, weight: .medium)
  15. label.textColor = UIColor(0xD5E0F2)
  16. label.backgroundColor = .clear
  17. return label
  18. }()
  19. let allAgreeButton : UIButton = {
  20. let button = UIButton(type: .custom)
  21. button.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .regular)
  22. button.setTitle(.agreeAllText, for: .normal)
  23. button.setTitleColor(UIColor(0xFFFFFF), for: .normal)
  24. button.setBackgroundImage(UIColor(0x1C66E5).withAlphaComponent(0.5).trans2Image(), for: .disabled)
  25. button.setBackgroundImage(UIColor(0x1C66E5).trans2Image(), for: .normal)
  26. button.layer.cornerRadius = 6
  27. button.clipsToBounds = true
  28. button.adjustsImageWhenHighlighted = false
  29. return button
  30. }()
  31. let allRejectButton: UIButton = {
  32. let button = UIButton(type: .custom)
  33. button.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .regular)
  34. button.setTitle(.rejectAllText, for: .normal)
  35. button.setTitleColor(UIColor(0xB2BBD1), for: .normal)
  36. button.setBackgroundImage(UIColor(0x4F586B).withAlphaComponent(0.5).trans2Image(), for: .disabled)
  37. button.setBackgroundImage(UIColor(0x4F586B).trans2Image(), for: .normal)
  38. button.layer.cornerRadius = 6
  39. button.clipsToBounds = true
  40. button.titleLabel?.adjustsFontSizeToFitWidth = true
  41. button.adjustsImageWhenHighlighted = false
  42. return button
  43. }()
  44. let placeholderUIImageView: UIImageView = {
  45. let image = UIImage(named: "room_apply_placeholder", in: tuiRoomKitBundle(), compatibleWith: nil)
  46. let imageView = UIImageView(image: image)
  47. return imageView
  48. }()
  49. let placeholderLabel: UILabel = {
  50. let label = UILabel()
  51. label.text = .noMemberApplicationText
  52. label.textColor = UIColor(0xB2BBD1)
  53. label.font = UIFont.systemFont(ofSize: 16, weight: .regular)
  54. return label
  55. }()
  56. lazy var applyTableView: UITableView = {
  57. let tableView = UITableView(frame: .zero, style: .plain)
  58. tableView.separatorStyle = .none
  59. tableView.delegate = self
  60. tableView.dataSource = self
  61. tableView.backgroundColor = .clear
  62. tableView.register(RaiseHandApplicationCell.self, forCellReuseIdentifier: "RaiseHandCell")
  63. return tableView
  64. }()
  65. init(viewModel: RaiseHandApplicationListViewModel) {
  66. self.viewModel = viewModel
  67. super.init(frame: .zero)
  68. }
  69. required init?(coder: NSCoder) {
  70. fatalError("init(coder:) has not been implemented")
  71. }
  72. private var isViewReady: Bool = false
  73. override func didMoveToWindow() {
  74. super.didMoveToWindow()
  75. backgroundColor = UIColor(0x22262E)
  76. guard !isViewReady else { return }
  77. constructViewHierarchy()
  78. activateConstraints()
  79. bindInteraction()
  80. isViewReady = true
  81. }
  82. func constructViewHierarchy() {
  83. addSubview(titleLabel)
  84. addSubview(placeholderUIImageView)
  85. addSubview(placeholderLabel)
  86. addSubview(applyTableView)
  87. addSubview(allRejectButton)
  88. addSubview(allAgreeButton)
  89. }
  90. func activateConstraints() {
  91. titleLabel.snp.makeConstraints { make in
  92. make.top.equalToSuperview().offset(10.scale375Height())
  93. make.leading.equalToSuperview().offset(16.scale375())
  94. }
  95. placeholderUIImageView.snp.makeConstraints { make in
  96. make.centerX.equalToSuperview()
  97. make.width.height.equalTo(48.scale375())
  98. make.centerY.equalToSuperview().offset(-30.scale375Height())
  99. }
  100. placeholderLabel.snp.makeConstraints { make in
  101. make.centerX.equalToSuperview()
  102. make.top.equalTo(placeholderUIImageView.snp.bottom).offset(8.scale375Height())
  103. make.height.equalTo(22.scale375Height())
  104. }
  105. applyTableView.snp.makeConstraints { make in
  106. make.leading.equalToSuperview().offset(16.scale375())
  107. make.trailing.equalToSuperview().offset(-16.scale375())
  108. make.top.equalTo(titleLabel.snp.bottom).offset(26.scale375Height())
  109. make.bottom.equalTo(allAgreeButton.snp.top).offset(-10.scale375Height())
  110. }
  111. allRejectButton.snp.remakeConstraints { make in
  112. make.leading.equalTo(applyTableView)
  113. make.bottom.equalToSuperview().offset(-34.scale375Height())
  114. make.height.equalTo(40.scale375Height())
  115. make.width.equalTo(167.scale375())
  116. }
  117. allAgreeButton.snp.makeConstraints { make in
  118. make.trailing.equalTo(applyTableView)
  119. make.bottom.height.width.equalTo(allRejectButton)
  120. }
  121. }
  122. func bindInteraction() {
  123. viewModel.viewResponder = self
  124. allAgreeButton.addTarget(self, action: #selector(allAgreeStageAction(sender:)), for: .touchUpInside)
  125. allRejectButton.addTarget(self, action: #selector(allRejectAction(sender:)), for: .touchUpInside)
  126. setupPlaceholderViewState(isShown: viewModel.isPlaceholderViewShown)
  127. setupApplyButtonState(isEnabled: viewModel.isApplyButtonEnabled)
  128. }
  129. @objc func allAgreeStageAction(sender: UIButton) {
  130. viewModel.respondAllRequest(isAgree: true)
  131. }
  132. @objc func allRejectAction(sender: UIButton) {
  133. viewModel.respondAllRequest(isAgree: false)
  134. }
  135. private func setupPlaceholderViewState(isShown: Bool) {
  136. placeholderLabel.isHidden = !isShown
  137. placeholderUIImageView.isHidden = !isShown
  138. applyTableView.isHidden = isShown
  139. }
  140. private func setupApplyButtonState(isEnabled: Bool) {
  141. allAgreeButton.isEnabled = isEnabled
  142. allRejectButton.isEnabled = isEnabled
  143. }
  144. deinit {
  145. debugPrint("deinit \(self)")
  146. }
  147. }
  148. extension RaiseHandApplicationListView: UITableViewDataSource {
  149. internal func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  150. return viewModel.inviteSeatList.count
  151. }
  152. }
  153. extension RaiseHandApplicationListView: UITableViewDelegate {
  154. internal func tableView(_ tableView: UITableView,
  155. cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  156. let attendeeModel = viewModel.inviteSeatList[indexPath.row]
  157. let cell = RaiseHandApplicationCell(attendeeModel: attendeeModel, viewModel: viewModel)
  158. cell.selectionStyle = .none
  159. return cell
  160. }
  161. internal func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  162. return 60.scale375()
  163. }
  164. }
  165. extension RaiseHandApplicationListView: RaiseHandApplicationListViewResponder {
  166. func updateApplyButtonState(isEnabled: Bool) {
  167. setupApplyButtonState(isEnabled: isEnabled)
  168. }
  169. func updatePlaceholderViewState(isShown: Bool) {
  170. setupPlaceholderViewState(isShown: isShown)
  171. }
  172. func reloadApplyListView() {
  173. applyTableView.reloadData()
  174. }
  175. func makeToast(text: String) {
  176. RoomRouter.makeToastInCenter(toast: text, duration: 1)
  177. }
  178. }
  179. private extension String {
  180. static var takeSeatApplyTitle: String {
  181. localized("Participants apply to come on stage")
  182. }
  183. static var rejectAllText: String {
  184. localized("Reject all")
  185. }
  186. static var noMemberApplicationText: String {
  187. localized("No participants's application yet")
  188. }
  189. static var agreeAllText: String {
  190. localized("Agree to all")
  191. }
  192. }