92 lines
2.9 KiB
Swift
92 lines
2.9 KiB
Swift
//
|
|
// SPHomeHotView.swift
|
|
// ShortPlay
|
|
//
|
|
// Created by 曾觉新 on 2025/4/14.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPHomeHotView: SPHomeDataItemView {
|
|
|
|
|
|
override class func contentHeight(dataArr: [SPShortModel]) -> CGFloat {
|
|
if dataArr.count == 1 {
|
|
return 139 + contentToTop
|
|
} else {
|
|
return 139 * 2 + 15 + contentToTop
|
|
}
|
|
}
|
|
|
|
override var dataArr: [SPShortModel]? {
|
|
didSet {
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.scrollDirection = .horizontal
|
|
layout.itemSize = CGSize(width: kSPScreenWidth - 15 - 20, height: 139)
|
|
layout.sectionInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15)
|
|
layout.minimumLineSpacing = 10
|
|
layout.minimumInteritemSpacing = 15
|
|
return layout
|
|
}()
|
|
|
|
private lazy var collectionView: SPCollectionView = {
|
|
let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
collectionView.showsVerticalScrollIndicator = false
|
|
collectionView.showsHorizontalScrollIndicator = false
|
|
SPHomeHotCell.registerCell(collectionView: collectionView)
|
|
return collectionView
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
self.titleLabel.text = "Editor's Hotlist".localized
|
|
_setupUI()
|
|
}
|
|
|
|
@MainActor required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension SPHomeHotView {
|
|
private func _setupUI() {
|
|
contentView.addSubview(collectionView)
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.edges.equalToSuperview()
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: -------------- UICollectionViewDelegate & UICollectionViewDataSource --------------
|
|
extension SPHomeHotView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = SPHomeHotCell.dequeueReusableCell(collectionView: collectionView, indexPath: indexPath)
|
|
cell.model = 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 = SPTVPlayerListViewController()
|
|
vc.shortPlayId = model?.short_play_id
|
|
self.viewController?.navigationController?.pushViewController(vc, animated: true)
|
|
}
|
|
|
|
}
|