Music_Player3/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Center(个人曲库页)/MPPositive_LibraryViewController.swift
2024-09-11 18:21:34 +08:00

307 lines
14 KiB
Swift

//
// MPPositive_LibraryViewController.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/4/19.
//
import UIKit
import Kingfisher
class MPPositive_LibraryViewController: MPPositive_BaseViewController, UIViewControllerTransitioningDelegate {
///
private lazy var backGroundImageView:UIImageView = {
let imageView:UIImageView = .init(frame: .init(x: 0, y: 0, width: screen_Width, height: 812*width))
imageView.image = UIImage(named: "Center_Mask'bg")
imageView.contentMode = .scaleAspectFill
return imageView
}()
//Label
private lazy var titleLabel:UILabel = createLabel(NSLocalizedString("Library", comment: "曲库"), font: .italicSystemFont(ofSize: 32*width), textColor: .white, textAlignment: .left)
///
private lazy var coverImageViews:[UIImageView] = {
var array:[UIImageView] = []
for index in 0...2{
let imageView:UIImageView = .init()
imageView.contentMode = .scaleAspectFill
imageView.tag = index
imageView.image = placeholderImage
array.append(imageView)
}
return array
}()
///Label
private lazy var songsLabel:UILabel = createLabel("0", font: .systemFont(ofSize: 26*width, weight: .bold), textColor: .white, textAlignment: .left)
///Label
private lazy var artistsLabel:UILabel = createLabel("0", font: .systemFont(ofSize: 26*width, weight: .bold), textColor: .white, textAlignment: .left)
///Label
private lazy var loadsLabel:UILabel = createLabel("0", font: .systemFont(ofSize: 26*width, weight: .bold), textColor: .white, textAlignment: .left)
///View
private lazy var actionViews:UIView = showTopView()
///广View
fileprivate lazy var adContainerView:UIView = {
let adContainerView:UIView = .init(frame: .init(x: 0, y: 0, width: screen_Width, height: 300*width))
adContainerView.backgroundColor = .clear
return adContainerView
}()
//MARK: -
//View
private lazy var segmentView:JXSegmentedView = {
var jxSegmentView = JXSegmentedView()
jxSegmentView.backgroundColor = .clear
return jxSegmentView
}()
//
private lazy var dataSource:JXSegmentedTitleDataSource = {
var dataSource = JXSegmentedTitleDataSource()
dataSource.titles = ["Playlists".localizableString(), "Collect Playlists".localizableString()]
//
dataSource.titleNormalColor = .init(hex: "#999999")
dataSource.titleNormalFont = .systemFont(ofSize: 14*width, weight: .regular)
//
dataSource.titleSelectedColor = .white
dataSource.titleSelectedFont = .systemFont(ofSize: 14*width, weight: .regular)
dataSource.itemSpacing = 16*width
dataSource.isItemSpacingAverageEnabled = false
//
dataSource.isTitleColorGradientEnabled = true
dataSource.isSelectedAnimable = true
dataSource.isItemTransitionEnabled = true
return dataSource
}()
//
private lazy var indicator:JXSegmentedIndicatorLineView = {
let indicator = JXSegmentedIndicatorLineView()
indicator.indicatorWidth = 20*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
}()
override func viewDidLoad() {
super.viewDidLoad()
setTitle("")
configure()
view.backgroundColor = .init(hex: "#000000")
MP_AdMobManager.shared.loadLibraryNativeAd()
MP_AdMobManager.shared.layoutLibraryNativeAd(in: adContainerView, index: 0)
MP_AdMobManager.shared.onLibraryNativeAdBlock = {
[weak adContainerView] in
guard let adContainerView = adContainerView else {return}
MP_AdMobManager.shared.layoutLibraryNativeAd(in: adContainerView, index: 0)
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
MP_AnalyticsManager.shared.me_b_pvAction()
reload()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}
//
private func reload() {
MPPositive_LoadCoreModel.shared.reloadCollectionListViewModels {
[weak self] in
guard let self = self else {return}
//
songsLabel.text = "\(MPPositive_LoadCoreModel.shared.songViewModels.count)"
coverImageViews[0].image = love_songBGImage
artistsLabel.text = "\(MPPositive_LoadCoreModel.shared.artistViewModels.count)"
coverImageViews[1].image = love_artistBGImage
loadsLabel.text = "\(MPPositive_LoadCoreModel.shared.loadViewModels.count)"
coverImageViews[2].image = offline_songBGImage
}
}
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return MPPositive_PresentationController(presentedViewController: presented, presenting: presenting)
}
private func configure() {
view.addSubview(backGroundImageView)
navView.addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16*width)
make.centerY.equalToSuperview()
}
//广
view.addSubview(adContainerView)
adContainerView.snp.makeConstraints { make in
make.top.equalTo(navView.snp.bottom).offset(20*width)
make.left.right.equalToSuperview()
make.height.equalTo(0)
}
//
view.addSubview(actionViews)
actionViews.snp.makeConstraints { make in
make.top.equalTo(adContainerView.snp.bottom).offset(24*width)
make.left.right.equalToSuperview()
make.height.equalTo(109*width)
}
//
segmentView.indicators = [indicator]
segmentView.dataSource = dataSource
view.addSubview(segmentView)
segmentView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(actionViews.snp.bottom).offset(20*width)
make.height.equalTo(45*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
}
//View
private func showTopView() -> UIView {
let topView = UIView()
topView.backgroundColor = .clear
//
let first = actionView(songsLabel, text: "SONG", tag: 0)
topView.addSubview(first)
first.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.height.width.equalTo(109*width)
make.left.equalToSuperview().offset(16*width)
}
let second = actionView(artistsLabel, text: "ARTIST", tag: 1)
topView.addSubview(second)
second.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.height.width.equalTo(109*width)
make.centerX.equalToSuperview()
}
let third = actionView(loadsLabel, text: "OFFLINE", tag: 2)
topView.addSubview(third)
third.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.height.width.equalTo(109*width)
make.right.equalToSuperview().offset(-16*width)
}
topView.isUserInteractionEnabled = true
return topView
}
//View
private func actionView(_ countLabel:UILabel, text:String, tag:Int) -> UIView {
let actionView = UIView()
actionView.backgroundColor = .clear
//
actionView.layer.masksToBounds = true
actionView.layer.cornerRadius = 8*width
//
actionView.addSubview(coverImageViews[tag])
coverImageViews[tag].snp.makeConstraints { make in
make.left.top.right.bottom.equalToSuperview()
}
//
let titlelLabel = createLabel(text, font: .systemFont(ofSize: 10*width, weight: .semibold), textColor: .white, textAlignment: .left)
actionView.addSubview(titlelLabel)
titlelLabel.snp.makeConstraints { make in
make.top.left.equalTo(10*width)
}
//
actionView.addSubview(countLabel)
countLabel.snp.makeConstraints { make in
make.left.equalTo(titlelLabel.snp.left)
make.top.equalTo(titlelLabel.snp.bottom).offset(8*width)
make.right.equalToSuperview().offset(-10*width)
}
actionView.tag = tag
actionView.isUserInteractionEnabled = true
actionView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(actionClick(_:))))
return actionView
}
//
@objc private func actionClick(_ sender:UITapGestureRecognizer) {
let tag = sender.view?.tag
switch tag {
case 0:
MP_AnalyticsManager.shared.library_clickAction("tab page", folder: "love")
let loveSongsVC = MPPositive_LoveSongsViewController()
navigationController?.pushViewController(loveSongsVC, animated: true)
case 1:
MP_AnalyticsManager.shared.library_clickAction("tab page", folder: "artist")
let loveArtistsVC = MPPositive_LoveArtistsViewController()
navigationController?.pushViewController(loveArtistsVC, animated: true)
default:
MP_AnalyticsManager.shared.library_clickAction("tab page", folder: "offline")
let offlineVC = MPPositive_OfflineSongsViewController()
navigationController?.pushViewController(offlineVC, animated: true)
}
MP_AdMobManager.shared.showLibraryInterstitialAdIfAvailable(completion: nil)
}
}
//MARK: - JXSegmentedTitleDataSource
extension MPPositive_LibraryViewController:JXSegmentedListContainerViewDataSource, JXSegmentedViewDelegate{
func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
return dataSource.titles.count
}
func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
switch index {
case 0://
let showView:MPPositive_PlayListsShowTypeView = .init(frame: listContainerView.frame)
showView.addBlock = {
[weak self] in
guard let self = self else {return}
//
MPPositive_ModalType = .NewList
let listVC = MPSideA_RenameViewController()
listVC.titleText = "Name Your PlayList".localizableString()
listVC.renameBlock = {
[weak self] text in
//
let list = try? MPPositive_CustomPlayListModel.create()
list?.playListId = Date().timeZone().toString(.custom("YYYY/MM/dd/HH:mm:ss"))
list?.title = text
list?.createTime = Date().timeZone()
list?.sortType = 0
list?.addToRelationshipToCustomVideos([])
MPPositive_CustomPlayListModel.save()
MP_AnalyticsManager.shared.create_list_actionAction()
//
print("成功新建\(text)歌单")
//
NotificationCenter.notificationKey.post(notificationName: .create_custom_playlist)
}
listVC.transitioningDelegate = self
listVC.modalPresentationStyle = .custom
present(listVC, animated: true)
}
showView.chooseBlock = {
[weak self] item in
guard let self = self else {return}
MP_AnalyticsManager.shared.library_clickAction("tab page", folder: "custom")
//
let playListVC = MPPositive_CustomPlayListViewController(item.playList)
navigationController?.pushViewController(playListVC, animated: true)
MP_AdMobManager.shared.showLibraryInterstitialAdIfAvailable(completion: nil)
}
return showView
default://
let showView:MPPositive_CollectionListsShowTypeView = .init(frame: listContainerView.frame)
showView.chooseBlock = {
[weak self] item in
guard let self = self else {return}
let listVC = MPPositive_ListShowViewController(item.collectionList.browseId ?? "", params: item.collectionList.params ?? "", title: item.collectionList.title ?? "", subtitle: item.collectionList.subtitle ?? "", clickTrackingParams: "")
navigationController?.pushViewController(listVC, animated: true)
}
return showView
}
}
}