Music_Player3/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Base(基类,导航栏,标签栏)/MPPositive_TabBarController.swift

316 lines
14 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MPPositive_TabBarController.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/4/19.
//
import UIKit
import AppLovinSDK
///btabBar
class MPPositive_TabBarController: UITabBarController, UIViewControllerTransitioningDelegate, GADFullScreenContentDelegate, MAAdDelegate {
//tabBar
private lazy var customTabBar:MPPositive_CustomTabBar = .init(frame: .init(x: 0, y: 0, width: screen_Width, height: 72*width))
private lazy var bottomView:MPPositive_BottomShowView = .init(frame: .init(x: 0, y: 0, width: 351, height: 82))
//
private var isbottomShow:Bool = false{
willSet{
if isbottomShow != newValue {
switch_bottomShowAnimation(newValue)
}
}
}
//Push
private var isPush:Bool = false
var pushPlayerBlock:(() -> Void)?
override func viewDidLoad() {
super.viewDidLoad()
self.setValue(customTabBar, forKey: "tabBar")
//
let homeVC = MPPositive_NavigationController(rootViewController: MPPositive_HomeViewController())
let searchVC = MPPositive_NavigationController(rootViewController: MPPositive_SearchViewController())
let libraryVC = MPPositive_NavigationController(rootViewController: MPPositive_LibraryViewController())
viewControllers = [homeVC,searchVC,libraryVC]
//tabBaritem
tabBar.items?.forEach({ item in
item.isEnabled = false
})
tabBar.barTintColor = .clear
UITabBar.appearance().backgroundColor = .clear
tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
//View
view.addSubview(bottomView)
//View
bottomView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.bottom.equalToSuperview().offset(82*width)
make.width.equalTo(351*width)
make.height.equalTo(82*width)
}
bottomView.showListBlock = {
[weak self] in
if MP_PlayerManager.shared.loadPlayer != nil {
MPPositive_ModalType = .PlayerList
let listVC = MPPositive_PlayerListShowViewController()
listVC.transitioningDelegate = self
listVC.modalPresentationStyle = .custom
self?.present(listVC, animated: true)
}
}
bottomView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(playerClick(_ :))))
addNotification()
//
updateVersionEvent()
//线
guard MP_NetWorkManager.shared.netWorkStatu != .reachable else {
return
}
//线
selectedIndex = 2
}
//
private func addNotification() {
//
NotificationCenter.notificationKey.add(observer: self, selector: #selector(switchAction(_:)), notificationName: .switch_tabBarItem)
//
NotificationCenter.notificationKey.add(observer: self, selector: #selector(pupPlayerAction), notificationName: .pup_player_vc)
NotificationCenter.notificationKey.add(observer: self, selector: #selector(bottomAnimationAction(_:)), notificationName: .pup_bottom_show)
NotificationCenter.notificationKey.add(observer: self, selector: #selector(bottomAnimationAction(_:)), notificationName: .player_delete_list)
NotificationCenter.notificationKey.add(observer: self, selector: #selector(pushAction(_ :)), notificationName: .positive_nav_push)
NotificationCenter.notificationKey.add(observer: self, selector: #selector(popAction(_ :)), notificationName: .positive_nav_pop)
NotificationCenter.notificationKey.add(observer: self, selector: #selector(updateVersionEvent), notificationName: .update_reminder)
}
deinit {
//
NotificationCenter.default.removeObserver(self)
}
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return MPPositive_PresentationController(presentedViewController: presented, presenting: presenting)
}
//
@objc private func updateVersionEvent() {
//
guard isUpDateReminder == true else {
//
return
}
//
DispatchQueue.main.async {
//
postUpdateReminder(self)
}
}
}
//MARK: -
extension MPPositive_TabBarController {
//
@objc private func switchAction(_ sender:Notification) {
let tag = sender.object as! Int
selectedIndex = tag
}
@objc private func playerClick(_ sender:UITapGestureRecognizer) {
MP_AnalyticsManager.shared.song_clickAction("Player")
pupPlayerAction()
}
//player
@objc private func pupPlayerAction() {
//block
self.pushPlayerBlock = {
[weak self] in
//
DispatchQueue.main.async {
[weak self] in
let playerVC = MPPositive_PlayerViewController()
playerVC.modalPresentationStyle = .fullScreen
playerVC.recommendBlock = {
let recommendVC = MPPositive_RecommendViewController(MP_PlayerManager.shared.loadPlayer?.currentVideo?.song.relatedID ?? "")
self?.viewControllers![self?.selectedIndex ?? 0].children[0].navigationController?.pushViewController(recommendVC, animated: false)
}
playerVC.searchBlock = { (text) in
MP_AnalyticsManager.shared.search_from_actionAction("player page")
let resultVC = MPPositive_SearchResultShowViewController(text, isShowAd: false)
self?.viewControllers![self?.selectedIndex ?? 0].children[0].navigationController?.pushViewController(resultVC, animated: false)
}
self?.present(playerVC, animated: true)
}
}
MP_ADSimpleManager.shared.showPlayInterstitialAdIfAvailable { [weak self] (ad, platform) in
guard let self = self else {return}
if platform {
if let ad = ad as? MAInterstitialAd {
//
MP_AppLovinManager.shared.setInterstitialSwitch(true)
MP_AppLovinManager.shared.isShowingPlayInterstitialAd = true
ad.delegate = self
ad.show()
}else {
if let block = self.pushPlayerBlock {
block()
}
}
}else {
if let ad = ad as? GADInterstitialAd {
//
MP_AdMobManager.shared.isShowingPlayInterstitialAd = true
//广
MP_AdMobManager.shared.setInterstitialSwitch(true)
ad.fullScreenContentDelegate = self
ad.present(fromRootViewController: self)
}else {
if let block = self.pushPlayerBlock {
block()
}
}
}
}
}
//
@objc private func bottomAnimationAction(_ sender:Notification) {
isbottomShow = MP_PlayerManager.shared.loadPlayer != nil
}
//BottomView
private func switch_bottomShowAnimation(_ state:Bool) {
UIView.animate(withDuration: 0.3) {
[weak self] in
guard let self = self else { return }
if state {
//
bottomView.transform = .init(translationX: 0, y: isPush ? -82*width:-145*width)
}else {
//
bottomView.transform = .identity
}
}
}
//push
@objc private func pushAction(_ sender:Notification) {
isPush = true
//
if isbottomShow == true {
//bottomView83
UIView.animate(withDuration: 0.3) {
[weak self] in
guard let self = self else { return }
bottomView.transform = .init(translationX: 0, y: -82*width)
}
}
}
@objc private func popAction(_ sender:Notification) {
isPush = false
//
if isbottomShow == true {
//bottomView83
UIView.animate(withDuration: 0.3) {
[weak self] in
guard let self = self else { return }
bottomView.transform = .init(translationX: 0, y: -145*width)
}
}
}
//MARK: - 广 GADFullScreenContentDelegate
//广
func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
// UIApplication.shared.isStatusBarHidden = true
if ad === MP_AdMobManager.shared.playInterstitialAd {//广
print("当前展示的广告是播放插页广告广告ID--\(MP_AdMobManager.shared.playInterstitialAd?.adUnitID ?? "")")
if MP_AnalyticsManager.shared.infoFromAdMobSource(MP_AdMobManager.shared.playInterstitialAd?.responseInfo) {
MP_AdMobManager.shared.playInterstitialAd?.paidEventHandler = { adValue in
if let response = MP_AdMobManager.shared.playInterstitialAd?.responseInfo {
MP_AnalyticsManager.shared.play_ads_showSuccessAction(response, adValue: adValue)
}
}
}else {
if let response = MP_AdMobManager.shared.playInterstitialAd?.responseInfo {
MP_AnalyticsManager.shared.play_ads_showSuccessAction(response, adValue: .init())
}
}
}
}
//广
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
// UIApplication.shared.isStatusBarHidden = false
MP_AdMobManager.shared.interstitialDate = Date()
if ad === MP_AdMobManager.shared.playInterstitialAd {//广
let UUID = MP_AdMobManager.shared.playInterstitialAd?.adUnitID ?? ""
print("当前消失的广告是播放插页广告广告ID--\(UUID)")
//广
if MP_AdMobManager.shared.completePlayInterstitialAdBlock != nil {
MP_AdMobManager.shared.completePlayInterstitialAdBlock!()
}
if let block = self.pushPlayerBlock {
block()
}
}
}
//广
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
// UIApplication.shared.isStatusBarHidden = false
MP_AdMobManager.shared.interstitialDate = Date()
if ad === MP_AdMobManager.shared.playInterstitialAd {//广
let UUID = MP_AdMobManager.shared.playInterstitialAd?.adUnitID ?? ""
print("播放插页广告展示时出错广告ID--\(UUID),具体错误原因:\(error.localizedDescription)")
MP_AnalyticsManager.shared.play_ads_showFailureAction(error.localizedDescription)
//广
if MP_AdMobManager.shared.completePlayInterstitialAdBlock != nil {
MP_AdMobManager.shared.completePlayInterstitialAdBlock!()
}
}
}
//MARK: - AppLovin
func didLoad(_ ad: MAAd) {
}
func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) {
}
func didDisplay(_ ad: MAAd) {
if ad.adUnitIdentifier == MP_AppLovinManager.shared.playInterstitialAd?.adUnitIdentifier {
print("当前展示的广告是播放插页广告广告ID--\(ad.adUnitIdentifier)")
MP_AnalyticsManager.shared.max_play_showSuccessAction()
}
}
func didHide(_ ad: MAAd) {
MP_AppLovinManager.shared.interstitialDate = Date()
if ad.adUnitIdentifier == MP_AppLovinManager.shared.playInterstitialAd?.adUnitIdentifier {
print("当前消失的广告是播放插页广告广告ID--\(ad.adUnitIdentifier)")
//广
if MP_AppLovinManager.shared.completePlayInterstitialAdBlock != nil {
MP_AppLovinManager.shared.completePlayInterstitialAdBlock!()
}
if let block = self.pushPlayerBlock {
block()
}
}
}
func didClick(_ ad: MAAd) {
}
func didFail(toDisplay ad: MAAd, withError error: MAError) {
MP_AppLovinManager.shared.interstitialDate = Date()
if ad.adUnitIdentifier == MP_AppLovinManager.shared.playInterstitialAd?.adUnitIdentifier {
print("播放插页广告展示时出错广告ID--\(ad.adUnitIdentifier)")
MP_AnalyticsManager.shared.max_play_showFailureAction(error.message)
//广
if MP_AppLovinManager.shared.completePlayInterstitialAdBlock != nil {
MP_AppLovinManager.shared.completePlayInterstitialAdBlock!()
}
if let block = self.pushPlayerBlock {
block()
}
}
}
}