124 lines
3.7 KiB
Swift
124 lines
3.7 KiB
Swift
//
|
|
// SPHomeChildController.swift
|
|
// MoviaBox
|
|
//
|
|
// Created by 曾觉新 on 2025/4/14.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPHomeChildController: SPViewController, WMZPageProtocol {
|
|
|
|
|
|
lazy var page = 1
|
|
lazy var dataArr: [SPShortModel] = []
|
|
|
|
|
|
private lazy var layout: UICollectionViewFlowLayout = {
|
|
let width = floor((kSPScreenWidth - 32 - 13) / 2)
|
|
let height = 221 / 165 * width + 44
|
|
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.itemSize = CGSize(width: width, height: height)
|
|
layout.sectionInset = .init(top: 0, left: 16, bottom: 0, right: 16)
|
|
layout.minimumInteritemSpacing = 13
|
|
layout.minimumLineSpacing = 13
|
|
return layout
|
|
}()
|
|
|
|
private lazy var collectionView: SPCollectionView = {
|
|
let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: layout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
// collectionView.sp_addRefreshHeader { [weak self] in
|
|
// self?.handleHeaderRefresh(nil)
|
|
// }
|
|
collectionView.sp_addRefreshBackFooter(insetBottom: 0) { [weak self] in
|
|
self?.handleFooterRefresh(nil)
|
|
}
|
|
SPHomeShortCell.registerCell(collectionView: collectionView)
|
|
return collectionView
|
|
}()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
setBackgroundView(isShowGradient: false, bgImage: nil, backgroundColor: .clear)
|
|
sp_setupUI()
|
|
|
|
requestListDataArr(page: 1, completer: nil)
|
|
}
|
|
|
|
|
|
override func handleHeaderRefresh(_ completer: (() -> Void)?) {
|
|
requestListDataArr(page: 1, completer: completer)
|
|
}
|
|
|
|
override func handleFooterRefresh(_ completer: (() -> Void)?) {
|
|
requestListDataArr(page: self.page + 1) { [weak self] in
|
|
self?.collectionView.sp_endFooterRefreshing()
|
|
}
|
|
}
|
|
|
|
func getMyScrollView() -> UIScrollView {
|
|
return self.collectionView
|
|
}
|
|
|
|
}
|
|
|
|
extension SPHomeChildController {
|
|
|
|
private func sp_setupUI() {
|
|
view.addSubview(collectionView)
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.edges.equalToSuperview()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: -------------- UICollectionViewDelegate & UICollectionViewDataSource --------------
|
|
extension SPHomeChildController: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = SPHomeShortCell.dequeueReusableCell(collectionView: collectionView, indexPath: indexPath)
|
|
cell.model = 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 = dataArr[indexPath.row]
|
|
|
|
let vc = SPPlayerDetailViewController()
|
|
vc.shortPlayId = model.short_play_id
|
|
self.navigationController?.pushViewController(vc, animated: true)
|
|
}
|
|
}
|
|
|
|
|
|
extension SPHomeChildController {
|
|
|
|
///获取列表数据
|
|
private func requestListDataArr(page: Int, completer: (() -> Void)?) {
|
|
SPHomeAPI.requestHomeList(page: page) { [weak self] listModel in
|
|
guard let self = self else { return }
|
|
|
|
if let list = listModel?.list {
|
|
if page == 1 {
|
|
self.dataArr.removeAll()
|
|
}
|
|
self.dataArr += list
|
|
|
|
self.collectionView.reloadData()
|
|
self.page = page
|
|
}
|
|
completer?()
|
|
}
|
|
}
|
|
}
|