194 lines
6.0 KiB
Swift
194 lines
6.0 KiB
Swift
//
|
|
// SPHomeHeaderView.swift
|
|
// Thimra
|
|
//
|
|
// Created by 曾觉新 on 2025/4/14.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPHomeHeaderView: UICollectionReusableView {
|
|
|
|
var viewModel: SPHomeViewModel? {
|
|
didSet {
|
|
let moduleModel = viewModel?.moduleModel
|
|
|
|
stackView.removeAllArrangedSubview()
|
|
|
|
stackView.addArrangedSubview(bannerView)
|
|
bannerView.reloadData()
|
|
|
|
if let historyList = viewModel?.playHistoryArr, historyList.count > 0 {
|
|
stackView.addArrangedSubview(playHistoryView)
|
|
playHistoryView.dataArr = historyList
|
|
}
|
|
|
|
if let list = moduleModel?.nineSquare?.list, list.count > 0 {
|
|
stackView.addArrangedSubview(exploreView)
|
|
exploreView.titleLabel.text = moduleModel?.nineSquare?.title
|
|
exploreView.dataArr = list
|
|
}
|
|
|
|
// stackView.addArrangedSubview(trendingView)
|
|
// trendingView.dataArr = moduleModel?.bannerData
|
|
//
|
|
// stackView.addArrangedSubview(hotView)
|
|
// hotView.dataArr = moduleModel?.bannerData
|
|
//
|
|
// stackView.addArrangedSubview(shortsForYouView)
|
|
// shortsForYouView.dataArr = moduleModel?.bannerData
|
|
|
|
stackView.addArrangedSubview(titleView)
|
|
}
|
|
}
|
|
|
|
|
|
private lazy var stackView: UIStackView = {
|
|
let view = UIStackView()
|
|
view.axis = .vertical
|
|
view.spacing = 25
|
|
return view
|
|
}()
|
|
|
|
private lazy var bannerLayout: SPZoomCollectionViewLayout = {
|
|
let layout = SPZoomCollectionViewLayout()
|
|
layout.itemSize = .init(width: 234, height: Self.bannerHeight())
|
|
layout.minimumLineSpacing = 10
|
|
layout.minimumInteritemSpacing = 0
|
|
return layout
|
|
}()
|
|
|
|
private lazy var bannerView: SPCollectionView = {
|
|
let view = SPCollectionView(frame: .zero, collectionViewLayout: bannerLayout)
|
|
view.delegate = self
|
|
view.dataSource = self
|
|
view.showsVerticalScrollIndicator = false
|
|
view.showsHorizontalScrollIndicator = false
|
|
SPHomeZoomBannerCell.registerCell(collectionView: view)
|
|
|
|
view.snp.makeConstraints { make in
|
|
make.width.equalTo(kSPScreenWidth)
|
|
make.height.equalTo(Self.bannerHeight())
|
|
}
|
|
return view
|
|
}()
|
|
|
|
private lazy var playHistoryView: SPHomePlayHistoryView = {
|
|
let view = SPHomePlayHistoryView()
|
|
return view
|
|
}()
|
|
|
|
private lazy var exploreView: SPHomeExploreView = {
|
|
let view = SPHomeExploreView()
|
|
return view
|
|
}()
|
|
|
|
private lazy var trendingView: SPHomeTrendingView = {
|
|
let view = SPHomeTrendingView()
|
|
return view
|
|
}()
|
|
|
|
private lazy var hotView: SPHomeHotView = {
|
|
let view = SPHomeHotView()
|
|
return view
|
|
}()
|
|
|
|
private lazy var shortsForYouView: SPHomeShortsForYouView = {
|
|
let view = SPHomeShortsForYouView()
|
|
return view
|
|
}()
|
|
|
|
private lazy var titleView: SPHomeDataItemView = {
|
|
let view = SPHomeDataItemView()
|
|
view.titleLabel.text = "More for you!".localized
|
|
return view
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
_setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension SPHomeHeaderView {
|
|
|
|
private func _setupUI() {
|
|
addSubview(stackView)
|
|
|
|
stackView.snp.makeConstraints { make in
|
|
make.edges.equalToSuperview()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: -------------- UICollectionViewDelegate & UICollectionViewDataSource --------------
|
|
extension SPHomeHeaderView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = SPHomeZoomBannerCell.dequeueReusableCell(collectionView: collectionView, indexPath: indexPath)
|
|
cell.model = self.viewModel?.moduleModel?.bannerData?[indexPath.row]
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return self.viewModel?.moduleModel?.bannerData?.count ?? 0
|
|
}
|
|
|
|
func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
return 1
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
let model = self.viewModel?.moduleModel?.bannerData?[indexPath.row]
|
|
|
|
let vc = SPPlayerDetailViewController()
|
|
vc.shortPlayId = model?.short_play_id
|
|
self.viewController?.navigationController?.pushViewController(vc, animated: true)
|
|
}
|
|
}
|
|
|
|
|
|
extension SPHomeHeaderView {
|
|
|
|
static func contentHeight(viewModel: SPHomeViewModel) -> CGFloat {
|
|
var height = bannerHeight()
|
|
let moduleModel = viewModel.moduleModel
|
|
|
|
///历史记录
|
|
if let historyList = viewModel.playHistoryArr, historyList.count > 0 {
|
|
height = height + SPHomePlayHistoryView.contentHeight(dataArr: historyList) + 25
|
|
}
|
|
|
|
|
|
///九宫格数据
|
|
if let list = moduleModel?.nineSquare?.list, list.count > 0 {
|
|
height = height + SPHomeExploreView.contentHeight(dataArr: list) + 25
|
|
}
|
|
|
|
// height = height + SPHomeTrendingView.contentHeight(dataArr: moduleModel?.bannerData ?? []) + 25
|
|
//
|
|
//
|
|
// height = height + SPHomeHotView.contentHeight(dataArr: moduleModel?.bannerData ?? []) + 25
|
|
//
|
|
// height = height + SPHomeShortsForYouView.contentHeight(dataArr: moduleModel?.bannerData ?? []) + 25
|
|
|
|
///标题高度
|
|
height = height + SPHomeDataItemView.contentHeight(dataArr: []) + 25
|
|
|
|
return height
|
|
}
|
|
|
|
static func bannerHeight() -> CGFloat {
|
|
return 336
|
|
}
|
|
|
|
|
|
|
|
}
|