|
|
@@ -16,12 +16,21 @@ protocol LNRoomGiftHeaderViewDelegate: AnyObject {
|
|
|
|
|
|
|
|
|
class LNRoomGiftHeaderView: UIView {
|
|
|
- private let scrollView = UIScrollView()
|
|
|
+ private let roomSeatsView = UIScrollView()
|
|
|
private let stackView = UIStackView()
|
|
|
+
|
|
|
+ private let specifiedUserView = LNRoomGiftSpecifiedUserView()
|
|
|
+
|
|
|
private weak var roomSession: LNRoomViewModel?
|
|
|
private var headers: [LNRoomSeatNum: LNRoomGiftAvatarView] = [:]
|
|
|
var selection: [String] {
|
|
|
- headers.map { $1 }.filter { !$0.isHidden && $0.isSelected }.compactMap { $0.curSeatItem?.uid }
|
|
|
+ if !roomSeatsView.isHidden {
|
|
|
+ headers.map { $1 }.filter { !$0.isHidden && $0.isSelected }.compactMap { $0.curSeatItem?.uid }
|
|
|
+ } else if let uid = specifiedUserView.curUid {
|
|
|
+ [uid]
|
|
|
+ } else {
|
|
|
+ []
|
|
|
+ }
|
|
|
}
|
|
|
weak var delegate: LNRoomGiftHeaderViewDelegate?
|
|
|
|
|
|
@@ -34,7 +43,20 @@ class LNRoomGiftHeaderView: UIView {
|
|
|
|
|
|
func update(_ room: LNRoomViewModel?, selectedUid: String?) {
|
|
|
roomSession = room
|
|
|
- onRoomSeatsChanged()
|
|
|
+ if selectedUid == nil
|
|
|
+ || room?.seatsInfo.contains(where: { $0.uid == selectedUid }) == true {
|
|
|
+ onRoomSeatsChanged()
|
|
|
+
|
|
|
+ roomSeatsView.isHidden = false
|
|
|
+ specifiedUserView.isHidden = true
|
|
|
+ } else {
|
|
|
+ roomSeatsView.isHidden = true
|
|
|
+ specifiedUserView.isHidden = false
|
|
|
+ }
|
|
|
+ if let selectedUid {
|
|
|
+ headers.first { $1.curSeatItem?.uid == selectedUid }?.value.isSelected = true
|
|
|
+ specifiedUserView.update(selectedUid)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
@@ -85,21 +107,40 @@ private extension LNRoomGiftHeaderView {
|
|
|
make.centerY.equalToSuperview()
|
|
|
}
|
|
|
|
|
|
- scrollView.showsHorizontalScrollIndicator = false
|
|
|
- addSubview(scrollView)
|
|
|
- scrollView.snp.makeConstraints { make in
|
|
|
+ let roomSeatsView = buildRoomSeatsView()
|
|
|
+ addSubview(roomSeatsView)
|
|
|
+ roomSeatsView.snp.makeConstraints { make in
|
|
|
make.leading.equalTo(titleLabel.snp.trailing).offset(6)
|
|
|
make.trailing.equalToSuperview().offset(-10)
|
|
|
make.verticalEdges.equalToSuperview()
|
|
|
make.height.equalTo(40)
|
|
|
}
|
|
|
|
|
|
+ let userView = buildSpecifiedUserView()
|
|
|
+ addSubview(userView)
|
|
|
+ userView.snp.makeConstraints { make in
|
|
|
+ make.leading.equalTo(titleLabel.snp.trailing).offset(6)
|
|
|
+ make.trailing.equalToSuperview().offset(-10)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildRoomSeatsView() -> UIView {
|
|
|
+ roomSeatsView.showsHorizontalScrollIndicator = false
|
|
|
+
|
|
|
stackView.axis = .horizontal
|
|
|
- scrollView.addSubview(stackView)
|
|
|
+ roomSeatsView.addSubview(stackView)
|
|
|
stackView.snp.makeConstraints { make in
|
|
|
make.edges.equalToSuperview()
|
|
|
make.height.equalToSuperview()
|
|
|
}
|
|
|
+
|
|
|
+ return roomSeatsView
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildSpecifiedUserView() -> UIView {
|
|
|
+
|
|
|
+ return specifiedUserView
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -185,3 +226,63 @@ private class LNRoomGiftAvatarView: UIView {
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+private class LNRoomGiftSpecifiedUserView: UIView {
|
|
|
+ private let nameLabel = UILabel()
|
|
|
+ private let avatar = UIImageView()
|
|
|
+ private(set) var curUid: String?
|
|
|
+
|
|
|
+ override init(frame: CGRect) {
|
|
|
+ super.init(frame: frame)
|
|
|
+
|
|
|
+ let avatarBg = UIView()
|
|
|
+ avatarBg.backgroundColor = .clear
|
|
|
+ avatarBg.layer.cornerRadius = 17
|
|
|
+ avatarBg.layer.borderWidth = 1
|
|
|
+ avatarBg.layer.borderColor = UIColor.primary_4.cgColor
|
|
|
+ addSubview(avatarBg)
|
|
|
+ avatarBg.snp.makeConstraints { make in
|
|
|
+ make.width.height.equalTo(34)
|
|
|
+ make.leading.equalToSuperview()
|
|
|
+ make.verticalEdges.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ avatar.layer.cornerRadius = 15
|
|
|
+ avatar.clipsToBounds = true
|
|
|
+ avatar.contentMode = .scaleAspectFill
|
|
|
+ avatarBg.addSubview(avatar)
|
|
|
+ avatar.snp.makeConstraints { make in
|
|
|
+ make.center.equalToSuperview()
|
|
|
+ make.width.height.equalTo(30)
|
|
|
+ }
|
|
|
+
|
|
|
+ nameLabel.font = .body_s
|
|
|
+ nameLabel.textColor = .text_1
|
|
|
+ addSubview(nameLabel)
|
|
|
+ nameLabel.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.leading.equalTo(avatarBg.snp.trailing).offset(5)
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func update(_ uid: String?) {
|
|
|
+ curUid = uid
|
|
|
+ guard let uid, !uid.isEmpty else {
|
|
|
+ isHidden = true
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ LNProfileManager.shared.getCachedProfileUserInfo(uid: uid, fetchIfNeeded: true)
|
|
|
+ { [weak self] info in
|
|
|
+ guard let self else { return }
|
|
|
+ guard let info, info.uid == curUid else { return }
|
|
|
+ nameLabel.text = info.name
|
|
|
+ avatar.sd_setImage(with: URL(string: info.avatar))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+}
|