262 lines
8.7 KiB
Swift
262 lines
8.7 KiB
Swift
//
|
|
// NRCoinsPackClaimCell.swift
|
|
// ReaderHive
|
|
//
|
|
// Created by 澜声世纪 on 2025/12/12.
|
|
//
|
|
|
|
import UIKit
|
|
import SnapKit
|
|
import YYText
|
|
|
|
class NRCoinsPackClaimCell: UICollectionViewCell {
|
|
|
|
var clickClaimButton: ((_ id: String?) -> Void)?
|
|
|
|
var model: NRCoinsPackReceiveModel? {
|
|
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 = ._714_A_1_B
|
|
titleAtt.yy_font = .font(ofSize: 14, weight: .bold)
|
|
|
|
let day = "d".localized
|
|
let dayAtt = NSMutableAttributedString(string: " (\(day) \(model?.day_text ?? ""))")
|
|
dayAtt.yy_color = ._946_A_37
|
|
dayAtt.yy_font = .font(ofSize: 14, weight: .regular)
|
|
titleAtt.append(dayAtt)
|
|
|
|
titleLabel.attributedText = titleAtt
|
|
|
|
}
|
|
}
|
|
|
|
private lazy var bgView: UIView = {
|
|
let view = UIImageView(image: UIImage(named: "bg_image_07"))
|
|
view.layer.cornerRadius = 12
|
|
view.layer.masksToBounds = true
|
|
view.layer.borderWidth = 1
|
|
view.layer.borderColor = UIColor.black.withAlphaComponent(0.05).cgColor
|
|
return view
|
|
}()
|
|
|
|
private lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.numberOfLines = 0
|
|
return label
|
|
}()
|
|
|
|
private lazy var lineView1: UIView = {
|
|
let view = NRDashedLineView()
|
|
view.direction = .horizontal
|
|
return view
|
|
}()
|
|
|
|
private lazy var lineView2: UIView = {
|
|
let view = NRDashedLineView()
|
|
view.direction = .vertical
|
|
return view
|
|
}()
|
|
|
|
private lazy var coinsView1: CoinsView = {
|
|
let view = CoinsView()
|
|
view.title = "reader_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 = NRGradientButton(configuration: config, primaryAction: UIAction(handler: { [weak self] _ in
|
|
guard let self = self else { return }
|
|
self.clickClaimButton?(self.model?.id)
|
|
}))
|
|
button.layer.masksToBounds = true
|
|
button.layer.cornerRadius = 24
|
|
button.layer.borderWidth = 1
|
|
|
|
button.startPoint = .init(x: 0, y: 0.5)
|
|
button.endPoint = .init(x: 1, y: 0.5)
|
|
button.configurationUpdateHandler = { [weak self] button in
|
|
guard let self = self else { return }
|
|
guard let button = button as? NRGradientButton else { return }
|
|
|
|
if button.isEnabled {
|
|
button.colors = [UIColor.white.cgColor, UIColor.FDE_9_CB.cgColor]
|
|
button.layer.borderColor = UIColor.black.withAlphaComponent(0.15).cgColor
|
|
|
|
let coinImage = UIImage(named: "coins_icon_01")!
|
|
let coinText = NSTextAttachment(image: coinImage)
|
|
coinText.bounds = .init(x: 0, y: -3, 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._946_A_37.withAlphaComponent(0.5)
|
|
]))
|
|
|
|
|
|
button.configuration?.attributedTitle = AttributedString("reader_claim".localized, attributes: AttributeContainer([
|
|
.font : UIFont.font(ofSize: 14, weight: .bold),
|
|
.foregroundColor : UIColor._714_A_1_B
|
|
]))
|
|
|
|
button.configuration?.attributedSubtitle = coinAtt + countAtt
|
|
|
|
} else {
|
|
button.colors = [UIColor.E_0_E_0_E_0.cgColor, UIColor.E_0_E_0_E_0.cgColor]
|
|
button.layer.borderColor = UIColor.clear.cgColor
|
|
|
|
button.configuration?.attributedTitle = AttributedString("reader_claimed".localized, attributes: AttributeContainer([
|
|
.font : UIFont.font(ofSize: 14, weight: .bold),
|
|
.foregroundColor : UIColor.black.withAlphaComponent(0.25)
|
|
]))
|
|
|
|
button.configuration?.attributedSubtitle = nil
|
|
}
|
|
|
|
|
|
}
|
|
return button
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
nr_setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
}
|
|
|
|
extension NRCoinsPackClaimCell {
|
|
|
|
private func nr_setupUI() {
|
|
contentView.addSubview(bgView)
|
|
contentView.addSubview(titleLabel)
|
|
contentView.addSubview(lineView1)
|
|
contentView.addSubview(lineView2)
|
|
contentView.addSubview(coinsView1)
|
|
contentView.addSubview(coinsView2)
|
|
contentView.addSubview(claimButton)
|
|
|
|
bgView.snp.makeConstraints { make in
|
|
make.edges.equalToSuperview()
|
|
}
|
|
|
|
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(-17)
|
|
}
|
|
|
|
lineView2.snp.makeConstraints { make in
|
|
make.centerY.equalTo(coinsView1)
|
|
make.left.equalTo(coinsView1.snp.right).offset(12)
|
|
make.height.equalTo(32)
|
|
}
|
|
|
|
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 NRCoinsPackClaimCell {
|
|
|
|
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 = ._946_A_37
|
|
return label
|
|
}()
|
|
|
|
private lazy var iconImageView = UIImageView(image: UIImage(named: "coins_icon_01"))
|
|
|
|
private lazy var coinsLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 14, weight: .bold)
|
|
label.textColor = ._946_A_37
|
|
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")
|
|
}
|
|
}
|
|
|
|
}
|