Music_Player3/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Home(首页,各项列表页,艺术家页)/MPPositive_MoreContentViewController.swift
2024-08-15 15:50:48 +08:00

177 lines
9.0 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_MoreContentViewController.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/4/28.
//
import UIKit
/////
class MPPositive_MoreContentViewController: MPPositive_BaseViewController {
//
enum MoreShowType: Int {
case Single = 0
case List = 1
case Artist = 2
case Video = 3
//Layout
var layout:UICollectionViewFlowLayout{
let layout = UICollectionViewFlowLayout()
layout.sectionInset = .init(top: 0, left: 18*width, bottom: 50*width, right: 16*width)
switch self {
case .Single:
layout.itemSize = .init(width: 168*width, height: 134*width)
layout.minimumInteritemSpacing = 2*width
layout.minimumLineSpacing = 32*width
case .List:
layout.itemSize = .init(width: 162*width, height: 210*width)
layout.minimumLineSpacing = 32*width
layout.minimumInteritemSpacing = 15*width
case .Artist:
layout.itemSize = .init(width: 94*width, height: 116*width)
layout.minimumInteritemSpacing = 2*width
layout.minimumLineSpacing = 32*width
case .Video:
layout.itemSize = .init(width: 339*width, height: 237*width)
layout.minimumLineSpacing = 32*width
}
return layout
}
}
///
private var showType:MoreShowType = .Single{
didSet{
collectionView.collectionViewLayout = showType.layout
collectionView.reloadData()
}
}
private lazy var collectionView:UICollectionView = {
let collectionView:UICollectionView = .init(frame: .init(x: 0, y: 0, width: screen_Width, height: screen_Height), collectionViewLayout: showType.layout)
collectionView.showsVerticalScrollIndicator = false
collectionView.showsHorizontalScrollIndicator = false
collectionView.backgroundColor = .clear
collectionView.dataSource = self
collectionView.delegate = self
collectionView.register(MPPositive_HomeListFirstCollectionViewCell.self, forCellWithReuseIdentifier: MPPositive_HomeListFirstCollectionViewCellID)
collectionView.register(MPPositive_MoreListContentCollectionViewCell.self, forCellWithReuseIdentifier: MPPositive_MoreListContentCollectionViewCellID)
collectionView.register(MPPositive_HomeListFourthCollectionViewCell.self, forCellWithReuseIdentifier: MPPositive_HomeListFourthCollectionViewCellID)
collectionView.register(MPPositive_HomeListFifthCollectionViewCell.self, forCellWithReuseIdentifier: MPPositive_HomeListFifthCollectionViewCellID)
collectionView.contentInset = .init(top: 0, left: 0, bottom: 70*width, right: 0)
return collectionView
}()
//cell
private let MPPositive_HomeListFirstCollectionViewCellID = "MPPositive_HomeListFirstCollectionViewCell"
private let MPPositive_MoreListContentCollectionViewCellID = "MPPositive_MoreListContentCollectionViewCell"
private let MPPositive_HomeListFourthCollectionViewCellID = "MPPositive_HomeListFourthCollectionViewCell"
//cell
private let MPPositive_HomeListFifthCollectionViewCellID = "MPPositive_HomeListFifthCollectionViewCell"
//
var browseModuleList:MPPositive_BrowseModuleListViewModel!
init(_ list:MPPositive_BrowseModuleListViewModel) {
super.init(nibName: nil, bundle: nil)
browseModuleList = list
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func viewDidLoad() {
super.viewDidLoad()
setTitle("More")
setPopBtn()
confirgue()
}
private func confirgue() {
view.backgroundColor = .init(hex: "#121212")
view.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.top.equalTo(navView.snp.bottom).offset(32*width)
make.left.right.bottom.equalToSuperview()
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
reload()
}
//
private func reload() {
//
let type:MoreShowType = .init(rawValue: browseModuleList.items.first?.browseItem.itemType?.rawValue ?? 0)!
if browseModuleList.items.first?.browseItem.pageType == "MUSIC_VIDEO_TYPE_OMV" {
showType = .Video
}else {
showType = type
}
}
}
//MARK: - collectionView
extension MPPositive_MoreContentViewController: UICollectionViewDataSource, UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return browseModuleList.items.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch showType {
case .Single:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MPPositive_HomeListFirstCollectionViewCellID, for: indexPath) as! MPPositive_HomeListFirstCollectionViewCell
cell.itemViewModel = browseModuleList.items[indexPath.row]
return cell
case .List:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MPPositive_MoreListContentCollectionViewCellID, for: indexPath) as! MPPositive_MoreListContentCollectionViewCell
cell.itemViewModel = browseModuleList.items[indexPath.row]
return cell
case .Artist:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MPPositive_HomeListFourthCollectionViewCellID, for: indexPath) as! MPPositive_HomeListFourthCollectionViewCell
cell.itemViewModel = browseModuleList.items[indexPath.row]
return cell
case .Video:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MPPositive_HomeListFifthCollectionViewCellID, for: indexPath) as! MPPositive_HomeListFifthCollectionViewCell
cell.itemViewModel = browseModuleList.items[indexPath.row]
return cell
}
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
MP_AnalyticsManager.shared.home_b_module_clickAction(browseModuleList.title ?? "")
switch showType {
case .Single, .Video:
///
MPPositive_Debouncer.shared.call {
[weak self] in
guard let self = self else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
MP_HUD.text("Bad connection~".localizableString(), delay: 2.0, completion: nil)
return
}
MP_AnalyticsManager.shared.song_clickAction("MoreContent")
//
MP_PlayerManager.shared.loadPlayer = nil
//
NotificationCenter.notificationKey.post(notificationName: .pup_player_vc)
MP_AnalyticsManager.shared.player_b_impAction()
let item = browseModuleList.items[indexPath.row]
//next
MP_NetWorkManager.shared.requestNextList(item.browseItem.playListId ?? "", videoId: item.browseItem.videoId ?? "", clickTrackingParams: item.browseItem.clickTrackingParams){ [weak self] listSongs in
guard let self = self else {return}
//playerloadViewModel
let lodaViewModel = MPPositive_PlayerLoadViewModel(listSongs, currentVideoId: browseModuleList.items[indexPath.row].browseItem.videoId ?? "")
lodaViewModel.improveData(browseModuleList.items[indexPath.row].browseItem.videoId ?? "")
//
MP_PlayerManager.shared.setPlayType(.normal)
MP_PlayerManager.shared.loadPlayer = lodaViewModel
MP_AnalyticsManager.shared.player_b_listAction()
}
}
case .Artist:
let item = browseModuleList.items[indexPath.row]
//
let artistVC = MPPositive_ArtistShowViewController(item.browseItem.artistId ?? "", clickTrackingParams: item.browseItem.clickTrackingParams ?? "")
navigationController?.pushViewController(artistVC, animated: true)
default:
let item = browseModuleList.items[indexPath.row]
//
let listVC = MPPositive_ListShowViewController(item.browseItem.browseId ?? "", params: "", title: item.title ?? "", subtitle: item.subtitle ?? "", clickTrackingParams: item.browseItem.clickTrackingParams ?? "")
navigationController?.pushViewController(listVC, animated: true)
}
}
}