// // SPHomePlayHistoryView.swift // Thimra // // Created by Overseas on 2025/4/22. // import UIKit class SPHomePlayHistoryView: SPHomeDataItemView { override class func contentHeight(dataArr: [SPShortModel]) -> CGFloat { let height = self.contentToTop + 136 return height } override var dataArr: [SPShortModel]? { didSet { self.collectionView.reloadData() } } private lazy var collectionViewLayout: UICollectionViewFlowLayout = { let layout = UICollectionViewFlowLayout() layout.scrollDirection = .horizontal layout.itemSize = CGSize(width: 88, height: 136) layout.sectionInset = .init(top: 0, left: 16, bottom: 0, right: 16) layout.minimumInteritemSpacing = 16 layout.minimumLineSpacing = 16 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 SPHomePlayHistoryCell.registerCell(collectionView: collectionView) return collectionView }() override init(frame: CGRect) { super.init(frame: frame) self.titleLabel.text = "Continue watching".localized _setupUI() } @MainActor required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } extension SPHomePlayHistoryView { private func _setupUI() { contentView.addSubview(self.collectionView) self.collectionView.snp.makeConstraints { make in make.edges.equalToSuperview() } } } //MARK: -------------- UICollectionViewDelegate & UICollectionViewDataSource -------------- extension SPHomePlayHistoryView: UICollectionViewDelegate, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = SPHomePlayHistoryCell.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 = dataArr?[indexPath.row] let vc = SPPlayerDetailViewController() vc.shortPlayId = model?.short_play_id vc.playHistoryModel = model self.viewController?.navigationController?.pushViewController(vc, animated: true) } }