Fableon/Fableon/Object/Class/Me/V/FACoinsPackClaimListCell.swift
湖北秦九 e0163dabe3 1
2025-10-31 13:36:20 +08:00

281 lines
9.8 KiB
Swift

//
// FACoinsPackClaimListCell.swift
// Fableon
//
// Created by on 2025/10/29.
//
import UIKit
import YYText
class FACoinsPackClaimListCell: UICollectionViewCell {
var clickClaimButton: ((_ id: String?) -> Void)?
var model: FACoinsPackReceiveModel? {
didSet {
coinsView1.coins = model?.week_max_total
coinsView2.coins = model?.week_remaining_total
claimButton.isEnabled = (model?.receive_coins ?? 0) > 0
claimButton.setNeedsUpdateConfiguration()
let titleAtt = NSMutableAttributedString(string: "\(model?.title ?? "")")
titleAtt.yy_color = .FFFFFF
titleAtt.yy_font = .font(ofSize: 14, weight: .bold)
let dayAtt = NSMutableAttributedString(string: " (Day \(model?.day_text ?? ""))")
dayAtt.yy_color = ._20_A_1_FF
dayAtt.yy_font = .font(ofSize: 14, weight: .regular)
titleAtt.append(dayAtt)
titleLabel.attributedText = titleAtt
}
}
private lazy var bgView: FAGradientView = {
let view = FAGradientView()
view.fa_colors = [UIColor._524_B_8_E.cgColor, UIColor._303265.cgColor]
view.fa_locations = [0, 1]
view.fa_startPoint = .init(x: 0, y: 0.5)
view.fa_endPoint = .init(x: 1, y: 0.5)
view.layer.cornerRadius = 12
view.layer.masksToBounds = true
view.layer.borderWidth = 1
view.layer.borderColor = UIColor.E_5_E_5_E_5.cgColor
return view
}()
private lazy var bgIconImageView1 = UIImageView(image: UIImage(named: "coin_attachment_01"))
private lazy var bgIconImageView2 = UIImageView(image: UIImage(named: "coin_attachment_03"))
private lazy var bgIconImageView4 = UIImageView(image: UIImage(named: "coin_attachment_04"))
private lazy var bgIconImageView5 = UIImageView(image: UIImage(named: "coin_attachment_05"))
private lazy var titleLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 0
return label
}()
private lazy var lineView1 = UIImageView(image: UIImage(named: "横间隔虚线"))
private lazy var lineView2 = UIImageView(image: UIImage(named: "间隔线"))
private lazy var coinsView1: CoinsView = {
let view = CoinsView()
view.title = "Total Reward".localized
return view
}()
private lazy var coinsView2: CoinsView = {
let view = CoinsView()
view.title = "Remaining".localized
return view
}()
private lazy var claimButton: UIButton = {
var config = UIButton.Configuration.plain()
config.titleAlignment = .center
let button = FAGradientButton(configuration: config, primaryAction: UIAction(handler: { [weak self] _ in
guard let self = self else { return }
self.clickClaimButton?(self.model?.id)
}))
button.layer.cornerRadius = 24
button.layer.masksToBounds = true
button.fa_locations = [0, 1]
button.fa_startPoint = .init(x: 0, y: 0.5)
button.fa_endPoint = .init(x: 1, y: 0.5)
button.configurationUpdateHandler = { [weak self] button in
guard let self = self else { return }
guard let button = button as? FAGradientButton else { return }
if button.isEnabled {
button.fa_colors = [UIColor._53_A_2_F_1.cgColor, UIColor.C_5_DDF_5.cgColor]
let coinImage = UIImage(named: "coins_icon_03")!
let coinText = NSTextAttachment(image: coinImage)
coinText.bounds = .init(x: 0, y: -2.5, width: coinImage.size.width, height: coinImage.size.height)
let coinAtt = AttributedString(NSAttributedString(attachment: coinText))
let countAtt = AttributedString(" \(self.model?.receive_coins ?? 0)", attributes: AttributeContainer([
.font : UIFont.font(ofSize: 12, weight: .bold),
.foregroundColor : UIColor._000000.withAlphaComponent(0.5)
]))
button.configuration?.attributedTitle = AttributedString("Claim".localized, attributes: AttributeContainer([
.font : UIFont.font(ofSize: 14, weight: .bold),
.foregroundColor : UIColor._114_CEE
]))
button.configuration?.attributedSubtitle = coinAtt + countAtt
} else {
button.fa_colors = [UIColor.BCBCBC.cgColor, UIColor.BCBCBC.cgColor]
button.configuration?.attributedTitle = AttributedString("Claim".localized, attributes: AttributeContainer([
.font : UIFont.font(ofSize: 14, weight: .bold),
.foregroundColor : UIColor.FFFFFF_0_8
]))
button.configuration?.attributedSubtitle = nil
}
}
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
fa_setupLayout()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension FACoinsPackClaimListCell {
private func fa_setupLayout() {
contentView.addSubview(bgView)
bgView.addSubview(bgIconImageView5)
bgView.addSubview(bgIconImageView4)
bgView.addSubview(bgIconImageView1)
bgView.addSubview(bgIconImageView2)
bgView.addSubview(titleLabel)
bgView.addSubview(lineView1)
bgView.addSubview(lineView2)
bgView.addSubview(coinsView1)
bgView.addSubview(coinsView2)
bgView.addSubview(claimButton)
bgView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
bgIconImageView1.snp.makeConstraints { make in
make.left.top.equalToSuperview()
}
bgIconImageView2.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.right.equalToSuperview().offset(-8)
}
bgIconImageView4.snp.makeConstraints { make in
make.top.equalToSuperview()
make.centerX.equalTo(bgIconImageView2)
}
bgIconImageView5.snp.makeConstraints { make in
make.bottom.equalToSuperview()
make.left.equalToSuperview().offset(0)
}
titleLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(12)
make.centerY.equalTo(self.bgView.snp.top).offset(25)
make.right.lessThanOrEqualToSuperview().offset(-12)
}
lineView1.snp.makeConstraints { make in
make.left.equalToSuperview().offset(12)
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(48)
}
coinsView1.snp.makeConstraints { make in
make.left.equalToSuperview().offset(12)
make.bottom.equalToSuperview().offset(-18)
}
lineView2.snp.makeConstraints { make in
make.centerY.equalTo(coinsView1)
make.left.equalTo(coinsView1.snp.right).offset(12)
}
coinsView2.snp.makeConstraints { make in
make.centerY.equalTo(coinsView1)
make.left.equalTo(lineView2.snp.right).offset(12)
}
claimButton.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-12)
make.centerY.equalTo(coinsView1)
make.height.equalTo(48)
make.width.equalTo(120)
}
}
}
extension FACoinsPackClaimListCell {
class CoinsView: UIView {
var title: String? {
didSet {
titleLabel.text = title
}
}
var coins: Int? {
didSet {
coinsLabel.text = "\(coins ?? 0)"
}
}
private lazy var titleLabel: UILabel = {
let label = UILabel()
label.font = .font(ofSize: 12, weight: .bold)
label.textColor = .DFEFFF
return label
}()
private lazy var iconImageView = UIImageView(image: UIImage(named: "coins_icon_03"))
private lazy var coinsLabel: UILabel = {
let label = FALabel()
label.font = .font(ofSize: 14, weight: .bold)
label.textColors = [UIColor.FFCE_63.cgColor, UIColor.FFE_1_AA.cgColor]
label.textStartPoint = .init(x: 0, y: 0.5)
label.textEndPoint = .init(x: 1, y: 0.5)
label.text = "0"
return label
}()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(titleLabel)
addSubview(iconImageView)
addSubview(coinsLabel)
titleLabel.snp.makeConstraints { make in
make.left.equalToSuperview()
make.top.equalToSuperview()
make.right.lessThanOrEqualToSuperview()
}
iconImageView.snp.makeConstraints { make in
make.left.equalToSuperview()
make.bottom.equalToSuperview()
make.top.equalTo(titleLabel.snp.bottom).offset(8)
}
coinsLabel.snp.makeConstraints { make in
make.centerY.equalTo(iconImageView)
make.left.equalTo(iconImageView.snp.right).offset(4)
make.right.lessThanOrEqualToSuperview()
}
}
@MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
}