Music_Player3/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Home(首页,各项列表页,艺术家页)/MPPositive_MoreContentViewController.swift

140 lines
7.1 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 Video = 2
//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 = 5*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 .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_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"
//cell
private let MPPositive_HomeListFifthCollectionViewCellID = "MPPositive_HomeListFifthCollectionViewCell"
//
var browseModuleList:MPPositive_BrowseModuleListViewModel!
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() {
//
showType = .init(rawValue: browseModuleList.items.first?.browseItem.itemType.rawValue ?? 0)!
}
}
//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 .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("Weak connection.", delay: 2.0, completion: nil)
return
}
//
MP_PlayerManager.shared.loadPlayer = nil
//
NotificationCenter.notificationKey.post(notificationName: .pup_player_vc)
//next
MP_NetWorkManager.shared.requestNextList(browseModuleList.items[indexPath.row].browseItem.playListId ?? "", videoId: browseModuleList.items[indexPath.row].browseItem.videoId ?? ""){ [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.loadPlayer = lodaViewModel
}
}
default:
//
let listVC = MPPositive_ListShowViewController(browseModuleList.items[indexPath.row].browseItem.browseId ?? "", params: browseModuleList.items[indexPath.row].browseItem.params ?? "", title: browseModuleList.items[indexPath.row].title ?? "", subtitle: browseModuleList.items[indexPath.row].subtitle ?? "")
navigationController?.pushViewController(listVC, animated: true)
}
}
}