MoviaBox/ShortPlay/Class/MyList/Controller/SPPlayHistoryViewController.swift
2025-04-19 09:20:15 +08:00

106 lines
2.9 KiB
Swift

//
// SPPlayHistoryViewController.swift
// ShortPlay
//
// Created by on 2025/4/19.
//
import UIKit
class SPPlayHistoryViewController: SPViewController {
private lazy var dataArr: [SPShortModel] = []
private var page: Int?
//MARK: UI
private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
let itemWidth = floor((kSPScreenWidth - 30 - 9 * 2) / 3)
let itemHeight = 146 / 109 * itemWidth + 36
let layout = UICollectionViewFlowLayout()
layout.itemSize = .init(width: itemWidth, height: itemHeight)
layout.minimumLineSpacing = 10
layout.minimumInteritemSpacing = 9
layout.sectionInset = .init(top: 10, left: 15, bottom: 0, right: 15)
return layout
}()
private lazy var collectionView: SPCollectionView = {
let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
collectionView.delegate = self
collectionView.dataSource = self
SPCollectListCell.registerCell(collectionView: collectionView)
return collectionView
}()
override func viewDidLoad() {
super.viewDidLoad()
requestDataList(page: 1, completer: nil)
_setupUI()
}
override func setBgImageView() { }
}
extension SPPlayHistoryViewController {
private func _setupUI() {
view.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.top.equalToSuperview().offset(10)
}
}
}
//MARK: -------------- UICollectionViewDelegate & UICollectionViewDataSource --------------
extension SPPlayHistoryViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = SPCollectListCell.dequeueReusableCell(collectionView: collectionView, indexPath: indexPath)
cell.model = dataArr[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.dataArr.count
}
}
extension SPPlayHistoryViewController {
private func requestDataList(page: Int, completer: (() -> Void)?) {
SPVideoAPI.requestCollectList(page: page) { [weak self] listModel in
guard let self = self else { return }
if let listModel = listModel, let list = listModel.list {
if page == 1 {
self.dataArr.removeAll()
}
self.dataArr += list
self.page = page
self.collectionView.reloadData()
}
completer?()
}
}
}