This commit is contained in:
zeng 2026-01-13 17:39:24 +08:00
parent 49c3b9b3c9
commit f903e4cfae

View File

@ -7,15 +7,16 @@
import UIKit
import SnapKit
import YYText
class FAPayRetainAlert: FABaseAlert {
var model: FAPayDateModel? {
didSet {
self.collectionView.reloadData()
self.titleLabel.text = model?.retrieve_lang?.title
self.countdownView.model = model
bonusTagView.update(text: model?.retrieve_lang?.subtitle ?? "")
}
}
@ -163,7 +164,11 @@ extension FAPayRetainAlert {
suffixLabel.text = model?.retrieve_lang?.miss_out
}
}
private static let defaultCountdownSeconds = 4 * 60 * 60
private var countdownTimer: Timer?
private var remainingSeconds: Int = 0
private let prefixLabel = UILabel()
private let suffixLabel = UILabel()
private let timeStackView = UIStackView()
@ -178,6 +183,10 @@ extension FAPayRetainAlert {
setupView()
}
deinit {
stopCountdown()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@ -191,6 +200,15 @@ extension FAPayRetainAlert {
secondView.setText(countdown.seconds)
}
override func didMoveToWindow() {
super.didMoveToWindow()
if window != nil {
startCountdown()
} else {
stopCountdown()
}
}
private func setupView() {
let mainStack = UIStackView()
mainStack.axis = .horizontal
@ -231,6 +249,42 @@ extension FAPayRetainAlert {
}
}
// 4
private func startCountdown() {
stopCountdown()
remainingSeconds = Self.defaultCountdownSeconds
updateTimeLabels()
countdownTimer = Timer.scheduledTimer(timeInterval: 1,
target: YYTextWeakProxy(target: self),
selector: #selector(handleCountdownTimer),
userInfo: nil,
repeats: true)
}
private func stopCountdown() {
countdownTimer?.invalidate()
countdownTimer = nil
}
@objc private func handleCountdownTimer() {
guard remainingSeconds > 0 else {
updateTimeLabels()
stopCountdown()
return
}
remainingSeconds -= 1
updateTimeLabels()
}
private func updateTimeLabels() {
let hours = remainingSeconds / 3600
let minutes = (remainingSeconds % 3600) / 60
let seconds = remainingSeconds % 60
hourView.setText(String(format: "%02d", hours))
minuteView.setText(String(format: "%02d", minutes))
secondView.setText(String(format: "%02d", seconds))
}
private final class TimeBoxView: UIView {
private let label = UILabel()
@ -298,17 +352,17 @@ extension FAPayRetainAlert {
addSubview(leftStar)
addSubview(rightStar)
addSubview(titleLabel)
leftStar.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalToSuperview().offset(8)
}
titleLabel.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalTo(leftStar.snp.right).offset(5)
}
rightStar.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalTo(titleLabel.snp.right).offset(5)
@ -360,7 +414,7 @@ final class FAPayRetainPackCell: UICollectionViewCell {
func configure(with item: FAPayItem?, isSelected: Bool) {
selectedBorderView.isHidden = !isSelected
guard let item = item else { return }
coinLabel.text = "\(item.coins ?? 0)"
bonusLabel.text = "+\((item.ext_info?.max_total_coins_pop ?? 0) - (item.ext_info?.max_total_coins ?? 0)) " + "fableon_free_coins".localized
priceLabel.text = "\(item.currency ?? "")\(item.price ?? "")"
@ -387,7 +441,7 @@ final class FAPayRetainPackCell: UICollectionViewCell {
bonusLabel.font = .font(ofSize: 12, weight: .medium)
bonusLabel.textColor = .FFFFFF
priceLabel.font = .font(ofSize: 22, weight: .bold)
priceLabel.textColor = .FFFFFF
@ -399,7 +453,7 @@ final class FAPayRetainPackCell: UICollectionViewCell {
contentView.addSubview(bgView)
contentView.addSubview(selectedBorderView)
bgView.addSubview(coinStack)
bgView.addSubview(bonusLabel)
bgView.addSubview(priceView)