LNRoomProfileBottomMenu.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // LNRoomProfileBottomMenu.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/3/16.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. protocol LNRoomProfileBottomMenuDelete: NSObject {
  11. func onRoomProfileBottomMenuRequestToDismiss()
  12. }
  13. class LNRoomProfileBottomMenu: UIView {
  14. private let follow = UIButton()
  15. private let chat = UIButton()
  16. private let gift = UIButton()
  17. private var curUid: String?
  18. private var isFollow: Bool = false {
  19. didSet {
  20. if isFollow {
  21. follow.setTitle(.init(key: "A00026"), for: .normal)
  22. follow.setTitleColor(.text_1.withAlphaComponent(0.2), for: .normal)
  23. follow.titleLabel?.font = .body_l
  24. } else {
  25. follow.setTitle(.init(key: "A00225"), for: .normal)
  26. follow.setTitleColor(.text_1, for: .normal)
  27. follow.titleLabel?.font = .body_l
  28. }
  29. }
  30. }
  31. weak var delegate: LNRoomProfileBottomMenuDelete?
  32. override init(frame: CGRect) {
  33. super.init(frame: frame)
  34. let stackView = UIStackView()
  35. stackView.axis = .horizontal
  36. stackView.alignment = .fill
  37. stackView.distribution = .fillEqually
  38. addSubview(stackView)
  39. stackView.snp.makeConstraints { make in
  40. make.horizontalEdges.equalToSuperview()
  41. make.top.equalToSuperview().offset(9)
  42. make.height.equalTo(48)
  43. make.bottom.equalToSuperview()
  44. }
  45. follow.setTitle(.init(key: "A00225"), for: .normal)
  46. follow.setTitleColor(.text_1, for: .normal)
  47. follow.titleLabel?.font = .body_l
  48. follow.addAction(UIAction(handler: { [weak self] _ in
  49. guard let self else { return }
  50. guard let curUid else { return }
  51. if isFollow {
  52. LNCommonAlertView.showUnfollowAlert(uid: curUid)
  53. } else {
  54. LNRelationManager.shared.operateFollow(uid: curUid, follow: true, handler: nil)
  55. }
  56. }), for: .touchUpInside)
  57. stackView.addArrangedSubview(follow)
  58. addSeperator(follow)
  59. chat.setTitle(.init(key: "A00042"), for: .normal)
  60. chat.setTitleColor(.text_1, for: .normal)
  61. chat.titleLabel?.font = .body_l
  62. chat.addAction(UIAction(handler: { [weak self] _ in
  63. guard let self else { return }
  64. guard let curUid else { return }
  65. delegate?.onRoomProfileBottomMenuRequestToDismiss()
  66. pushToChat(uid: curUid)
  67. }), for: .touchUpInside)
  68. stackView.addArrangedSubview(chat)
  69. // addSeperator(chat)
  70. //
  71. // gift.setTitle(.init(key: "A00336"), for: .normal)
  72. // gift.setTitleColor(.text_6, for: .normal)
  73. // gift.titleLabel?.font = .body_l
  74. // stackView.addArrangedSubview(gift)
  75. LNEventDeliver.addObserver(self)
  76. }
  77. func update(_ uid: String) {
  78. curUid = uid
  79. if uid.isMyUid {
  80. isHidden = true
  81. return
  82. }
  83. LNRelationManager.shared.getRelationWithUser(uid: uid, handler: nil)
  84. }
  85. required init?(coder: NSCoder) {
  86. fatalError("init(coder:) has not been implemented")
  87. }
  88. private func addSeperator(_ view: UIView) {
  89. let sep = UIView()
  90. sep.backgroundColor = .text_3
  91. view.addSubview(sep)
  92. sep.snp.makeConstraints { make in
  93. make.width.equalTo(1)
  94. make.height.equalTo(12)
  95. make.centerY.equalToSuperview()
  96. make.trailing.equalToSuperview()
  97. }
  98. }
  99. }
  100. extension LNRoomProfileBottomMenu: LNRelationManagerNotify {
  101. func onUserRelationChanged(uid: String, relation: LNUserRelationShip) {
  102. guard uid == curUid else { return }
  103. isFollow = relation.contains(.followed)
  104. }
  105. }