123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- //
- // LoadingAnimationViewController.swift
- // Learn Genie
- //
- // Created by Suraj Kumar Mandal on 12/08/21.
- //
- import UIKit
- import SwiftyGif
- import Toast_Swift
- class LoadingAnimationViewController: UIViewController {
-
- @IBOutlet weak var imageView: UIImageView!
- @IBOutlet weak var loadingLabel: UILabel!
- //@IBOutlet weak var linearProgressBar: DSGradientProgressView!
-
- @IBOutlet var activityIndicator: UIActivityIndicatorView!
-
- var viewModel = LoadingAnimationViewModel()
- let group = DispatchGroup()
- var isWaiting = false
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- // Do any additional setup after loading the view.
- viewModel.delegate = self
- self.isWaiting = true
- setupUI()
- }
-
- override func viewWillAppear(_ animated: Bool) {
- //Progress View
- //linearProgressBar.startProgress()
- activityIndicator.startAnimating()
- //GIF Animation
- let gif = try! UIImage(gifName: "loading.gif")
- self.imageView.setGifImage(gif, loopCount: -1)
- self.loadingLabel.text = Helper.translateText(inputText: "Loading data please wait")
- // Call performTask after a delay of 5 second
- DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 5) {
- DispatchQueue.main.async {
- self.loadingLabel.text = Helper.translateText(inputText: "An exciting journey awaits you, please wait for a couple of minutes")
- }
- }
- }
-
- func setupUI() {
- if UserDefaults.standard.bool(forKey: "introduction") {
- if Reachability.isConnectedToNetwork() {
- DispatchQueue.main.async {
- self.viewModel.generateCookie()
- }
- } else {
- Alert.showInternetFailureAlert(on: self)
- }
- } else {
- // Call performTask after a delay of 4 second
- DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 4) {
- DispatchQueue.main.async {
- self.navigation()
- }
- }
- }
- }
-
- func callAPI() {
- group.enter()
- viewModel.topicDownloader()
-
- group.enter()
- viewModel.getLevel()
-
- group.enter()
- viewModel.getQuestionBank(offset: 0)
-
- group.enter()
- viewModel.getQuestion(offset: 0)
-
- group.enter()
- viewModel.getChoice(offset: 0)
-
- group.enter()
- viewModel.getScoreBoard()
-
- group.notify(queue: .main, execute: {
- // Update the UI
- self.isWaiting = false
- print("All API called")
- self.activityIndicator.stopAnimating()
- //self.linearProgressBar.stopProgress()
- self.navigation()
- })
- }
-
- /*
- // 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 LoadingAnimationViewController : LoadingAnimationViewProtocol {
-
- func callDataAPI() {
- self.callAPI()
- }
-
- func groupLeave() {
- group.leave()
- }
-
- func stopActivityIndicator() {
- //linearProgressBar.stopProgress()
- self.activityIndicator.stopAnimating()
- }
-
- func showToastMessage(message: String) {
- self.view.makeToast(message)
- }
-
- func navigation() {
- if UserDefaults.standard.bool(forKey: "introduction") {
- DispatchQueue.main.async {
- let introVC = self.storyboard?.instantiateViewController(withIdentifier: "IntroductionViewController") as! IntroductionViewController
- introVC.topicName = "Introduction"
- self.navigationController?.pushViewController(introVC, animated: false)
- }
- } else {
- DispatchQueue.main.async {
- let dashboardVC = self.storyboard?.instantiateViewController(withIdentifier: "DashboardViewController") as! DashboardViewController
- self.navigationController?.pushViewController(dashboardVC, animated: false)
- }
- }
- }
-
- }
|