- Updated ADs api, Changed the whole response. - Made changes on webseries for local ads and google ads, improvised the logic. - Added logic on theme 2 to show google ad - Karaoke updated for google ads and normal ads. - Audio Books updated for google ads and normal ads. - FM updated for google ads. - Karaoke Player updated for google ads. - Games WebView updated for google ads. - Games Details Interstitial AD updated for google ads. - Games List updated for google and local ads.
101 lines
3.8 KiB
Swift
101 lines
3.8 KiB
Swift
//
|
|
// HomeVC.swift
|
|
// WOKA
|
|
//
|
|
// Created by Bilal on 24/05/2024.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
protocol ChildViewControllerDelegate: AnyObject {
|
|
func didPressSwitchButton(from viewController: UIViewController)
|
|
}
|
|
|
|
class HomeVC: UIViewController ,ChildViewControllerDelegate{
|
|
|
|
@IBOutlet weak var containerView: UIView!
|
|
var currentChildViewController: UIViewController?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
//setup google ads for fullscreen if its turned on.
|
|
if let adsData = AuthFunc.shareInstance.adsData, let gamesIntersitialAd = adsData.result?.filter({$0.slug == AdsEnum.gameInterestial.rawValue}).first, gamesIntersitialAd.googleAd != nil{
|
|
/*
|
|
setup google ads.
|
|
*/
|
|
GoogleInterstistialADSetup.shareInstance.setupGoogleIntersitialAD()
|
|
}
|
|
|
|
switch AuthFunc.shareInstance.selectedTheme {
|
|
case .theme1:
|
|
let sb = UIStoryboard(name: K.StoryBoard.theme, bundle: nil)
|
|
if let firstVC = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Theme.themeOneVC) as? ThemeOneVC {
|
|
add(asChildViewController: firstVC)
|
|
firstVC.delegate = self
|
|
}
|
|
case .theme2:
|
|
let sb = UIStoryboard(name: K.StoryBoard.theme, bundle: nil)
|
|
if let firstVC = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Theme.themeTwoVC) as? ThemeTwoVC {
|
|
add(asChildViewController: firstVC)
|
|
firstVC.delegate = self
|
|
}
|
|
}
|
|
}
|
|
|
|
func didPressSwitchButton(from viewController: UIViewController) {
|
|
if viewController is ThemeOneVC {
|
|
switchToViewController(withIdentifier: K.StoryBoardID.Theme.themeTwoVC)
|
|
} else if viewController is ThemeTwoVC {
|
|
switchToViewController(withIdentifier: K.StoryBoardID.Theme.themeOneVC)
|
|
}
|
|
}
|
|
|
|
|
|
private func switchToViewController(withIdentifier identifier: String) {
|
|
let sb = UIStoryboard(name: K.StoryBoard.theme, bundle: nil)
|
|
let newVC = sb.instantiateViewController(withIdentifier: identifier)
|
|
if let newVC = newVC as? ThemeOneVC {
|
|
newVC.delegate = self
|
|
} else if let newVC = newVC as? ThemeTwoVC {
|
|
newVC.delegate = self
|
|
}
|
|
|
|
print("Switching to view controller with identifier \(identifier)")
|
|
DispatchQueue.main.async { [weak self] in
|
|
guard let self else{return}
|
|
self.replaceCurrentChildViewController(with: newVC)
|
|
}
|
|
}
|
|
|
|
private func add(asChildViewController viewController: UIViewController) {
|
|
print("Adding child view controller: \(viewController)")
|
|
addChild(viewController)
|
|
viewController.view.frame = containerView.bounds
|
|
containerView.addSubview(viewController.view)
|
|
viewController.didMove(toParent: self)
|
|
currentChildViewController = viewController
|
|
}
|
|
|
|
private func remove(asChildViewController viewController: UIViewController, onCompletion : @escaping () -> Void) {
|
|
print("Removing child view controller: \(viewController)")
|
|
viewController.willMove(toParent: nil)
|
|
viewController.view.removeFromSuperview()
|
|
viewController.removeFromParent()
|
|
onCompletion()
|
|
}
|
|
|
|
private func replaceCurrentChildViewController(with newViewController: UIViewController) {
|
|
// Clear previous views
|
|
containerView.subviews.forEach { $0.removeFromSuperview() }
|
|
|
|
// Remove current child view controller if exists
|
|
if let currentVC = currentChildViewController {
|
|
remove(asChildViewController: currentVC) { [weak self] in
|
|
guard let self else{return}
|
|
// Add new child view controller
|
|
add(asChildViewController: newViewController)
|
|
}
|
|
}
|
|
}
|
|
}
|