2024-05-02 13:20:40 +05:30
//
// O n B o a r d V M . s w i f t
// W O K A
//
// C r e a t e d b y B i l a l o n 2 6 / 0 4 / 2 0 2 4 .
//
import UIKit
import Lottie
2024-05-15 10:52:14 +05:30
import Alamofire
2024-08-12 19:58:58 +05:30
import FirebaseAnalytics
2024-05-02 13:20:40 +05:30
class OnBoardVM {
weak var vc : OnBoardVC !
private var animationView : LottieAnimationView ?
var data : [ CarouselData ] ?
func initData ( ) {
// A n i m a t e b a c k g r o u n d
animateWokaLogo ( )
// P l a y S o u n d g l o b a l l y
playBackGroundAnimationJSON ( )
// G r a d i e n t a n d r o u n d c o r n e r f o r b u t t o n
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 )
let color3 = # colorLiteral ( red : 0.968627451 , green : 0.7882352941 , blue : 0.1294117647 , alpha : 1 )
let color4 = # colorLiteral ( red : 0.968627451 , green : 0.4196078431 , blue : 0.1098039216 , alpha : 1 )
let color5 = # colorLiteral ( red : 0.6666666667 , green : 0.6666666667 , blue : 0.231372549 , alpha : 1 )
let color6 = # colorLiteral ( red : 0.09803921569 , green : 0.4392156863 , blue : 0.4156862745 , alpha : 1 )
vc . createAccountBtn . applyGradient ( colors : [ color1 , color2 ] , startPoint : CGPoint ( x : 0 , y : 0 ) , endPoint : CGPoint ( x : 0 , y : 0.8 ) )
vc . loginBtn . applyGradient ( colors : [ color4 , color3 ] , startPoint : CGPoint ( x : 0 , y : 0 ) , endPoint : CGPoint ( x : 0 , y : 0.8 ) )
vc . loginAsGuestBtn . applyGradient ( colors : [ color6 , color5 ] , startPoint : CGPoint ( x : 0 , y : 0 ) , endPoint : CGPoint ( x : 0 , y : 0.8 ) )
vc . createAccountBtn . roundCorner ( )
vc . loginBtn . roundCorner ( )
vc . loginAsGuestBtn . roundCorner ( )
// S e t t i n g b u t t o n t e x t t o l o c a l i z e
2024-05-07 19:33:29 +05:30
vc . createAccountBtn . setTitle ( " CREATE YOUR ACCOUNT " . localized ( loc : AuthFunc . shareInstance . languageSelected . rawValue ) , for : . normal )
vc . loginBtn . setTitle ( " LOGIN " . localized ( loc : AuthFunc . shareInstance . languageSelected . rawValue ) , for : . normal )
vc . loginAsGuestBtn . setTitle ( " Continue as a Guest " . localized ( loc : AuthFunc . shareInstance . languageSelected . rawValue ) , for : . normal )
2024-05-02 13:20:40 +05:30
// I n i t C o l l e c t i o n D a t a
vc . pageControl . numberOfPages = 3
2024-05-07 19:33:29 +05:30
data = [ CarouselData ( title : " Watch, Listen & Play " . localized ( loc : AuthFunc . shareInstance . languageSelected . rawValue ) , desc : " LIVE TV, VIDEOS, GAMES, AND AUDIO BOOKS " . localized ( loc : AuthFunc . shareInstance . languageSelected . rawValue ) , image : " Slide1 " ) ,
CarouselData ( title : " Sing-Along and Shop " . localized ( loc : AuthFunc . shareInstance . languageSelected . rawValue ) , desc : " " , image : " Slide2 " ) ,
CarouselData ( title : " Lets all go to WOKALAND " . localized ( loc : AuthFunc . shareInstance . languageSelected . rawValue ) , desc : " " . localized ( loc : AuthFunc . shareInstance . languageSelected . rawValue ) , image : " Slide3 " ) ]
2024-05-02 13:20:40 +05:30
// S e t u p C o l l e c t i o n V i e w
setupCell ( )
// a f t e r a l l s e t u p a n i m a t e t h e b o t t o m s t a c k t o a p p e a r
UIView . animate ( withDuration : 0.3 , delay : 0.4 , options : . transitionCrossDissolve , animations : {
self . vc . mainStack . alpha = 1
} , completion : nil )
}
func animateWokaLogo ( ) {
2024-05-02 19:30:09 +05:30
let topConstriant = CheckPhoneHomeBtnOrNotch . shareInstance . topConstriant ( )
2024-05-02 13:20:40 +05:30
UIView . animate ( withDuration : 0.6 , animations : {
self . vc . wokaLogoTopConstriant . constant = topConstriant
// I n f o r m t h e l a y o u t s y s t e m t o u p d a t e
self . vc . view . layoutIfNeeded ( )
// U n h i d e t h e v i e w w i t h c r o s s d i s s o l v e a n i m a t i o n a n d d e l a y
} )
}
func setupCell ( ) {
vc . carouselCV . register ( UINib ( nibName : K . CellIdentifier . OnBoarding . onBoardCell , bundle : nil ) , forCellWithReuseIdentifier : K . CellIdentifier . OnBoarding . onBoardCell )
vc . carouselCV . delegate = vc . self
vc . carouselCV . dataSource = vc . self
}
// MARK: - B a c k g r o u n d a n i m a t i o n
func playBackGroundAnimationJSON ( ) {
animationView = . init ( name : K . StaticFilesString . passingCloud )
animationView ! . frame = vc . viewLottie . bounds
// S e t a n i m a t i o n c o n t e n t m o d e
animationView ! . contentMode = . scaleAspectFill
// S e t a n i m a t i o n l o o p m o d e
animationView ! . loopMode = . loop
animationView ? . backgroundBehavior = . pauseAndRestore
// A d j u s t a n i m a t i o n s p e e d
animationView ! . animationSpeed = 1
vc . viewLottie . addSubview ( animationView ! )
// P l a y a n i m a t i o n
animationView ! . play ( )
}
func stopBackGroundAnimationJSON ( ) {
animationView ? . pause ( )
}
func resumeBackGroundAnimationJSON ( ) {
animationView ? . play ( )
}
2024-05-15 10:52:14 +05:30
// MARK: - C r e a t e G u e s t
/*
Guest Login
*/
func guestLogin ( ) {
2024-08-13 20:02:41 +05:30
2024-05-15 10:52:14 +05:30
let params : Parameters = [
" user_type " : 3 , // 1 - k i d , 2 - g u a r d i a n , 3 - g u e s t
2024-08-13 20:02:41 +05:30
" one_signal_player_id " : AuthFunc . shareInstance . getOneSignalID ( ) ,
2024-05-15 10:52:14 +05:30
" language_id " : AuthFunc . shareInstance . languageSelected = = . english ? 1 : 2 , // 1 - e n g , 2 - h i n d i
" device_type " : 1 // 1 - a n d r o i d , 2 - i O S
]
let header : HTTPHeaders = [ " device-id " : AuthFunc . shareInstance . getDeviceUUID ( ) ,
" Accept-Language " : AuthFunc . shareInstance . languageSelected = = . english ? " English " : " Hindi " ]
2024-05-30 19:49:41 +05:30
animationView ? . pause ( )
2024-05-15 10:52:14 +05:30
Utilities . startProgressHUD ( )
2024-05-29 19:40:46 +05:30
NetworkManager . shareInstance . apiRequest ( url : APIEndPoints . Auth . guest_login , method : . post , parameters : params , headers : header ) { ( result : Result < BaseResponseModel < GuestDataDM > , NetworkManager . APIError > ) in
2024-05-15 10:52:14 +05:30
switch result {
case . success ( let data ) :
switch data . success {
case 0 :
Utilities . dismissProgressHUD ( )
self . vc . toast ( msg : data . message ? ? " Unrecognised error " , time : 2 )
case 1 :
Utilities . dismissProgressHUD ( )
2024-05-29 19:40:46 +05:30
guard let dataUser = data . data else { return }
2024-05-30 19:49:41 +05:30
2024-08-12 19:58:58 +05:30
if let newGuest = dataUser . newGuest , newGuest = = true {
// F i r e A n a l y t i c s
Analytics . logEvent ( K . AnalyticsEventKeys . guest_login_iOS , parameters : nil )
2024-08-13 20:02:41 +05:30
Analytics . logEvent ( K . AnalyticsEventKeys . new_user_iOS , parameters : nil )
2024-08-12 19:58:58 +05:30
}
2024-10-17 19:25:38 +05:30
let userDataConverted = UserDataDM . ResultData ( id : nil , username : dataUser . username , fullname : dataUser . fullname , genderData : nil , birthdate : nil , email : nil , avtar : nil , avtarURL : nil , userType : " 3 " , languageMasterID : nil , lastLogin : nil , rememberToken : nil , childDetail : nil , language : nil , alreadyLoggedIn : nil , isDeactive : nil )
AuthFunc . shareInstance . loginDefaults ( data : userDataConverted )
2024-05-15 10:52:14 +05:30
default :
break
}
case . failure ( let error ) :
Utilities . dismissProgressHUD ( )
self . vc . toast ( msg : error . localizedDescription , time : 2 )
}
}
}
2024-05-02 13:20:40 +05:30
}