123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- //
- // IntroductionViewController.swift
- // Learn Genie
- //
- // Created by Suraj Kumar Mandal on 30/08/21.
- //
- import UIKit
- import WebKit
- import RealmSwift
- import SideMenu
- class IntroductionViewController: UIViewController {
- @IBOutlet weak var webView: WKWebView!
- @IBOutlet weak var proceedButton: UIButton!
- @IBOutlet var navigationBar: UINavigationBar!
- @IBOutlet var quizInstructionView: UIView!
- @IBOutlet var instructionTableView: UITableView!
- @IBOutlet var quizInstructionLabel: UILabel!
- @IBOutlet var continueButton: UIButton!
- @IBOutlet var cancelButton: UIButton!
- @IBOutlet var wantToContinueLabel: UILabel!
-
- let translation = DBManager.sharedInstance.database.objects(TopicModel.self)
- let levelData = DBManager.sharedInstance.database.objects(LevelModel.self)
- var topicName = ""
- var topicId = Int()
- var mainTopicIndex = Int()
- var topicIndex = Int()
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- quizInstructionView.isHidden = true
- instructionTableView.delegate = self
- instructionTableView.dataSource = self
- instructionTableView.tableFooterView = UIView()
- instructionTableView.allowsSelection = false
- }
-
- override func viewWillAppear(_ animated: Bool) {
- if Helper.translateText(inputText: topicName) == Helper.translateText(inputText: "Introduction") {
- proceedButton.setTitle(Helper.translateText(inputText: "Proceed"), for: .normal)
- } else {
- proceedButton.setTitle(Helper.translateText(inputText: "Take Quiz"), for: .normal)
- }
- quizInstructionLabel.text = Helper.translateText(inputText: "Quiz Instructions")
- navigationBar.topItem?.title = Helper.translateText(inputText: topicName)
- getTopic()
- setupUI()
- }
-
- func setupUI() {
- wantToContinueLabel.text = Helper.translateText(inputText: "Do you want to continue?")
- continueButton.setTitle(Helper.translateText(inputText: "CONTINUE"), for: .normal)
- cancelButton.setTitle(Helper.translateText(inputText: "CANCEL"), for: .normal)
- }
-
- func getTopic() {
- for item in translation {
- if topicName.lowercased() == item.name.lowercased() {
- topicId = item.id
- self.loadWebView()
- return
- } else {
- //self.view.makeToast("No topic found!")
- }
- }
- }
-
- func loadWebView() {
- let language = DBManager.sharedInstance.database.objects(LanguageModel.self)
- for item in language {
- if item.id == UserDefaultsConstant.getIntValueFromUserDefults(for: "selectedLanguageId") as! Int {
- let unZipDestination = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
- let languageFolderUrl = unZipDestination.appendingPathComponent(item.name)
- let unZipUrl = languageFolderUrl.appendingPathComponent("\(topicId)")
- let contentUrl = unZipUrl.appendingPathComponent("content")
- let indexUrl = contentUrl.appendingPathComponent("index.html")
- print("Unzip Url: \(unZipUrl)")
- print("Content Url: \(contentUrl)")
- print("Index Url: \(indexUrl)")
-
- //let url = URL(string: link)
- let requestObj = URLRequest(url: indexUrl as URL)
- webView.load(requestObj)
- }
- }
- }
-
-
-
- /*
- // 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.
- }
- */
-
-
- @IBAction func menuNavAction(_ sender: Any) {
- let menu = storyboard!.instantiateViewController(withIdentifier: "SideMenuNavigationController") as! SideMenuNavigationController
- present(menu, animated: true, completion: nil)
- }
-
- @IBAction func headerNavigation(_ sender: UIButton) {
- switch sender.tag {
- case 0:
- DispatchQueue.main.async {
- let introVC = self.storyboard?.instantiateViewController(withIdentifier: "IntroductionViewController") as! IntroductionViewController
- introVC.topicName = self.topicName
- self.navigationController?.pushViewController(introVC, animated: false)
- }
- break
- case 1:
- DispatchQueue.main.async {
- let videoVC = self.storyboard?.instantiateViewController(withIdentifier: "VideoIntroductionViewController") as! VideoIntroductionViewController
- videoVC.topicName = self.topicName
- self.navigationController?.pushViewController(videoVC, animated: false)
- }
- case 2:
- DispatchQueue.main.async {
- let audioVC = self.storyboard?.instantiateViewController(withIdentifier: "AudioIntroductionViewController") as! AudioIntroductionViewController
- audioVC.topicName = self.topicName
- self.navigationController?.pushViewController(audioVC, animated: false)
- }
- default:
- break
- }
- }
-
- @IBAction func proceedAction(_ sender: Any) {
- if Helper.translateText(inputText: topicName) == Helper.translateText(inputText: "Introduction") {
- //Set Introduction status to false
- UserDefaults.standard.set(false, forKey: "introduction")
- UserDefaults.standard.synchronize()
- //Navigate to login screen
- DispatchQueue.main.async {
- let homeVC = self.storyboard?.instantiateViewController(withIdentifier:"DashboardViewController" ) as! DashboardViewController
- self.navigationController?.pushViewController(homeVC, animated: true)
- }
- } else {
- if UserDefaultsConstant.getValueFromUserDefults(for: Constant.signInMethod) as! String == "google" {
- quizInstructionView.isHidden = false
- } else {
- let userModel = DBManager.sharedInstance.database.objects(UserDetailsModel.self)
- let userIdentifier = UserDefaultsConstant.getValueFromUserDefults(for: Constant.userIdentifier) as! String
- if userModel.contains(where: {$0.appleIdentifier == userIdentifier}) {
- quizInstructionView.isHidden = false
- } else {
- Alert.showAlertWithAction(vc: self, title: Helper.translateText(inputText: "Incomplete Profile"), message: Helper.translateText(inputText: "Please fill up user details and try again!"), alertStyle: .alert, actionTitles: [Helper.translateText(inputText: "CANCEL"), Helper.translateText(inputText: "Edit Profile")], actionStyles: [.cancel, .default], actions: [{_ in
- print("cancel click")
- }, { [self]_ in
- print("yes click")
- //Navigate to User details
- DispatchQueue.main.async {
- let loaderVC = self.storyboard?.instantiateViewController(withIdentifier:"UserDetailsViewController" ) as! UserDetailsViewController
- self.navigationController?.pushViewController(loaderVC, animated: true)
- }
- }])
- }
- }
- }
- }
-
- @IBAction func quizInstructionAction(_ sender: UIButton) {
- switch sender.tag {
- case 0:
- quizInstructionView.isHidden = true
- DispatchQueue.main.async {
- // let quizVC = self.storyboard?.instantiateViewController(withIdentifier: "TakeQuizViewController") as! TakeQuizViewController
- // quizVC.topicId = self.topicId
- // self.navigationController?.pushViewController(quizVC, animated: false)
- let quizVC = self.storyboard?.instantiateViewController(withIdentifier: "AnimationTakeQuizViewController") as! AnimationTakeQuizViewController
- quizVC.topicId = self.topicId
- quizVC.topicIndex = self.topicIndex
- quizVC.mainTopicIndex = self.mainTopicIndex
- self.navigationController?.pushViewController(quizVC, animated: false)
- }
- break
- case 1:
- quizInstructionView.isHidden = true
- break
- default:
- break
- }
- }
- }
- extension IntroductionViewController: UITableViewDelegate, UITableViewDataSource {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return Constant.quizInstruction.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "OptionsTableViewCell", for: indexPath) as? OptionsTableViewCell else {
- return UITableViewCell()
- }
-
- if indexPath.row > 3 {
- cell.optionTitleLabel.text = "\(Constant.bullet) \(indexPath.row-4)/5 \(Helper.translateText(inputText: Constant.quizInstruction[indexPath.row]))"
- } else {
- cell.optionTitleLabel.text = Helper.translateText(inputText: Constant.quizInstruction[indexPath.row])
- }
-
- return cell
- }
- }
|