LNRoomProfileBottomMenu.swift 3.9 KB

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