Files
Woka_Native_iOS/WOKA/TabBar & SideMenu/ViewModel/SideMenuVM.swift
BilalKhanWDI 86bd90db31 - Created an extension to handle the rootview.
- 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.
2024-05-28 19:47:51 +05:30

100 lines
4.1 KiB
Swift

//
// SideMenuVM.swift
// WOKA
//
// Created by MacBook Pro on 21/05/24.
//
import UIKit
class SideMenuVM{
weak var vc : SideMenuVC!
func initView(){
customizeSegmentControl()
AuthFunc.shareInstance.languageSelected == .english ? (vc.languageControl.selectedSegmentIndex = 0) : (vc.languageControl.selectedSegmentIndex = 1)
let color1 = #colorLiteral(red: 0.144693464, green: 0.1426281333, blue: 0.6686832905, alpha: 1)
let color2 = #colorLiteral(red: 0.6901960784, green: 0.2745098039, blue: 0.7568627451, alpha: 1)
vc.logoutBtn.applyGradient(colors: [color1, color2], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0.8, y: 0))
vc.logoutBtn.layer.cornerRadius = vc.logoutBtn.frame.height / 2
// Adding the trailing constriant to make the view appeared center when expanded
let sidemenuBasicConfiguration = SideMenuController.preferences.basic
let showPlaceTableOnLeft = (sidemenuBasicConfiguration.position == .under) != (sidemenuBasicConfiguration.direction == .right)
if showPlaceTableOnLeft {
vc.selectionMenuTrailingConstraint.constant = SideMenuController.preferences.basic.menuWidth - vc.view.frame.width
}
// Add border to theme
vc.theme1.addBorderView(width: 1.5, color: UIColor.white)
vc.theme2.addBorderView(width: 1.5, color: UIColor.white)
vc.theme1.addTapGesture { [weak self] in
UserDefaults.standard.setValue(ThemeSelect.theme1.rawValue, forKey: K.UserDefaultsStruct.themeDefault)
AuthFunc.shareInstance.selectedTheme = .theme1
guard let self else {return}
ViewButtonAnimation.sharedInstance.btnTapped(in: self.vc, view: vc.theme1) {
NotificationCenter.default.post(name: NSNotification.Name(K.NotificationCenterReloads.reloadTheme), object: nil, userInfo: nil)
self.themeSelect()
}
}
vc.theme2.addTapGesture { [weak self] in
UserDefaults.standard.setValue(ThemeSelect.theme2.rawValue, forKey: K.UserDefaultsStruct.themeDefault)
AuthFunc.shareInstance.selectedTheme = .theme2
guard let self else {return}
ViewButtonAnimation.sharedInstance.btnTapped(in: self.vc, view: vc.theme2) {
NotificationCenter.default.post(name: NSNotification.Name(K.NotificationCenterReloads.reloadTheme), object: nil, userInfo: nil)
self.themeSelect()
}
}
setData()
}
func setData(){
guard let data = AuthFunc.shareInstance.userData else{return}
//set the first name as the name
vc.userName.text = (data.fullname == nil || data.fullname == "") ? "User" : data.fullname
if let avatar = data.avtar{
//https://wokaland.com/admin/storage/app/public/uploads/avtar/avatar2.png?d=1716889852
vc.avatarImage.imageURL("https://wokaland.com/admin/storage/app/public/uploads/avtar/avatar2.png?d=1716889852",color: .white)
}
}
func themeSelect(){
switch AuthFunc.shareInstance.selectedTheme {
case .theme1:
//Show theme 1 selected
vc.themeOneView.isHidden = false
vc.themeOneCheckMark.isHidden = false
// remove theme 2 selection
vc.themeTwoView.isHidden = true
vc.themetwoCheckMark.isHidden = true
case .theme2:
//Show theme 2 selected
vc.themeTwoView.isHidden = false
vc.themetwoCheckMark.isHidden = false
// remove theme 1 selection
vc.themeOneView.isHidden = true
vc.themeOneCheckMark.isHidden = true
}
self.vc.sideMenuController?.hideMenu()
}
private func customizeSegmentControl(){
// Customize Segment Control
vc.languageControl.layer.cornerRadius = vc.languageControl.layer.frame.height / 2
vc.languageControl.layer.masksToBounds = true
vc.languageControl.clipsToBounds = true
}
}