194 lines
5.9 KiB
Swift
194 lines
5.9 KiB
Swift
//
|
|
// BRHomeTop10ViewController.swift
|
|
// BeeReel
|
|
//
|
|
// Created by 长沙鸿瑶 on 2025/6/30.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class BRHomeTop10ViewController: BRViewController {
|
|
|
|
|
|
private lazy var dataArr: [[BRShortModel]] = []
|
|
|
|
|
|
private lazy var collectionViewLayout: WaterfallMutiSectionFlowLayout = {
|
|
let layout = WaterfallMutiSectionFlowLayout()
|
|
layout.delegate = self
|
|
return layout
|
|
}()
|
|
|
|
private lazy var collectionView: BRCollectionView = {
|
|
let collectionView = BRCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.contentInset = .init(top: 0, left: 0, bottom: UIScreen.customTabBarHeight + 10, right: 0)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
collectionView.register(BRHomeTop10Cell.self, forCellWithReuseIdentifier: "cell")
|
|
collectionView.register(BRHomeTop3Cell.self, forCellWithReuseIdentifier: "BRHomeTop3Cell")
|
|
return collectionView
|
|
}()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
requestDataArr()
|
|
|
|
br_setupUI()
|
|
}
|
|
|
|
|
|
override func handleHeaderRefresh(_ completer: (() -> Void)?) {
|
|
requestDataArr {
|
|
completer?()
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
extension BRHomeTop10ViewController {
|
|
|
|
private func br_setupUI() {
|
|
view.addSubview(collectionView)
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.left.right.equalToSuperview()
|
|
make.bottom.equalToSuperview()
|
|
make.top.equalToSuperview().offset(20)
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//MARK: -------------- WMZPageProtocol --------------
|
|
extension BRHomeTop10ViewController: WMZPageProtocol {
|
|
|
|
func getMyScrollView() -> UIScrollView {
|
|
return self.collectionView
|
|
}
|
|
}
|
|
|
|
|
|
//MARK: -------------- UICollectionViewDelegate UICollectionViewDataSource --------------
|
|
extension BRHomeTop10ViewController: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let model = self.dataArr[indexPath.section][indexPath.row]
|
|
|
|
if indexPath.section == 0 {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "BRHomeTop3Cell", for: indexPath) as! BRHomeTop3Cell
|
|
cell.num = indexPath.row + 1
|
|
cell.model = model
|
|
return cell
|
|
} else {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! BRHomeTop10Cell
|
|
cell.num = indexPath.row + 4
|
|
cell.model = model
|
|
return cell
|
|
}
|
|
}
|
|
|
|
func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
return self.dataArr.count
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return self.dataArr[section].count
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
let model = self.dataArr[indexPath.section][indexPath.row]
|
|
|
|
let vc = BRVideoDetailViewController()
|
|
vc.shortPlayId = model.short_play_id
|
|
self.navigationController?.pushViewController(vc, animated: true)
|
|
}
|
|
}
|
|
|
|
//MARK: -------------- WaterfallMutiSectionDelegate --------------
|
|
extension BRHomeTop10ViewController: WaterfallMutiSectionDelegate {
|
|
|
|
func heightForRowAtIndexPath(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, indexPath: IndexPath, itemWidth: CGFloat) -> CGFloat {
|
|
if indexPath.section == 0 {
|
|
if indexPath.row == 0 {
|
|
return 240
|
|
} else {
|
|
return 115
|
|
}
|
|
}
|
|
return 126
|
|
}
|
|
|
|
func columnNumber(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> Int {
|
|
if section == 0 {
|
|
return 2
|
|
} else {
|
|
return 1
|
|
}
|
|
}
|
|
|
|
func lineSpacing(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> CGFloat {
|
|
if section == 0 {
|
|
return 10
|
|
} else {
|
|
return 12
|
|
}
|
|
}
|
|
|
|
func interitemSpacing(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> CGFloat {
|
|
return 10
|
|
}
|
|
|
|
func referenceSizeForHeader(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> CGSize {
|
|
if section > 0 {
|
|
return .init(width: UIScreen.width, height: 10)
|
|
} else {
|
|
return .zero
|
|
}
|
|
}
|
|
|
|
func insetForSection(collectionView collection: UICollectionView, layout: WaterfallMutiSectionFlowLayout, section: Int) -> UIEdgeInsets {
|
|
return .init(top: 0, left: 15, bottom: 0, right: 15)
|
|
}
|
|
}
|
|
|
|
extension BRHomeTop10ViewController {
|
|
|
|
private func requestDataArr(completer: (() -> Void)? = nil) {
|
|
|
|
BRHomeAPI.requestTop10List { [weak self] list in
|
|
guard let self = self else { return }
|
|
guard let list = list else {
|
|
completer?()
|
|
return
|
|
}
|
|
self.dataArr.removeAll()
|
|
|
|
var arr1: [BRShortModel] = []
|
|
var arr2: [BRShortModel] = []
|
|
|
|
list.enumerated().forEach {
|
|
if $0 < 3 {
|
|
arr1.append($1)
|
|
} else {
|
|
arr2.append($1)
|
|
}
|
|
}
|
|
if arr1.count > 0 {
|
|
self.dataArr.append(arr1)
|
|
}
|
|
if arr2.count > 0 {
|
|
self.dataArr.append(arr2)
|
|
}
|
|
self.collectionView.reloadData()
|
|
|
|
completer?()
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|