// // SplashScreenViewController.swift // LMS // // Created by Suraj Kumar Mandal on 17/08/22. // import UIKit import Toast_Swift class SplashScreenViewController: UIViewController { @IBOutlet var presentedByLabel: UILabel! @IBOutlet var hindujaLogoView: UIView! @IBOutlet var hindujaLogoImageView: UIImageView! @IBOutlet var andLabel: UILabel! @IBOutlet var hindujaCollegeView: UIView! @IBOutlet var hindujaCollegeImageView: UIImageView! @IBOutlet var poweredByLabel: UILabel! @IBOutlet var finlabsLogoView: UIView! @IBOutlet var finlabsLogoImageView: UIImageView! let viewModel = SplashScreenViewModel() var timer = Timer() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. viewModel.delegate = self setupUI() perform(#selector(navigation), with: nil, afterDelay: 4) } override var preferredStatusBarStyle : UIStatusBarStyle { return .lightContent } func setupUI() { hindujaLogoView.layer.borderWidth = 1 hindujaLogoView.layer.borderColor = #colorLiteral(red: 0.1058823529, green: 0.3764705882, blue: 0.5960784314, alpha: 1) hindujaLogoView.layer.cornerRadius = 30 hindujaCollegeView.layer.borderWidth = 1 hindujaCollegeView.layer.borderColor = #colorLiteral(red: 0.1058823529, green: 0.3764705882, blue: 0.5960784314, alpha: 1) hindujaCollegeView.layer.cornerRadius = 30 finlabsLogoView.layer.borderWidth = 1 finlabsLogoView.layer.borderColor = #colorLiteral(red: 0.1058823529, green: 0.3764705882, blue: 0.5960784314, alpha: 1) finlabsLogoView.layer.cornerRadius = 30 andLabel.layer.masksToBounds = true andLabel.layer.cornerRadius = andLabel.frame.height / 2 } @objc func navigation() { if UIApplication.isFirstLaunch() { UserDefaults.standard.set(false, forKey: "isLogin") UserDefaults.standard.synchronize() let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController self.navigationController?.pushViewController(vc, animated: false) } else { if UserDefaults.standard.bool(forKey: "isLogin") { if Reachability.isConnectedToNetwork() { viewModel.getAccessToken() } else { Alert.showInternetFailureAlert(on: self) } } else { let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController self.navigationController?.pushViewController(vc, animated: false) } } } func scheduledTimerWithTimeInterval() { let time = UserDefaults.standard.value(forKey: "tokenExpire") as! Int timer = Timer.scheduledTimer(timeInterval: TimeInterval(time), target: self, selector: #selector(self.refresh), userInfo: nil, repeats: true) } @objc func refresh() { Dispatch.background { self.viewModel.refreshToken() } } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ } extension SplashScreenViewController: SplashScreenViewProtocol { func navigateToHome() { self.scheduledTimerWithTimeInterval() // let vc = self.storyboard?.instantiateViewController(withIdentifier: "DashboardViewController") as! DashboardViewController // self.navigationController?.pushViewController(vc, animated: false) // Navigate to calendar page as home let vc = self.storyboard?.instantiateViewController(withIdentifier: "StudyMaterialsViewController") as! StudyMaterialsViewController self.navigationController?.pushViewController(vc, animated: false) } }