141 lines
4.2 KiB
Swift
141 lines
4.2 KiB
Swift
//
|
|
// BRVideoLockView.swift
|
|
// BeeReel
|
|
//
|
|
// Created by 长沙鸿瑶 on 2025/7/26.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class BRVideoLockView: UIView {
|
|
|
|
var clickUnlockButton: (() -> Void)?
|
|
|
|
var videoInfo: BRVideoInfoModel? {
|
|
didSet {
|
|
lockButton.setNeedsUpdateConfiguration()
|
|
}
|
|
}
|
|
|
|
var hasLastEpisodeUnlocked = false {
|
|
didSet {
|
|
lockButton.setNeedsUpdateConfiguration()
|
|
}
|
|
}
|
|
|
|
|
|
private lazy var lockIconView: UIImageView = {
|
|
let view = UIImageView(image: UIImage(named: "Frame 4"))
|
|
return view
|
|
}()
|
|
|
|
private lazy var bottomView: UIView = {
|
|
let view = UIImageView(image: UIImage(named: "bg"))
|
|
view.isUserInteractionEnabled = true
|
|
return view
|
|
}()
|
|
|
|
private lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontBold(ofSize: 18)
|
|
label.textColor = .colorFFFFFF()
|
|
label.text = "Unlock to Continue".localized
|
|
return label
|
|
}()
|
|
|
|
private lazy var lockButton: UIButton = {
|
|
var config = UIButton.Configuration.plain()
|
|
config.background.image = UIImage(named: "bg 1")
|
|
config.image = UIImage(named: "Frame 5")
|
|
config.imagePadding = 10
|
|
|
|
let button = UIButton(configuration: config)
|
|
button.configurationUpdateHandler = { [weak self] button in
|
|
guard let self = self else { return }
|
|
|
|
let title: String
|
|
if hasLastEpisodeUnlocked {
|
|
title = "beereel_video_lock_tip_text".localized
|
|
} else {
|
|
title = "Unlocking costs ## Coins".localizedReplace(text: "\(videoInfo?.coins ?? 0)")
|
|
}
|
|
|
|
|
|
button.configuration?.attributedTitle = AttributedString.br_createAttributedString(string: title, color: .color1C1C1C(), font: .fontRegular(ofSize: 14))
|
|
}
|
|
button.addTarget(self, action: #selector(handleUnlockButton), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
private lazy var totalCoinsLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 12)
|
|
label.textColor = .colorB5B5B5()
|
|
return label
|
|
}()
|
|
|
|
deinit {
|
|
NotificationCenter.default.removeObserver(self)
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
backgroundColor = .color000000(alpha: 0.4)
|
|
NotificationCenter.default.addObserver(self, selector: #selector(updateUserInfo), name: BRLoginManager.userInfoUpdateNotification, object: nil)
|
|
|
|
updateUserInfo()
|
|
br_setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
@objc private func updateUserInfo() {
|
|
let userInfo = BRLoginManager.manager.userInfo
|
|
totalCoinsLabel.text = "Balance: ## Coins".localizedReplace(text: "\(userInfo?.totalCoin ?? 0)")
|
|
}
|
|
|
|
@objc private func handleUnlockButton() {
|
|
self.clickUnlockButton?()
|
|
}
|
|
}
|
|
|
|
extension BRVideoLockView {
|
|
|
|
private func br_setupUI() {
|
|
addSubview(lockIconView)
|
|
addSubview(bottomView)
|
|
bottomView.addSubview(titleLabel)
|
|
bottomView.addSubview(lockButton)
|
|
bottomView.addSubview(totalCoinsLabel)
|
|
|
|
lockIconView.snp.makeConstraints { make in
|
|
make.center.equalToSuperview()
|
|
}
|
|
|
|
bottomView.snp.makeConstraints { make in
|
|
make.left.right.bottom.equalToSuperview()
|
|
make.height.equalTo(UIScreen.tabbarSafeBottomMargin + 222)
|
|
}
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalToSuperview().offset(26)
|
|
}
|
|
|
|
lockButton.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.centerY.equalToSuperview()
|
|
make.width.equalTo(260)
|
|
make.height.equalTo(48)
|
|
}
|
|
|
|
totalCoinsLabel.snp.makeConstraints { make in
|
|
make.centerX.equalToSuperview()
|
|
make.bottom.equalToSuperview().offset(-(UIScreen.tabbarSafeBottomMargin + 10))
|
|
}
|
|
}
|
|
|
|
}
|