- Added localisation to theme 1, also updated the English localisation for reversing the language - Added localisation to the sidebar. Also handled the live language change with the help of observers - Integrated GetUserData API at splash. - Added the login NAv. Now if user will logout he will be redirected to the login Screen. - Added Activity Indicator on the splash to handle the getuserdata. - Added Guest Login To home.
98 lines
3.6 KiB
Swift
98 lines
3.6 KiB
Swift
//
|
|
// SplashVM.swift
|
|
// WOKA
|
|
//
|
|
// Created by MacBook Pro on 25/04/24.
|
|
//
|
|
|
|
import UIKit
|
|
import AVFoundation
|
|
import Alamofire
|
|
|
|
class SplashVM{
|
|
|
|
weak var vc : SplashVC!
|
|
var player: AVAudioPlayer?
|
|
|
|
func playSplashSound() {
|
|
guard let path = Bundle.main.path(forResource: K.StaticFilesString.wokaSplashSound, ofType:"m4a") else {
|
|
return }
|
|
let url = URL(fileURLWithPath: path)
|
|
|
|
do {
|
|
player = try AVAudioPlayer(contentsOf: url)
|
|
player?.play()
|
|
|
|
} catch let error {
|
|
print(error.localizedDescription)
|
|
}
|
|
}
|
|
|
|
func initView(){
|
|
let color1 = #colorLiteral(red: 0.144693464, green: 0.1426281333, blue: 0.6686832905, alpha: 1)
|
|
let color2 = #colorLiteral(red: 0.4862745098, green: 0.1960784314, blue: 0.7019607843, alpha: 1)
|
|
vc.hindiBtn.applyGradient(colors: [color1, color2], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0, y: 0.8))
|
|
vc.englishBtn.applyGradient(colors: [color1, color2], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0, y: 0.8))
|
|
vc.hindiBtn.roundCorner()
|
|
vc.englishBtn.roundCorner()
|
|
selectTheme()
|
|
vc.activityIndicator.stopAnimating()
|
|
}
|
|
|
|
func selectTheme(){
|
|
let theme = UserDefaults.standard.string(forKey: K.UserDefaultsStruct.themeDefault)
|
|
if theme != nil{
|
|
(theme == ThemeSelect.theme1.rawValue) ? (AuthFunc.shareInstance.selectedTheme = .theme1) : (AuthFunc.shareInstance.selectedTheme = .theme2)
|
|
}else{
|
|
AuthFunc.shareInstance.selectedTheme = .theme1
|
|
}
|
|
}
|
|
|
|
func getUserData(){
|
|
|
|
let headers : HTTPHeaders = ["Accept-Language" : AuthFunc.shareInstance.languageSelected == .english ? "English" : "Hindi",
|
|
"access-token": AuthFunc.shareInstance.getAccessToken()]
|
|
startStopIndicator(start: true)
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Auth.get_user_data, method: .get, headers: headers) { [weak self](result : Result<BaseResponseModel<UserDataDM>, NetworkManager.APIError>) in
|
|
switch result{
|
|
case .success(let data):
|
|
guard let self else{return}
|
|
switch data.success{
|
|
case 0:
|
|
startStopIndicator(start: false)
|
|
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
case 1:
|
|
startStopIndicator(start: false,hide: true)
|
|
guard let data = data.data?.result else{return}
|
|
AuthFunc.shareInstance.userData = data
|
|
UIApplication.setRootView(SideMenuController.instantiate(from: .Home))
|
|
default:
|
|
break
|
|
}
|
|
case .failure(let error):
|
|
guard let self else{return}
|
|
startStopIndicator(start: false)
|
|
self.vc.toast(msg: error.localizedDescription , time: 2)
|
|
}
|
|
}
|
|
}
|
|
|
|
func startStopIndicator(start : Bool , hide : Bool = false){
|
|
if hide{
|
|
vc.activityIndicator.stopAnimating()
|
|
vc.activityIndicator.isHidden = true
|
|
vc.retryBtn.isHidden = true
|
|
return
|
|
}
|
|
if start{
|
|
vc.activityIndicator.isHidden = false
|
|
vc.activityIndicator.startAnimating()
|
|
vc.retryBtn.isHidden = true
|
|
}else{
|
|
vc.activityIndicator.stopAnimating()
|
|
vc.activityIndicator.isHidden = true
|
|
vc.retryBtn.isHidden = false
|
|
}
|
|
}
|
|
}
|