| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- //
- // LNRoomProfileBottomMenu.swift
- // Gami
- //
- // Created by OneeChan on 2026/3/16.
- //
- import Foundation
- import UIKit
- import SnapKit
- protocol LNRoomProfileBottomMenuDelete: NSObject {
- func onRoomProfileBottomMenuRequestToDismiss()
- }
- class LNRoomProfileBottomMenu: UIView {
- private let follow = UIButton()
- private let chat = UIButton()
- private let gift = UIButton()
-
- private var curUid: String?
- private var isFollow: Bool = false {
- didSet {
- if isFollow {
- follow.setTitle(.init(key: "A00026"), for: .normal)
- follow.setTitleColor(.text_1.withAlphaComponent(0.2), for: .normal)
- follow.titleLabel?.font = .body_l
- } else {
- follow.setTitle(.init(key: "A00225"), for: .normal)
- follow.setTitleColor(.text_1, for: .normal)
- follow.titleLabel?.font = .body_l
- }
- }
- }
- weak var delegate: LNRoomProfileBottomMenuDelete?
-
- override init(frame: CGRect) {
- super.init(frame: frame)
-
- let stackView = UIStackView()
- stackView.axis = .horizontal
- stackView.alignment = .fill
- stackView.distribution = .fillEqually
- addSubview(stackView)
- stackView.snp.makeConstraints { make in
- make.horizontalEdges.equalToSuperview()
- make.top.equalToSuperview().offset(9)
- make.height.equalTo(48)
- make.bottom.equalToSuperview()
- }
-
- follow.setTitle(.init(key: "A00225"), for: .normal)
- follow.setTitleColor(.text_1, for: .normal)
- follow.titleLabel?.font = .body_l
- follow.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
- guard let curUid else { return }
- if isFollow {
- LNCommonAlertView.showUnfollowAlert(uid: curUid)
- } else {
- LNRelationManager.shared.operateFollow(uid: curUid, follow: true, handler: nil)
- }
- }), for: .touchUpInside)
- stackView.addArrangedSubview(follow)
- addSeperator(follow)
-
- chat.setTitle(.init(key: "A00042"), for: .normal)
- chat.setTitleColor(.text_1, for: .normal)
- chat.titleLabel?.font = .body_l
- chat.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
- guard let curUid else { return }
- delegate?.onRoomProfileBottomMenuRequestToDismiss()
- pushToChat(uid: curUid)
- }), for: .touchUpInside)
- stackView.addArrangedSubview(chat)
-
- // addSeperator(chat)
- //
- // gift.setTitle(.init(key: "A00336"), for: .normal)
- // gift.setTitleColor(.text_6, for: .normal)
- // gift.titleLabel?.font = .body_l
- // stackView.addArrangedSubview(gift)
-
- LNEventDeliver.addObserver(self)
- }
-
- func update(_ uid: String) {
- curUid = uid
-
- if uid.isMyUid {
- isHidden = true
- return
- }
- LNRelationManager.shared.getRelationWithUser(uid: uid, handler: nil)
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- private func addSeperator(_ view: UIView) {
- let sep = UIView()
- sep.backgroundColor = .text_3
- view.addSubview(sep)
- sep.snp.makeConstraints { make in
- make.width.equalTo(1)
- make.height.equalTo(12)
- make.centerY.equalToSuperview()
- make.trailing.equalToSuperview()
- }
- }
- }
- extension LNRoomProfileBottomMenu: LNRelationManagerNotify {
- func onUserRelationChanged(uid: String, relation: LNUserRelationShip) {
- guard uid == curUid else { return }
- isFollow = relation.contains(.followed)
- }
- }
|