134 lines
4.3 KiB
Swift
134 lines
4.3 KiB
Swift
//
|
|
// SRStoreVipView.swift
|
|
// SynthReel
|
|
//
|
|
// Created by CSGY on 2025/12/2.
|
|
// Copyright © 2025 SR. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SRStoreVipView: UIView {
|
|
var dataArr: [SRPayItem] = [] {
|
|
didSet {
|
|
collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var shortPlayId: String?
|
|
var videoId: String?
|
|
|
|
var buyFinishHandle: (() -> Void)?
|
|
|
|
private lazy var viptitleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 12, weight: .medium)
|
|
label.textColor = .white
|
|
label.text = "synthreel_viptitle".localized
|
|
return label
|
|
}()
|
|
|
|
private lazy var collectionViewLayout: UICollectionViewCompositionalLayout = {
|
|
|
|
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1)))
|
|
|
|
let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(90)), subitems: [item])
|
|
|
|
let layoutSection = NSCollectionLayoutSection(group: group)
|
|
layoutSection.interGroupSpacing = 10
|
|
layoutSection.contentInsets = .init(top: 0, leading: 16, bottom: 0, trailing: 16)
|
|
|
|
|
|
let config = UICollectionViewCompositionalLayoutConfiguration()
|
|
|
|
let layout = UICollectionViewCompositionalLayout(section: layoutSection)
|
|
layout.configuration = config
|
|
|
|
return layout
|
|
}()
|
|
|
|
private lazy var collectionView: SRCollectionView = {
|
|
let collectionView = SRCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
collectionView.isScrollEnabled = false
|
|
collectionView.addObserver(self, forKeyPath: "contentSize", context: nil)
|
|
collectionView.register(SRStoreVipCell.self, forCellWithReuseIdentifier: "cell")
|
|
return collectionView
|
|
}()
|
|
|
|
deinit {
|
|
collectionView.removeObserver(self, forKeyPath: "contentSize")
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
fa_setupLayout()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
|
if keyPath == "contentSize" {
|
|
let height = self.collectionView.contentSize.height + 1
|
|
self.collectionView.snp.updateConstraints { make in
|
|
make.height.equalTo(height)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension SRStoreVipView {
|
|
|
|
private func fa_setupLayout() {
|
|
addSubview(viptitleLabel)
|
|
addSubview(collectionView)
|
|
|
|
viptitleLabel.snp.makeConstraints { make in
|
|
make.top.equalToSuperview()
|
|
make.left.equalTo(12)
|
|
}
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.top.equalTo(viptitleLabel.snp.bottom).offset(10)
|
|
make.left.right.bottom.equalToSuperview()
|
|
make.height.equalTo(1)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//MARK: UICollectionViewDelegate UICollectionViewDataSource
|
|
extension SRStoreVipView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! SRStoreVipCell
|
|
cell.item = self.dataArr[indexPath.row]
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return dataArr.count
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
let model = self.dataArr[indexPath.row]
|
|
|
|
SRIapManager.manager.start(model: model, shortPlayId: self.shortPlayId, videoId: self.videoId) { [weak self] finish in
|
|
guard let self = self else { return }
|
|
if finish {
|
|
Task {
|
|
await SRAccountManager.manager.updateUserInfo()
|
|
self.buyFinishHandle?()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|