Music_Player3/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Center(个人曲库页)/MPPositive_LoveSongsViewController.swift

148 lines
7.0 KiB
Swift

//
// MPPositive_LoveSongsViewController.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/5/28.
//
import UIKit
class MPPositive_LoveSongsViewController: MPPositive_BaseViewController, UIViewControllerTransitioningDelegate {
private lazy var numbersLabel:UILabel = createLabel(font: .systemFont(ofSize: 18*width, weight: .regular), textColor: .white, textAlignment: .left)
///tableView
private lazy var tableView:UITableView = {
let tableView = UITableView(frame: .init(x: 0, y: 0, width: screen_Width, height: screen_Height), style: .plain)
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
tableView.backgroundColor = .clear
tableView.separatorStyle = .none
tableView.estimatedRowHeight = 200
tableView.rowHeight = UITableView.automaticDimension
tableView.dataSource = self
tableView.delegate = self
tableView.register(MPPositive_SearchResultShowTableViewCell.self, forCellReuseIdentifier: MPPositive_SearchResultShowTableViewCellID)
tableView.contentInset = .init(top: 0, left: 0, bottom: 70*width, right: 0)
return tableView
}()
private let MPPositive_SearchResultShowTableViewCellID = "MPPositive_SearchResultShowTableViewCell"
override func viewDidLoad() {
super.viewDidLoad()
setTitle("Love Songs")
setPopBtn()
configure()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
reload()
}
//
private func reload() {
MPPositive_LoadCoreModel.shared.reloadCollectionSongViewModel {
[weak self] in
guard let self = self else {return}
tableView.showMessage(MPPositive_LoadCoreModel.shared.songViewModels.count, title: "No Songs")
numbersLabel.text = "\(MPPositive_LoadCoreModel.shared.songViewModels.count) Songs"
tableView.reloadData()
}
}
private func configure() {
view.addSubview(numbersLabel)
numbersLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(18*width)
make.top.equalTo(navView.snp.bottom).offset(32*width)
}
view.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.top.equalTo(navView.snp.bottom).offset(70*width)
make.left.right.bottom.equalToSuperview()
}
}
}
//MARK: - tableView
extension MPPositive_LoveSongsViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return MPPositive_LoadCoreModel.shared.songViewModels.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: MPPositive_SearchResultShowTableViewCellID, for: indexPath) as! MPPositive_SearchResultShowTableViewCell
cell.songViewModel = MPPositive_LoadCoreModel.shared.songViewModels[indexPath.row]
cell.moreBlock = {
[weak self] in
guard let self = self else {return}
MPPositive_Debouncer.shared.call {
MP_NetWorkManager.shared.requestNextList("", videoId: MPPositive_LoadCoreModel.shared.songViewModels[indexPath.row].collectionSong.videoId ?? ""){ [weak self] listSongs in
guard let first = listSongs.first else {return}
let group = DispatchGroup()
group.enter()
improveDataforLycirsAndRelated(first) {[weak self] (result) in
first.lyricsID = result.0
first.relatedID = result.1
group.leave()
}
group.enter()
//
improveDataforResouceAndCover(first) {[weak self] resourceUrls, coverUrls in
if let resourceUrls = resourceUrls {
first.resourceUrls = resourceUrls.0
first.itags = resourceUrls.1
first.mimeTypes = resourceUrls.2
}
first.coverUrls = coverUrls
group.leave()
}
group.notify(queue: .main, execute: {
[weak self] in
MPPositive_ModalType = .MoreOperations
let moreVC = MPPositive_MoreSongOperationsViewController(first)
moreVC.removeBlock = {
self?.reload()
}
moreVC.disMissBlock = {
self?.reload()
}
moreVC.collectionBlock = {
self?.reload()
}
moreVC.transitioningDelegate = self
moreVC.modalPresentationStyle = .custom
self?.present(moreVC, animated: true)
})
}
}
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
MPPositive_Debouncer.shared.call {
[weak self] in
guard let self = self else {return}
//
NotificationCenter.notificationKey.post(notificationName: .pup_player_vc)
//
MP_PlayerManager.shared.loadPlayer = nil
//
var array:[MPPositive_SongItemModel] = []
for (index,song) in MPPositive_LoadCoreModel.shared.songViewModels.enumerated() {
let item = MPPositive_SongItemModel()
//item
item.index = index
item.reviewUrls = [song.coverURL.absoluteString]
item.title = song.title
item.shortBylineText = song.subtitle
item.videoId = song.collectionSong.videoId
item.lyricsID = song.collectionSong.lyricsID
item.relatedID = song.collectionSong.relatedID
array.append(item)
}
let lodaViewModel = MPPositive_PlayerLoadViewModel(array, currentVideoId: MPPositive_LoadCoreModel.shared.songViewModels[indexPath.row].collectionSong.videoId ?? "")
lodaViewModel.improveData(MPPositive_LoadCoreModel.shared.songViewModels[indexPath.row].collectionSong.videoId ?? "")
MP_PlayerManager.shared.loadPlayer = lodaViewModel
// NotificationCenter.notificationKey.post(notificationName: .pup_player_vc)
}
}
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return MPPositive_PresentationController(presentedViewController: presented, presenting: presenting)
}
}