Music_Player3/relax.offline.mp3.music/MP/MPSideA/ViewControllers/Center(个人资源)/MPSideA_SettingViewController.swift
2024-08-15 15:50:48 +08:00

153 lines
7.4 KiB
Swift

//
// SettingViewController.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/4/10.
//
import UIKit
class MPSideA_SettingViewController: MPSideA_BaseViewController {
@IBOutlet weak var tableView: UITableView!{
didSet{
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
tableView.rowHeight = 70*width
tableView.dataSource = self
tableView.delegate = self
tableView.register(UINib(nibName: SettingTableViewCellID, bundle: nil), forCellReuseIdentifier: SettingTableViewCellID)
}
}
@IBOutlet weak var setLabel: UILabel!{
didSet{
setLabel.text = NSLocalizedString("Setting", comment: "设置页")
}
}
private let SettingTableViewCellID = "MPSideA_SettingTableViewCell"
private lazy var titles:[String] = ["About","Feedback","Share","Privacy Policy","Terms of Use","Clear Cache"]
var cleanSide:Bool = false
var setblock:(() -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func popClick(_ sender: UIButton) {
if setblock != nil {
setblock!()
}
navigationController?.popViewController(animated: true)
}
}
//MARK: - tableView
extension MPSideA_SettingViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titles.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: SettingTableViewCellID, for: indexPath) as! MPSideA_SettingTableViewCell
cell.title = titles[indexPath.row]
switch indexPath.row {
case titles.count - 1:
cell.sizeLabel.isHidden = !cleanSide
default:
cell.sizeLabel.isHidden = true
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 0://About
let aboutVC = MPSideA_AboutViewController()
navigationController?.pushViewController(aboutVC, animated: true)
case 1://Feedback
let alert = UIAlertController(title: NSLocalizedString("Feedback".localizableString(), comment: ""), message: NSLocalizedString("If you have any comments or suggestions, please contact us at the following e-mail address".localizableString(), comment: ""), preferredStyle: .actionSheet)
let email = UIAlertAction(title: "marketing@lux-ad.com", style: .default) { (_) in
//
UIPasteboard.general.string = "marketing@lux-ad.com"
MP_HUD.text(NSLocalizedString("Successfully copied the e-mail address to the clipboard".localizableString(), comment: ""), delay: 1.0, completion: nil)
}
alert.addAction(email)
let cancel = UIAlertAction(title: NSLocalizedString("Cancel".localizableString(), comment: ""), style: .cancel)
alert.addAction(cancel)
present(alert, animated: true)
case 2://Share
//
let text = App_Name
//icon
let image = UIImage(named: "ICON")
//
let url = URL(string: "https://musiclax.mystrikingly.com/")
let activityItems = [text,image as Any,url as Any]
//
let activityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities:nil)
present(activityViewController, animated: true, completion: nil)
//
activityViewController.completionWithItemsHandler = { [weak self] ( activityType, isCompleted, returnedItems, error) -> Void in
print(isCompleted ? "Share Success":"Share Failure")
}
case 3:
MP_NetWorkManager.shared.requestNetworkPermission(oberve: self) {
[weak self] in
let privacyVC = MPSideA_PrivacyViewController()
self?.navigationController?.pushViewController(privacyVC, animated: true)
}
case 4:
MP_NetWorkManager.shared.requestNetworkPermission(oberve: self) {
[weak self] in
let serviceVC = MPSideA_ServiceViewController()
self?.navigationController?.pushViewController(serviceVC, animated: true)
}
default://
if cleanSide {
//B
let alertController = UIAlertController(title: "Clear Cache".localizableString(), message: "Clearing B".localizableString(), preferredStyle: .alert)
let cancel = UIAlertAction(title: "Cancel".localizableString(), style: .cancel)
alertController.addAction(cancel)
let sure = UIAlertAction(title: "Confirm".localizableString(), style: .destructive) { [weak self] (action) in
MP_HUD.loading()
MP_CacheAndArchiverManager.shared.cleanAllCache { statu in
if statu {
//
MP_HUD.hideNow()
MP_HUD.success("Success".localizableString(), delay: 1.0, completion: nil)
}else {
//
MP_HUD.hideNow()
MP_HUD.error("Failure".localizableString(), delay: 1.0, completion: nil)
}
tableView.reloadData()
}
}
alertController.addAction(sure)
present(alertController, animated: true)
}else {
//A
let alertController = UIAlertController(title: "Clear Cache".localizableString(), message: "Clearing A".localizableString(), preferredStyle: .alert)
let cancel = UIAlertAction(title: "Cancel".localizableString(), style: .cancel)
alertController.addAction(cancel)
let sure = UIAlertAction(title: "Confirm".localizableString(), style: .destructive) { [weak self] (action) in
MP_HUD.loading()
MPSideA_LoadDataMusic.shared.userlistMusics.forEach { music in
//
if music.music.identifier == MPSideA_MediaCenterManager.shared.getMusic()?.identifier {
MPSideA_MediaCenterManager.shared.setMusic(nil)
//
MPSideA_MediaCenterManager.shared.playerStop()
//
NotificationCenter.notificationKey.post(notificationName: .sideA_close_show)
}
MPSideA_MusicModel.delete(music.music)
}
MP_HUD.hideNow()
MP_HUD.success("Success".localizableString(), delay: 1.0, completion: nil)
tableView.reloadData()
}
alertController.addAction(sure)
present(alertController, animated: true)
}
}
}
}