Music_Player3/relax.offline.mp3.music/MP/MPSideA/ViewControllers/Home(音乐资源列表)/MPSideA_HomeViewController.swift

115 lines
4.7 KiB
Swift

//
// HomeViewController.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/3/27.
//
import UIKit
class MPSideA_HomeViewController: MPSideA_BaseViewController {
@IBOutlet weak var tableView: UITableView!{
didSet{
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
tableView.contentInsetAdjustmentBehavior = .never
tableView.estimatedRowHeight = 200
tableView.rowHeight = UITableView.automaticDimension
tableView.tableHeaderView = headView
//
tableView.contentInset = .init(top: 0, left: 0, bottom: 100*width, right: 0)
tableView.dataSource = self
tableView.delegate = self
tableView.register(UINib(nibName: Home_RowListsTableViewCellID, bundle: nil), forCellReuseIdentifier: Home_RowListsTableViewCellID)
}
}
private lazy var headView:MPSideA_Home_HeadBannerView = .init(frame: .init(x: 0, y: 0, width: screen_Width, height: 135*width))
private let Home_RowListsTableViewCellID = "MPSideA_Home_RowListsTableViewCell"
//
private lazy var sectionTitles:[String] = ["", MPSideA_MusicShowType.First.title, MPSideA_MusicShowType.Second.title, MPSideA_MusicShowType.Third.title]
override func viewDidLoad() {
super.viewDidLoad()
MP_AdMobManager.shared.loadAnyAdMobs()
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
//
requestTrackingAuthorization { idfa in
}
}
//
nullMusicAction = {
[weak self] in
//
self?.reload()
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
MP_AnalyticsManager.shared.home_a_pvAction()
//
NotificationCenter.notificationKey.add(observer: self, selector: #selector(fileMissAction(_ :)), notificationName: .sideA_null_music)
// NotificationCenter.notificationKey.add(observer: self, selector: #selector(switchPlayerStateAction(_ :)), notificationName: .play_music)
// NotificationCenter.notificationKey.add(observer: self, selector: #selector(switchPlayerStateAction(_ :)), notificationName: .stop_music)
// NotificationCenter.notificationKey.add(observer: self, selector: #selector(switchPlayerStateAction(_ :)), notificationName: .resume_music)
// NotificationCenter.notificationKey.add(observer: self, selector: #selector(switchPlayerStateAction(_ :)), notificationName: .pause_music)
reload()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
//
NotificationCenter.default.removeObserver(self)
}
deinit {
}
//
private func reload() {
MPSideA_LoadDataMusic.shared.reloadListData()
tableView.reloadData()
}
// //
// @objc private func switchPlayerStateAction(_ sender:Notification) {
// //
// tableView.reloadData()
// }
}
//MARK: - tableView
extension MPSideA_HomeViewController:UITableViewDataSource, UITableViewDelegate {
func numberOfSections(in tableView: UITableView) -> Int {
return sectionTitles.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: Home_RowListsTableViewCellID, for: indexPath) as! MPSideA_Home_RowListsTableViewCell
cell.layout = .init(rawValue: indexPath.section) ?? .Zero
return cell
}
//View
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let sectionView:UIView = .init(frame: .init(x: 0, y: 0, width: screen_Width, height: 40*width))
sectionView.backgroundColor = .clear
//Label
let label = UILabel()
label.textColor = .white
label.font = .systemFont(ofSize: 20, weight: .regular)
label.text = sectionTitles[section]
sectionView.addSubview(label)
label.snp.makeConstraints { make in
make.left.equalToSuperview().offset(16*width)
make.top.equalToSuperview()
}
return sectionView
}
//View
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return section != 0 ? 40*width:0
}
}