198 lines
6.4 KiB
Swift
198 lines
6.4 KiB
Swift
//
|
|
// SREpSelectorView.swift
|
|
// SynthReel
|
|
//
|
|
// Created by 湖北秦九 on 2025/11/18.
|
|
// Copyright © 2025 SR. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import HWPanModal
|
|
import SnapKit
|
|
|
|
class SREpSelectorView: SRPanModalContentView {
|
|
|
|
var didSelected: ((_ index: Int) -> Void)?
|
|
|
|
var model: SRShortDetailModel? {
|
|
didSet {
|
|
coverImageView.sr_setImage(model?.shortPlayInfo?.image_url)
|
|
shortNameLabel.text = model?.shortPlayInfo?.name
|
|
desLabel.text = model?.shortPlayInfo?.sr_description
|
|
|
|
subtitleLabel.text = "all_episodes_text".localizedReplace(text: "\(model?.shortPlayInfo?.episode_total ?? 0)")
|
|
|
|
if let text = model?.shortPlayInfo?.category?.first, text.count > 0 {
|
|
cagetoryLabel.text = "#" + text
|
|
} else {
|
|
cagetoryLabel.text = ""
|
|
}
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
var selectedIndex: Int = 0 {
|
|
didSet {
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
lazy var coverBgView = UIImageView(image: UIImage(named: "ep_cover_bg_image"))
|
|
lazy var coverImageView: UIImageView = {
|
|
let imageView = SRImageView()
|
|
imageView.layer.cornerRadius = 2
|
|
return imageView
|
|
}()
|
|
|
|
lazy var shortNameLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 15, weight: .semibold)
|
|
label.textColor = .srBlue
|
|
return label
|
|
}()
|
|
|
|
lazy var cagetoryLabel: SRLabel = {
|
|
let label = SRLabel()
|
|
label.font = .font(ofSize: 12, weight: .regular)
|
|
label.textColors = [UIColor.srGreen.cgColor, UIColor.srBlue.cgColor]
|
|
label.textStartPoint = .init(x: 0.5, y: 0)
|
|
label.textEndPoint = .init(x: 0.5, y: 1)
|
|
return label
|
|
}()
|
|
|
|
lazy var desLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 12, weight: .regular)
|
|
label.textColor = .A_6_A_6_A_6
|
|
label.numberOfLines = 3
|
|
return label
|
|
}()
|
|
|
|
lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 15, weight: .medium)
|
|
label.textColor = .white
|
|
label.text = "Select Episode".localized
|
|
return label
|
|
}()
|
|
|
|
lazy var subtitleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 12, weight: .regular)
|
|
label.textColor = .CCCCCC
|
|
return label
|
|
}()
|
|
|
|
lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
let itemWidth = (UIScreen.width - 30 - 40) / 5
|
|
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.minimumLineSpacing = 10
|
|
layout.minimumInteritemSpacing = 10
|
|
layout.sectionInset = .init(top: 0, left: 15, bottom: 0, right: 15)
|
|
layout.itemSize = .init(width: floor(itemWidth), height: 50)
|
|
return layout
|
|
}()
|
|
|
|
lazy var collectionView: SRCollectionView = {
|
|
let collectionView = SRCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
collectionView.showsVerticalScrollIndicator = false
|
|
collectionView.contentInset = .init(top: 0, left: 0, bottom: UIScreen.safeBottom + 10, right: 0)
|
|
collectionView.register(SREpSelectorCell.self, forCellWithReuseIdentifier: "cell")
|
|
return collectionView
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
sr_setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
|
|
extension SREpSelectorView {
|
|
|
|
private func sr_setupUI() {
|
|
addSubview(coverBgView)
|
|
addSubview(coverImageView)
|
|
addSubview(shortNameLabel)
|
|
addSubview(cagetoryLabel)
|
|
addSubview(desLabel)
|
|
addSubview(titleLabel)
|
|
addSubview(subtitleLabel)
|
|
addSubview(collectionView)
|
|
|
|
coverBgView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(15)
|
|
make.top.equalToSuperview().offset(18)
|
|
}
|
|
|
|
coverImageView.snp.makeConstraints { make in
|
|
make.center.equalTo(coverBgView)
|
|
make.width.equalTo(63)
|
|
make.height.equalTo(84)
|
|
}
|
|
|
|
shortNameLabel.snp.makeConstraints { make in
|
|
make.left.equalTo(coverImageView.snp.right).offset(10)
|
|
make.top.equalToSuperview().offset(24)
|
|
make.right.lessThanOrEqualToSuperview().offset(-15)
|
|
}
|
|
|
|
cagetoryLabel.snp.makeConstraints { make in
|
|
make.left.equalTo(shortNameLabel)
|
|
make.top.equalTo(shortNameLabel.snp.bottom).offset(8)
|
|
}
|
|
|
|
desLabel.snp.makeConstraints { make in
|
|
make.left.equalTo(shortNameLabel)
|
|
make.right.lessThanOrEqualToSuperview().offset(-15)
|
|
make.top.equalTo(shortNameLabel.snp.bottom).offset(32)
|
|
}
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(15)
|
|
make.top.equalTo(coverBgView.snp.bottom).offset(16)
|
|
}
|
|
|
|
subtitleLabel.snp.makeConstraints { make in
|
|
make.centerY.equalTo(titleLabel)
|
|
make.left.equalTo(titleLabel.snp.right).offset(3)
|
|
}
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.left.right.equalToSuperview()
|
|
make.top.equalToSuperview().offset(166)
|
|
make.bottom.equalToSuperview()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: UICollectionViewDelegate UICollectionViewDataSource
|
|
extension SREpSelectorView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! SREpSelectorCell
|
|
cell.model = self.model?.episodeList?[indexPath.row]
|
|
cell.sr_isSelected = indexPath.row == self.selectedIndex
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return self.model?.episodeList?.count ?? 0
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
self.didSelected?(indexPath.row)
|
|
Task {
|
|
await self.dismiss(animated: true)
|
|
}
|
|
}
|
|
}
|