123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- //
- // LessonListViewController.swift
- // LMS
- //
- // Created by Suraj Kumar Mandal on 24/08/22.
- //
- import UIKit
- import SideMenu
- import Toast_Swift
- class LessonListViewController: UIViewController {
-
- @IBOutlet var navigationBar: UINavigationBar!
- @IBOutlet var contentNameLabel: UILabel!
- @IBOutlet var contentListTableView: UITableView!
-
- var viewModel = LessonListViewModel()
- var lessonListModel = [LessonListModel]()
- var lessonId = Int()
- var contentName = String()
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- // Do any additional setup after loading the view.
- viewModel.delegate = self
- contentListTableView.delegate = self
- contentListTableView.dataSource = self
- getLessonList()
- setupData()
- }
-
- func setupData() {
- contentNameLabel.text = "\(contentName) ->"
- }
-
- func getLessonList() {
- if Reachability.isConnectedToNetwork() {
- viewModel.getLessonsList(id: lessonId)
- } else {
- Alert.showInternetFailureAlert(on: self)
- }
- }
-
-
- /*
- // 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 backAction(_ sender: UIBarButtonItem) {
- self.navigationController?.popViewController(animated: true)
- }
-
- }
- extension LessonListViewController: UITableViewDelegate, UITableViewDataSource {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return lessonListModel.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "ContentListTableViewCell", for: indexPath) as? ContentListTableViewCell else {
- return UITableViewCell()
- }
-
- cell.selectionStyle = .none
- cell.customView.dropShadow()
- cell.customView.layer.cornerRadius = 10
- switch lessonListModel[indexPath.row].type {
- case "scorm":
- cell.contentImageView.image = UIImage(named: "scorn-test")
- case "pdf":
- cell.contentImageView.image = UIImage(named: "pdf")
- case "jpeg":
- cell.contentImageView.image = UIImage(named: "jpg")
- case "mp4":
- cell.contentImageView.image = UIImage(named: "video")
- case "youtube":
- cell.contentImageView.image = UIImage(named: "video")
- case "mp3":
- cell.contentImageView.image = UIImage(named: "mp3")
- case "docx":
- cell.contentImageView.image = UIImage(named: "docx")
- default:
- cell.contentImageView.image = UIImage(named: "docx")
- }
- cell.contentLabel.text = lessonListModel[indexPath.row].name
-
- return cell
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- switch lessonListModel[indexPath.row].type {
- case "mp4":
- let vc = self.storyboard?.instantiateViewController(withIdentifier: "VideoViewController") as! VideoViewController
- vc.videoId = lessonListModel[indexPath.row].fileId ?? ""
- vc.pageName = lessonListModel[indexPath.row].name ?? ""
- self.navigationController?.pushViewController(vc, animated: true)
- case "youtube":
- let vc = self.storyboard?.instantiateViewController(withIdentifier: "YouTubeViewController") as! YouTubeViewController
- vc.youtubeId = lessonListModel[indexPath.row].fileId ?? ""
- vc.pageName = lessonListModel[indexPath.row].name ?? ""
- self.navigationController?.pushViewController(vc, animated: true)
- case "mp3":
- let vc = self.storyboard?.instantiateViewController(withIdentifier: "AudioViewController") as! AudioViewController
- vc.fileId = lessonListModel[indexPath.row].fileId ?? ""
- vc.pageName = lessonListModel[indexPath.row].name ?? ""
- self.navigationController?.pushViewController(vc, animated: true)
- case "scorm":
- let vc = self.storyboard?.instantiateViewController(withIdentifier: "ScromViewController") as! ScromViewController
- vc.id = lessonListModel[indexPath.row].fileId ?? ""
- vc.docType = lessonListModel[indexPath.row].type ?? ""
- vc.name = lessonListModel[indexPath.row].name ?? ""
- self.navigationController?.pushViewController(vc, animated: true)
- default:
- let vc = self.storyboard?.instantiateViewController(withIdentifier: "PdfReaderViewController") as! PdfReaderViewController
- vc.id = lessonListModel[indexPath.row].fileId ?? ""
- vc.docType = lessonListModel[indexPath.row].type ?? ""
- vc.name = lessonListModel[indexPath.row].name ?? ""
- self.navigationController?.pushViewController(vc, animated: true)
- }
- }
- }
- extension LessonListViewController: LessonListProtocol {
- func startLoader() {
- ActivityIndicator.start()
- }
-
- func stopLoader() {
- ActivityIndicator.stop()
- }
-
- func showError(error: String) {
- self.view.makeToast(error)
- }
-
- func lessonListModel(model: [LessonListModel]) {
- self.lessonListModel = model
- self.contentListTableView.reloadData()
- }
- }
|