SplashScreenViewController.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // SplashScreenViewController.swift
  3. // LMS
  4. //
  5. // Created by Suraj Kumar Mandal on 17/08/22.
  6. //
  7. import UIKit
  8. import Toast_Swift
  9. class SplashScreenViewController: UIViewController {
  10. @IBOutlet var presentedByLabel: UILabel!
  11. @IBOutlet var hindujaLogoView: UIView!
  12. @IBOutlet var hindujaLogoImageView: UIImageView!
  13. @IBOutlet var andLabel: UILabel!
  14. @IBOutlet var hindujaCollegeView: UIView!
  15. @IBOutlet var hindujaCollegeImageView: UIImageView!
  16. @IBOutlet var poweredByLabel: UILabel!
  17. @IBOutlet var finlabsLogoView: UIView!
  18. @IBOutlet var finlabsLogoImageView: UIImageView!
  19. let viewModel = SplashScreenViewModel()
  20. var timer = Timer()
  21. override func viewDidLoad() {
  22. super.viewDidLoad()
  23. // Do any additional setup after loading the view.
  24. viewModel.delegate = self
  25. setupUI()
  26. perform(#selector(navigation), with: nil, afterDelay: 4)
  27. }
  28. override var preferredStatusBarStyle : UIStatusBarStyle {
  29. return .lightContent
  30. }
  31. func setupUI() {
  32. hindujaLogoView.layer.borderWidth = 1
  33. hindujaLogoView.layer.borderColor = #colorLiteral(red: 0.1058823529, green: 0.3764705882, blue: 0.5960784314, alpha: 1)
  34. hindujaLogoView.layer.cornerRadius = 30
  35. hindujaCollegeView.layer.borderWidth = 1
  36. hindujaCollegeView.layer.borderColor = #colorLiteral(red: 0.1058823529, green: 0.3764705882, blue: 0.5960784314, alpha: 1)
  37. hindujaCollegeView.layer.cornerRadius = 30
  38. finlabsLogoView.layer.borderWidth = 1
  39. finlabsLogoView.layer.borderColor = #colorLiteral(red: 0.1058823529, green: 0.3764705882, blue: 0.5960784314, alpha: 1)
  40. finlabsLogoView.layer.cornerRadius = 30
  41. andLabel.layer.masksToBounds = true
  42. andLabel.layer.cornerRadius = andLabel.frame.height / 2
  43. }
  44. @objc func navigation() {
  45. if UIApplication.isFirstLaunch() {
  46. UserDefaults.standard.set(false, forKey: "isLogin")
  47. UserDefaults.standard.synchronize()
  48. let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
  49. self.navigationController?.pushViewController(vc, animated: false)
  50. } else {
  51. if UserDefaults.standard.bool(forKey: "isLogin") {
  52. if Reachability.isConnectedToNetwork() {
  53. viewModel.getAccessToken()
  54. } else {
  55. Alert.showInternetFailureAlert(on: self)
  56. }
  57. } else {
  58. let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
  59. self.navigationController?.pushViewController(vc, animated: false)
  60. }
  61. }
  62. }
  63. func scheduledTimerWithTimeInterval() {
  64. let time = UserDefaults.standard.value(forKey: "tokenExpire") as! Int
  65. timer = Timer.scheduledTimer(timeInterval: TimeInterval(time), target: self, selector: #selector(self.refresh), userInfo: nil, repeats: true)
  66. }
  67. @objc func refresh() {
  68. Dispatch.background {
  69. self.viewModel.refreshToken()
  70. }
  71. }
  72. /*
  73. // MARK: - Navigation
  74. // In a storyboard-based application, you will often want to do a little preparation before navigation
  75. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  76. // Get the new view controller using segue.destination.
  77. // Pass the selected object to the new view controller.
  78. }
  79. */
  80. }
  81. extension SplashScreenViewController: SplashScreenViewProtocol {
  82. func navigateToHome() {
  83. self.scheduledTimerWithTimeInterval()
  84. // let vc = self.storyboard?.instantiateViewController(withIdentifier: "DashboardViewController") as! DashboardViewController
  85. // self.navigationController?.pushViewController(vc, animated: false)
  86. // Navigate to calendar page as home
  87. let vc = self.storyboard?.instantiateViewController(withIdentifier: "StudyMaterialsViewController") as! StudyMaterialsViewController
  88. self.navigationController?.pushViewController(vc, animated: false)
  89. }
  90. }