144 lines
5.4 KiB
Swift
144 lines
5.4 KiB
Swift
//
|
|
// MPPositive_AddSongsShowView.swift
|
|
// relax.offline.mp3.music
|
|
//
|
|
// Created by Mr.Zhou on 2024/9/24.
|
|
//
|
|
|
|
import UIKit
|
|
///选择歌曲
|
|
class MPPositive_AddSongsShowView: UIView, JXSegmentedListContainerViewListDelegate {
|
|
private lazy var tableView:UITableView = {
|
|
let tableView = UITableView()
|
|
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.contentInset = .init(top: 0, left: 0, bottom: 70*width, right: 0)
|
|
tableView.register(MPPositive_AddSongTableViewCell.self, forCellReuseIdentifier: MPPositive_AddSongTableViewCellID)
|
|
return tableView
|
|
}()
|
|
private let MPPositive_AddSongTableViewCellID = "MPPositive_AddSongTableViewCell"
|
|
//当前展示的页面
|
|
var selectedIndex:Int = 0
|
|
///当前歌单数据
|
|
var list:MPPositive_CustomPlayListModel?
|
|
//收藏歌曲组
|
|
private var loves:[MPPositive_CollectionSongViewModel] = []
|
|
//离线歌曲组
|
|
private var offlines:[MPPositive_DownloadViewModel] = []
|
|
|
|
init(frame: CGRect, playList:MPPositive_CustomPlayListModel) {
|
|
super.init(frame: frame)
|
|
self.list = playList
|
|
backgroundColor = .init(hex: "1A1A1A")
|
|
configure()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
}
|
|
|
|
//MARK: - 分页代理
|
|
func listView() -> UIView {
|
|
return self
|
|
}
|
|
func listWillAppear() {
|
|
reload()
|
|
}
|
|
//加载数据
|
|
private func reload() {
|
|
if selectedIndex == 0 {
|
|
//更新搜藏歌曲
|
|
MPPositive_LoadCoreModel.shared.reloadCollectionSongViewModel {
|
|
[weak self] in
|
|
guard let self = self else {return}
|
|
loves = MPPositive_LoadCoreModel.shared.songViewModels
|
|
tableView.showMessage(loves.count)
|
|
tableView.reloadData()
|
|
}
|
|
}else {
|
|
//更新离线歌曲
|
|
MPPositive_LoadCoreModel.shared.reloadLoadSongViewModel {
|
|
[weak self] in
|
|
guard let self = self else {return}
|
|
offlines = MPPositive_LoadCoreModel.shared.loadViewModels
|
|
tableView.showMessage(offlines.count)
|
|
tableView.reloadData()
|
|
}
|
|
}
|
|
}
|
|
|
|
//配置
|
|
private func configure() {
|
|
addSubview(tableView)
|
|
tableView.snp.makeConstraints { make in
|
|
make.left.top.right.bottom.equalToSuperview()
|
|
}
|
|
}
|
|
}
|
|
//MARK: - tableView
|
|
extension MPPositive_AddSongsShowView:UITableViewDataSource, UITableViewDelegate {
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return selectedIndex == 0 ? loves.count:offlines.count
|
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: MPPositive_AddSongTableViewCellID, for: indexPath) as! MPPositive_AddSongTableViewCell
|
|
cell.list = list
|
|
if selectedIndex == 0 {
|
|
cell.love = loves[indexPath.row]
|
|
}else {
|
|
cell.offline = offlines[indexPath.row]
|
|
}
|
|
return cell
|
|
}
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
if selectedIndex == 0 {
|
|
let item = loves[indexPath.row]
|
|
guard let array = list?.videosArray.filter({$0.videoId == item.collectionSong.videoId}), array.isEmpty == true else {
|
|
return
|
|
}
|
|
//添加数据
|
|
let video = try? MPPositive_CustomVideoModel.create()
|
|
video?.coverImageURL = item.coverURL
|
|
video?.title = item.title
|
|
video?.subtitle = item.collectionSong.subtitle
|
|
video?.videoId = item.collectionSong.videoId
|
|
video?.lyricsID = item.collectionSong.lyricsID
|
|
video?.relatedID = item.collectionSong.relatedID
|
|
video?.addTime = Date().timeZone()
|
|
video?.playList = list
|
|
MPPositive_CustomVideoModel.save()
|
|
MP_HUD.onlytext("Successfully added to the playlist".localizableString(), delay: 1.0) {
|
|
[weak self] in
|
|
self?.tableView.reloadData()
|
|
}
|
|
}else {
|
|
let item = offlines[indexPath.row]
|
|
guard let array = list?.videosArray.filter({$0.videoId == item.loadItem.videoId}), array.isEmpty == true else {
|
|
return
|
|
}
|
|
//添加数据
|
|
let video = try? MPPositive_CustomVideoModel.create()
|
|
video?.coverImageURL = item.reviewURL
|
|
video?.title = item.title
|
|
video?.subtitle = item.loadItem.shortBylineText
|
|
video?.videoId = item.loadItem.videoId
|
|
video?.lyricsID = item.loadItem.lyricsID
|
|
video?.relatedID = item.loadItem.relatedID
|
|
video?.addTime = Date().timeZone()
|
|
video?.playList = list
|
|
MPPositive_CustomVideoModel.save()
|
|
MP_HUD.onlytext("Successfully added to the playlist".localizableString(), delay: 1.0) {
|
|
[weak self] in
|
|
self?.tableView.reloadData()
|
|
}
|
|
}
|
|
}
|
|
}
|