169 lines
5.6 KiB
Swift
169 lines
5.6 KiB
Swift
//
|
|
// BRSpotlightHotCell.swift
|
|
// BeeReel
|
|
//
|
|
// Created by 长沙鸿瑶 on 2025/6/30.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class BRSpotlightHotCell: BRCollectionViewCell {
|
|
|
|
var model: BRShortModel? {
|
|
didSet {
|
|
coverImageView.br_setImage(url: model?.image_url)
|
|
titleLabel.text = model?.name
|
|
categoryLabel.text = model?.category?.first
|
|
|
|
// favoriteButton.isSelected = self.model?.is_collect ?? false
|
|
|
|
hotView.setNeedsUpdateConfiguration()
|
|
}
|
|
}
|
|
|
|
|
|
private lazy var coverImageView: BRImageView = {
|
|
let imageView = BRImageView()
|
|
return imageView
|
|
}()
|
|
|
|
private lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 12)
|
|
label.textColor = .color1C1C1C()
|
|
return label
|
|
}()
|
|
|
|
private lazy var playIconImageView: UIImageView = {
|
|
let imageView = UIImageView(image: UIImage(named: "play_icon_02"))
|
|
return imageView
|
|
}()
|
|
|
|
private lazy var categoryLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 10)
|
|
label.textColor = .color899D00()
|
|
return label
|
|
}()
|
|
|
|
private lazy var hotView: UIButton = {
|
|
var config = UIButton.Configuration.plain()
|
|
config.image = UIImage(named: "hot_icon_02")
|
|
config.imagePlacement = .leading
|
|
config.imagePadding = 2
|
|
config.contentInsets = .init(top: 0, leading: 0, bottom: 0, trailing: 0)
|
|
|
|
let button = UIButton(configuration: config)
|
|
button.isUserInteractionEnabled = false
|
|
button.configurationUpdateHandler = { [weak self] button in
|
|
guard let self = self else { return }
|
|
let count = model?.watch_total ?? 0
|
|
var string = "\(count)"
|
|
if count > 1000 {
|
|
string = String(format: "%.1fk", Float(count) / 1000)
|
|
}
|
|
button.configuration?.attributedTitle = AttributedString.br_createAttributedString(string: string, color: .colorFF7489(), font: .fontRegular(ofSize: 10))
|
|
|
|
}
|
|
return button
|
|
}()
|
|
|
|
// private lazy var favoriteButton: UIButton = {
|
|
// let button = UIButton(type: .custom)
|
|
// button.setImage(UIImage(named: "favorite_icon_01"), for: .normal)
|
|
// button.setImage(UIImage(named: "favorite_icon_01_selected"), for: .selected)
|
|
// button.setImage(UIImage(named: "favorite_icon_01_selected"), for: [.selected, .highlighted])
|
|
// button.addTarget(self, action: #selector(handleFavoriteButton), for: .touchUpInside)
|
|
// return button
|
|
// }()
|
|
|
|
|
|
// deinit {
|
|
// NotificationCenter.default.removeObserver(self)
|
|
// }
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
// NotificationCenter.default.addObserver(self, selector: #selector(updateShortFavoriteStateNotification), name: BRVideoAPI.updateShortFavoriteStateNotification, object: nil)
|
|
|
|
contentView.backgroundColor = .colorFFFFFF()
|
|
contentView.layer.cornerRadius = 10
|
|
contentView.layer.masksToBounds = true
|
|
|
|
br_setupUI()
|
|
}
|
|
|
|
@MainActor required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
|
|
// @objc private func handleFavoriteButton() {
|
|
// guard let shortPlayId = self.model?.short_play_id else { return }
|
|
//
|
|
// let isFavorite = !(self.model?.is_collect ?? false)
|
|
// let videoId = self.model?.short_play_video_id
|
|
//
|
|
// BRVideoAPI.requestFavorite(isFavorite: isFavorite, shortPlayId: shortPlayId, videoId: videoId) {
|
|
//
|
|
// }
|
|
// }
|
|
|
|
// @objc private func updateShortFavoriteStateNotification(sender: Notification) {
|
|
// guard let userInfo = sender.userInfo else { return }
|
|
// guard let shortPlayId = userInfo["id"] as? String else { return }
|
|
// guard let state = userInfo["state"] as? Bool else { return }
|
|
// guard shortPlayId == self.model?.short_play_id else { return }
|
|
//
|
|
// self.model?.is_collect = state;
|
|
//
|
|
// favoriteButton.isSelected = self.model?.is_collect ?? false
|
|
// }
|
|
|
|
}
|
|
|
|
extension BRSpotlightHotCell {
|
|
|
|
private func br_setupUI() {
|
|
contentView.addSubview(coverImageView)
|
|
// contentView.addSubview(favoriteButton)
|
|
contentView.addSubview(titleLabel)
|
|
contentView.addSubview(playIconImageView)
|
|
contentView.addSubview(categoryLabel)
|
|
contentView.addSubview(hotView)
|
|
|
|
coverImageView.snp.makeConstraints { make in
|
|
make.left.right.top.equalToSuperview()
|
|
make.height.equalTo(160)
|
|
}
|
|
|
|
// favoriteButton.snp.makeConstraints { make in
|
|
// make.top.equalToSuperview().offset(4)
|
|
// make.right.equalToSuperview().offset(-4)
|
|
// }
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(7)
|
|
make.right.lessThanOrEqualToSuperview().offset(-7)
|
|
make.top.equalTo(coverImageView.snp.bottom).offset(5)
|
|
}
|
|
|
|
playIconImageView.snp.makeConstraints { make in
|
|
make.right.equalToSuperview().offset(-4)
|
|
make.bottom.equalToSuperview().offset(-5)
|
|
}
|
|
|
|
categoryLabel.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(7)
|
|
make.top.equalTo(coverImageView.snp.bottom).offset(26)
|
|
}
|
|
|
|
hotView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(7)
|
|
make.bottom.equalToSuperview().offset(-8)
|
|
}
|
|
|
|
}
|
|
|
|
}
|