Music_Player3/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Player(播放器)/MPPositive_RecommendViewController.swift
2024-07-05 17:25:49 +08:00

233 lines
9.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MPPositive_RecommendViewController.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/5/20.
//
import UIKit
///
class MPPositive_RecommendViewController: MPPositive_BaseViewController,UIViewControllerTransitioningDelegate {
//load
private var loadRecommend:MPPositive_RecommendLoadViewModel!{
didSet{
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
if loadRecommend != nil {
membersView.isHidden = false
segmentView.isHidden = false
listContainerView.isHidden = false
loadRecommend.resultReloadBlock = {
[weak self] in
//
guard let self = self else {return}
sectionLabel.text = loadRecommend?.members?.title
collectionView.reloadData()
dataSource.titles = loadRecommend?.sectionLists?.compactMap({$0.title}) ?? []
dataSource.reloadData(selectedIndex: 0)
segmentView.reloadData()
}
configure()
removeErrorView()
MP_HUD.hideNow()
}else {
membersView.isHidden = true
segmentView.isHidden = true
listContainerView.isHidden = true
}
}
}
}
//MARK: -
///View
private lazy var membersView:UIView = createMusicMembersView()
//
private lazy var sectionLabel:UILabel = createLabel("Loading",font: .systemFont(ofSize: 18*width, weight: .regular), textColor: .white, textAlignment: .left)
//CollectionView
private lazy var collectionView:UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.itemSize = .init(width: 50*width, height: 90*width)
layout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
layout.minimumInteritemSpacing = 16*width
layout.scrollDirection = .horizontal
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.backgroundColor = .clear
collectionView.showsVerticalScrollIndicator = false
collectionView.showsHorizontalScrollIndicator = false
collectionView.dataSource = self
collectionView.delegate = self
collectionView.register(MPPositive_RecommendMemberCollectionViewCell.self, forCellWithReuseIdentifier: MPPositive_RecommendMemberCollectionViewCellID)
return collectionView
}()
private let MPPositive_RecommendMemberCollectionViewCellID = "MPPositive_RecommendMemberCollectionViewCell"
//MARK: -
//View
private lazy var segmentView:JXSegmentedView = {
var jxSegmentView = JXSegmentedView()
jxSegmentView.backgroundColor = .init(hex: "1A1A1A")
return jxSegmentView
}()
//
private lazy var dataSource:JXSegmentedTitleDataSource = {
var dataSource = JXSegmentedTitleDataSource()
//
dataSource.titleNormalColor = .init(hex: "#666666")
dataSource.titleNormalFont = .systemFont(ofSize: 16*width, weight: .regular)
//
dataSource.titleSelectedColor = .init(hex: "#80F988")
dataSource.titleSelectedFont = .systemFont(ofSize: 16*width, weight: .bold)
//
dataSource.isTitleColorGradientEnabled = true
dataSource.isSelectedAnimable = true
dataSource.isItemTransitionEnabled = true
return dataSource
}()
//
private lazy var indicator:JXSegmentedIndicatorLineView = {
let indicator = JXSegmentedIndicatorLineView()
indicator.indicatorWidth = 16*width
indicator.indicatorHeight = 3*width
indicator.indicatorCornerRadius = 1.5*width
indicator.indicatorColor = .init(hex: "#80F988")
indicator.indicatorPosition = .bottom
return indicator
}()
//
fileprivate lazy var listContainerView:JXSegmentedListContainerView = {
let listContainerView = JXSegmentedListContainerView(dataSource: self)
listContainerView.backgroundColor = .clear
return listContainerView
}()
private var browseId:String!
///
/// - Parameter browseId: id
init(_ browseId:String) {
super.init(nibName: nil, bundle: nil)
self.browseId = browseId
MP_HUD.loading()
DispatchQueue.main.async {
[weak self] in
self?.loadRecommend = .init(browseId)
}
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func viewDidLoad() {
super.viewDidLoad()
setTitle("Recommend")
setPopBtn()
errorBlock = {
[weak self] in
guard let self = self else {
return
}
//navView
view.subviews.forEach { item in
if item != self.navView {
//
if item.superview != nil {
item.removeFromSuperview()
}
}
}
//View
setErrorView()
MP_HUD.hideNow()
}
retryBlock = {
[weak self] in
guard let self = self else {return}
MP_HUD.loading()
DispatchQueue.main.async {
self.loadRecommend = .init(self.browseId)
}
}
}
private func configure() {
view.addSubview(membersView)
membersView.snp.makeConstraints { make in
make.width.equalTo(338*width)
make.height.equalTo(141*width)
make.top.equalTo(navView.snp.bottom).offset(33*width)
make.centerX.equalToSuperview()
}
segmentView.indicators = [indicator]
segmentView.dataSource = dataSource
//View
view.addSubview(segmentView)
segmentView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(membersView.snp.bottom).offset(10*width)
make.height.equalTo(60*width)
}
view.addSubview(listContainerView)
listContainerView.snp.makeConstraints { (make) in
make.left.right.bottom.equalToSuperview().priority(999)
make.top.equalTo(segmentView.snp.bottom).priority(999)
}
segmentView.contentScrollView = listContainerView.scrollView
segmentView.listContainer = listContainerView
}
//
private func createMusicMembersView() -> UIView {
let membersView:UIView = .init()
membersView.backgroundColor = .init(hex: "#1A1A1A")
membersView.layer.masksToBounds = true
membersView.layer.cornerRadius = 14*width
//
membersView.addSubview(sectionLabel)
sectionLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(14*width)
make.left.equalToSuperview().offset(12*width)
make.right.equalToSuperview().offset(-12*width)
}
membersView.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(50*width)
make.left.equalToSuperview().offset(14*width)
make.right.equalToSuperview().offset(-10*width)
make.bottom.equalToSuperview()
}
return membersView
}
@objc override func popActionClick(_ sender:UIButton) {
super.popActionClick(sender)
navigationController?.popToRootViewController(animated: false)
}
}
//MARK: - collectionView
extension MPPositive_RecommendViewController:UICollectionViewDataSource, UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return loadRecommend?.members?.items.count ?? 0
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MPPositive_RecommendMemberCollectionViewCellID, for: indexPath) as! MPPositive_RecommendMemberCollectionViewCell
cell.itemView = loadRecommend?.members?.items[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//
let artistVC = MPPositive_ArtistShowViewController(loadRecommend?.members?.items[indexPath.row].browseItem.artistId ?? "")
navigationController?.pushViewController(artistVC, animated: true)
}
}
//MARK: - JXSegmentedTitleDataSource
extension MPPositive_RecommendViewController: JXSegmentedListContainerViewDataSource, JXSegmentedViewDelegate {
func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
return dataSource.titles.count
}
func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
let showView:MPPositive_RecommendShowTypeView = .init(listContainerView.frame, list: loadRecommend.sectionLists[index])
return showView
}
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return MPPositive_PresentationController(presentedViewController: presented, presenting: presenting)
}
}