240 lines
9.0 KiB
Swift
240 lines
9.0 KiB
Swift
//
|
|
// ThemeOneVC.swift
|
|
// WOKA
|
|
//
|
|
// Created by Bilal on 03/05/2024.
|
|
//
|
|
|
|
import UIKit
|
|
import Alamofire
|
|
|
|
class ThemeOneVC: UIViewController {
|
|
|
|
@IBOutlet weak var gradientView: UIView!
|
|
@IBOutlet weak var cloud2: UIImageView!
|
|
@IBOutlet weak var cloud1: UIImageView!
|
|
@IBOutlet weak var liveTVView: UIView!
|
|
@IBOutlet weak var liveTvPlayer: UIView!
|
|
@IBOutlet weak var homeGrass: UIImageView!
|
|
@IBOutlet weak var nameLabel: UILabel!
|
|
@IBOutlet weak var welcomeLabel: LocalisedElementsLabel!
|
|
@IBOutlet weak var HelloLabel: LocalisedElementsLabel!
|
|
@IBOutlet weak var liveTVIcon: UIView!
|
|
|
|
@IBOutlet weak var notificationBtnn: UIButton!
|
|
@IBOutlet weak var avatarImage: UIImageView!
|
|
|
|
@IBOutlet weak var webSeriesView: UIView!
|
|
@IBOutlet weak var audioBooksView: UIView!
|
|
@IBOutlet var star: [UIImageView]!
|
|
@IBOutlet weak var moonImage: UIImageView!
|
|
@IBOutlet weak var moreStack: UIStackView!
|
|
@IBOutlet weak var bottomArrow: UIImageView!
|
|
@IBOutlet weak var gamesView: UIView!
|
|
@IBOutlet weak var karaokeView: UIView!
|
|
@IBOutlet weak var shopView: UIView!
|
|
|
|
@IBOutlet weak var liveTVActivityIndicator: UIActivityIndicatorView!
|
|
|
|
var timer: Timer?
|
|
|
|
var vm = ThemeOneVM()
|
|
|
|
weak var delegate: ChildViewControllerDelegate?
|
|
|
|
|
|
deinit{
|
|
timer?.invalidate()
|
|
// Removing observers
|
|
NotificationCenter.default.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil)
|
|
NotificationCenter.default.removeObserver(self, name: UIApplication.willEnterForegroundNotification, object: nil)
|
|
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: K.NotificationCenterReloads.reloadTheme), object: nil)
|
|
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: K.NotificationCenterReloads.themeOnePush), object: nil)
|
|
|
|
vm.playerItem.removeObserver(self, forKeyPath: "status")
|
|
vm.avPlayer.removeObserver(self, forKeyPath: "timeControlStatus")
|
|
vm.playerItem.removeObserver(self, forKeyPath: "isPlaybackBufferEmpty")
|
|
vm.playerItem.removeObserver(self, forKeyPath: "isPlaybackLikelyToKeepUp")
|
|
vm.avPlayer.pause()
|
|
}
|
|
|
|
override var preferredStatusBarStyle: UIStatusBarStyle {
|
|
.darkContent
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
vm.vc = self
|
|
vm.initView()
|
|
|
|
if MyListDataTemp.shareInstance.favListingData?.showData == nil {
|
|
MyListDataTemp.shareInstance.favListingData = FavouriteListingDM.ResultData(showData: [], videoData: [], gameData: [], singKaraokeData: [], audioData: [])
|
|
}
|
|
// connectedToNetwork()
|
|
}
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
setNeedsStatusBarAppearanceUpdate()
|
|
}
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
vm.shouldAnimate = false
|
|
if let player = vm.avPlayer{
|
|
player.pause()
|
|
}
|
|
}
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
vm.shouldAnimate = true
|
|
K.GVar.topView = .theme1
|
|
vm.moveLiveTVView()
|
|
if let player = vm.avPlayer{
|
|
player.play()
|
|
}
|
|
}
|
|
|
|
override func viewDidLayoutSubviews() {
|
|
vm.setupAvPlayer()
|
|
self.addObservers()
|
|
}
|
|
|
|
// Define a function to customize tab bar item icon size
|
|
func customizeTabBarItemIconSize() {
|
|
// Get a reference to the tab bar controller
|
|
if let tabBarController = self.tabBarController {
|
|
// Loop through each tab bar item
|
|
for item in tabBarController.tabBar.items! {
|
|
// Adjust the image insets to increase the icon size
|
|
item.imageInsets = UIEdgeInsets(top: 2, left: -5, bottom: -8, right: -5)
|
|
item.titlePositionAdjustment.vertical = CGFloat(8)
|
|
}
|
|
}
|
|
}
|
|
|
|
@IBAction func barButtonTapped(_ sender: UIButton) {
|
|
self.sideMenuController?.revealMenu()
|
|
}
|
|
|
|
@IBAction func notificationBtnTapped(_ sender: UIButton) {
|
|
CommonNwCall.shareInstance.getUserNotification(vc: self) { isDone in
|
|
if isDone{
|
|
let sb = UIStoryboard(name: K.StoryBoard.theme, bundle: nil)
|
|
let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Home.userNotificationVC) as! UserNotificationVC
|
|
self.navigationController?.pushViewController(vcPush, animated: true)
|
|
}
|
|
}
|
|
}
|
|
|
|
@IBAction func radioBtnTapped(_ sender: UIButton) {
|
|
let sb = UIStoryboard(name: K.StoryBoard.wokaFM, bundle: nil)
|
|
let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.WokaFM.wokaFMVC) as! WokaFMVC
|
|
vcPush.modalPresentationStyle = .overCurrentContext
|
|
vcPush.modalTransitionStyle = .crossDissolve
|
|
self.present(vcPush, animated: true)
|
|
}
|
|
}
|
|
|
|
// MARK: - Handle Live TV Observer
|
|
|
|
extension ThemeOneVC{
|
|
func startMonitoring(){
|
|
NetworkReachibility.shared.startMonitoring { [weak self] isConnected in
|
|
guard let self else{return}
|
|
switch isConnected{
|
|
case true: // if network is connected than stop
|
|
// when internet is back we have to setup player again
|
|
NetworkReachibility.shared.stopMonitoring()
|
|
// vm.avPlayer.play()
|
|
print("network connection is back")
|
|
case false:
|
|
// if there is no internet connection prompt user and show reload icon
|
|
self.toast(msg: "Lost Connection.", time: 1.4)
|
|
liveTVActivityIndicator.stopAnimating()
|
|
}
|
|
}
|
|
}
|
|
|
|
func addObservers() {
|
|
// Observe the player's status
|
|
vm.playerItem.addObserver(self, forKeyPath: "status", options: [.new, .old], context: nil)
|
|
|
|
// Observe the player's time control status
|
|
vm.avPlayer.addObserver(self, forKeyPath: "timeControlStatus", options: [.new, .old], context: nil)
|
|
|
|
// Observe buffering status
|
|
vm.playerItem.addObserver(self, forKeyPath: "isPlaybackBufferEmpty", options: [.new, .old], context: nil)
|
|
vm.playerItem.addObserver(self, forKeyPath: "isPlaybackLikelyToKeepUp", options: [.new, .old], context: nil)
|
|
}
|
|
|
|
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
|
if keyPath == "status" {
|
|
if vm.playerItem.status == .readyToPlay {
|
|
print("Player is ready to play")
|
|
vm.avPlayer.play()
|
|
} else if vm.playerItem.status == .failed {
|
|
print("Player failed to load")
|
|
if !liveTVActivityIndicator.isAnimating{
|
|
liveTVActivityIndicator.startAnimating()
|
|
}
|
|
}
|
|
} else if keyPath == "timeControlStatus" {
|
|
switch vm.avPlayer.timeControlStatus {
|
|
case .playing:
|
|
print("Player is playing")
|
|
liveTVActivityIndicator.stopAnimating()
|
|
case .paused:
|
|
print("Player is paused")
|
|
vm.avPlayer.play()
|
|
liveTVActivityIndicator.stopAnimating()
|
|
case .waitingToPlayAtSpecifiedRate:
|
|
print("Player is Buffering 1")
|
|
if !(NetworkReachabilityManager()?.isReachable ?? false){
|
|
if !NetworkReachibility.shared.isMonitoring{
|
|
startMonitoring()
|
|
}
|
|
}
|
|
@unknown default:
|
|
break
|
|
}
|
|
} else if keyPath == "isPlaybackBufferEmpty" {
|
|
if vm.playerItem.isPlaybackBufferEmpty {
|
|
print("Player is buffering 2")
|
|
liveTVActivityIndicator.startAnimating()
|
|
startMonitoring()
|
|
}
|
|
} else if keyPath == "isPlaybackLikelyToKeepUp" {
|
|
if vm.playerItem.isPlaybackLikelyToKeepUp {
|
|
print("Player is likely to keep up with the playback")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class NavigationController: UINavigationController {
|
|
|
|
open override var childForStatusBarHidden: UIViewController? {
|
|
return self.topViewController
|
|
}
|
|
|
|
open override var childForStatusBarStyle: UIViewController? {
|
|
return self.topViewController
|
|
}
|
|
}
|
|
|
|
|
|
extension UINavigationController {
|
|
func pushWithPopInAnimation(_ viewController: UIViewController, duration: CFTimeInterval = 0.3) {
|
|
let transition = CATransition()
|
|
transition.duration = duration
|
|
transition.type = CATransitionType.push
|
|
transition.subtype = CATransitionSubtype.fromRight
|
|
|
|
// Customize the animation to look like a "pop-in"
|
|
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
|
|
|
|
self.view.layer.add(transition, forKey: kCATransition)
|
|
self.pushViewController(viewController, animated: false)
|
|
}
|
|
}
|