122 lines
4.0 KiB
Swift
122 lines
4.0 KiB
Swift
//
|
|
// FAPopularListViewController.swift
|
|
// Fableon
|
|
//
|
|
// Created by 湖北秦九 on 2025/10/20.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class FAPopularListViewController: FAViewController {
|
|
|
|
private var dataArr: [FAShortPlayModel] = []
|
|
// private var page = 1
|
|
|
|
private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
let width = floor((UIScreen.width - 32 - 16) / 3)
|
|
let height = 145 / 109 * width + 41
|
|
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.minimumLineSpacing = 12
|
|
layout.minimumInteritemSpacing = 8
|
|
layout.itemSize = .init(width: width, height: height)
|
|
layout.sectionInset = .init(top: 0, left: 16, bottom: 0, right: 16)
|
|
return layout
|
|
}()
|
|
|
|
private lazy var collectionView: FACollectionView = {
|
|
let collectionView = FACollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
collectionView.contentInset = .init(top: 20, left: 0, bottom: UIScreen.safeBottom + 10, right: 0)
|
|
collectionView.register(UINib(nibName: "FAGenresListCell", bundle: nil), forCellWithReuseIdentifier: "cell")
|
|
collectionView.fa_addRefreshHeader(insetTop: collectionView.contentInset.top) { [weak self] in
|
|
self?.handleHeaderRefresh(nil)
|
|
}
|
|
// collectionView.fa_addRefreshFooter(insetBottom: 0) { [weak self] in
|
|
// self?.handleFooterRefresh(nil)
|
|
// }
|
|
return collectionView
|
|
}()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
self.title = "Popular".localized
|
|
|
|
fa_setupLayout()
|
|
|
|
requestDataArr(page: 1, completer: nil)
|
|
}
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
self.navigationController?.setNavigationBarHidden(false, animated: true)
|
|
fa_setNavigationStyle()
|
|
}
|
|
|
|
override func handleHeaderRefresh(_ completer: (() -> Void)?) {
|
|
requestDataArr(page: 1) { [weak self] in
|
|
self?.collectionView.fa_endHeaderRefreshing()
|
|
}
|
|
}
|
|
|
|
// override func handleFooterRefresh(_ completer: (() -> Void)?) {
|
|
// requestDataArr(page: page + 1) { [weak self] in
|
|
// self?.collectionView.fa_endFooterRefreshing()
|
|
// }
|
|
// }
|
|
|
|
}
|
|
|
|
extension FAPopularListViewController {
|
|
|
|
private func fa_setupLayout() {
|
|
view.addSubview(collectionView)
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.left.right.bottom.equalToSuperview()
|
|
make.top.equalToSuperview().offset(UIScreen.navBarHeight)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: UICollectionViewDelegate UICollectionViewDataSource
|
|
extension FAPopularListViewController: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return dataArr.count
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! FAGenresListCell
|
|
cell.model = dataArr[indexPath.row]
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
let model = dataArr[indexPath.row]
|
|
let vc = FAPlayerDetailViewController()
|
|
vc.shortPlayId = model.short_play_id
|
|
self.navigationController?.pushViewController(vc, animated: true)
|
|
}
|
|
}
|
|
|
|
extension FAPopularListViewController {
|
|
|
|
private func requestDataArr(page: Int, completer: (() -> Void)?) {
|
|
|
|
FAAPI.requestPopularVideoList { [weak self] list in
|
|
guard let self = self else { return }
|
|
if let list = list {
|
|
|
|
self.dataArr = list
|
|
self.collectionView.reloadData()
|
|
}
|
|
completer?()
|
|
}
|
|
}
|
|
|
|
}
|
|
|