140 lines
4.4 KiB
Swift
140 lines
4.4 KiB
Swift
//
|
|
// SPMinePlayHistoryView.swift
|
|
// Thimra
|
|
//
|
|
// Created by Overseas on 2025/4/23.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPMinePlayHistoryView: UIView {
|
|
|
|
var contentHeight: CGFloat {
|
|
return 8 + collectionViewLayout.itemSize.height + 20 + 12
|
|
}
|
|
|
|
override var intrinsicContentSize: CGSize {
|
|
return CGSize(width: kSPScreenWidth, height: contentHeight)
|
|
}
|
|
|
|
var dataArr: [SPShortModel]? {
|
|
didSet {
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
//MARK: UI属性
|
|
private lazy var titleIconImageView: UIImageView = {
|
|
let imageView = UIImageView(image: UIImage(named: "history_icon_01"))
|
|
return imageView
|
|
}()
|
|
|
|
private lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontMedium(ofSize: 16)
|
|
label.textColor = .colorFFFFFF()
|
|
label.text = "Watch History".localized
|
|
return label
|
|
}()
|
|
|
|
private lazy var moreButton: UIButton = {
|
|
let button = UIButton(type: .custom)
|
|
button.setImage(UIImage(named: "arrow_right_icon_02"), for: .normal)
|
|
button.addTarget(self, action: #selector(handleMoreButton), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
let width = floor((kSPScreenWidth - 32 - 16) / 3)
|
|
let height = 145 / 109 * width + 58
|
|
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.itemSize = CGSize(width: width, height: height)
|
|
layout.minimumLineSpacing = 8
|
|
layout.minimumInteritemSpacing = 8
|
|
layout.sectionInset = .init(top: 0, left: 16, bottom: 0, right: 16)
|
|
return layout
|
|
}()
|
|
|
|
private lazy var collectionView: SPCollectionView = {
|
|
let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
collectionView.isScrollEnabled = false
|
|
SPMinePlayHistoryCell.registerCell(collectionView: collectionView)
|
|
return collectionView
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
_setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
@objc private func handleMoreButton() {
|
|
SPAPPTool.mainTabBarController?.onPlayHistory()
|
|
}
|
|
|
|
}
|
|
|
|
extension SPMinePlayHistoryView {
|
|
|
|
private func _setupUI() {
|
|
addSubview(titleIconImageView)
|
|
addSubview(titleLabel)
|
|
addSubview(moreButton)
|
|
addSubview(collectionView)
|
|
|
|
titleIconImageView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(16)
|
|
make.top.equalToSuperview().offset(8)
|
|
}
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.centerY.equalTo(titleIconImageView)
|
|
make.left.equalTo(titleIconImageView.snp.right).offset(12)
|
|
}
|
|
|
|
moreButton.snp.makeConstraints { make in
|
|
make.centerY.equalTo(titleIconImageView)
|
|
make.right.equalToSuperview().offset(-3)
|
|
make.width.equalTo(40)
|
|
make.height.equalTo(40)
|
|
}
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.left.right.bottom.equalToSuperview()
|
|
make.height.equalTo(self.collectionViewLayout.itemSize.height)
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: -------------- UICollectionViewDelegate & UICollectionViewDataSource --------------
|
|
extension SPMinePlayHistoryView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = SPMinePlayHistoryCell.dequeueReusableCell(collectionView: collectionView, indexPath: indexPath)
|
|
cell.model = self.dataArr?[indexPath.row]
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return dataArr?.count ?? 0
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
let model = self.dataArr?[indexPath.row]
|
|
|
|
let vc = SPPlayerDetailViewController()
|
|
vc.shortPlayId = model?.short_play_id
|
|
vc.playHistoryModel = model
|
|
self.viewController?.navigationController?.pushViewController(vc, animated: true)
|
|
}
|
|
}
|