Files
Woka_Native_iOS/WOKA/Home/Controller/MyListViewAllVC.swift
Bilal 1eb7727aa2 - Added no data and error handling in my orderdetails
- added lazy loading in myorders
- finalised karaoke with new key
- handled failure to show retry btn in karaoke
- made mylist view all, with api call, modified the api which will display all kind of data.
- made a common module for above
2024-08-09 21:04:55 +05:30

143 lines
5.5 KiB
Swift

//
// MyListViewAllVC.swift
// WOKA
//
// Created by MacBook Pro on 08/08/24.
//
import UIKit
class MyListViewAllVC: UIViewController {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var tableHeight: NSLayoutConstraint!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var loadMoreBtn: LocalisedElementsButton!
@IBOutlet weak var loadMoreActivityIndicator: UIActivityIndicatorView!
var vm = MyListViewAllVM()
override func viewDidLoad() {
super.viewDidLoad()
vm.vc = self
vm.initView()
// let color1 = #colorLiteral(red: 0, green: 0.4784313725, blue: 0.7529411765, alpha: 1)
// let color2 = #colorLiteral(red: 0, green: 0.7529411765, blue: 0.7529411765, alpha: 1)
// self.view.applyGradient(colors: [color1,color2], startPoint: .Point.left.point , endPoint: .Point.right.point)
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
self.navigationController?.setColor(color: .black)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
self.navigationController?.navigationBar.removeGradientBackground()
// Customize the navigation bar's appearance
self.navigationController?.setColor(color: .black)
}
@IBAction func loadMoreBtnTapped(_ sender: LocalisedElementsButton) {
loadMoreBtn.isHidden = true
vm.pageNo += 1
loadMoreActivityIndicator.startAnimating()
vm.getFavouriteListing()
}
}
// MARK: - TableView DataSource , Delegates
extension MyListViewAllVC : TableViewSRC{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch vm.postType{
case 1: // webSeries
return vm.favListingData?.showData?.count ?? 0
case 6: // Games
return vm.favListingData?.gameData?.count ?? 0
case 7: // Audio
return vm.favListingData?.audioData?.count ?? 0
case 8: //KAraoke
return vm.favListingData?.singKaraokeData?.count ?? 0
default:
return 0
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch vm.postType{
case 1: // webSeries
break
case 6://Games
guard let gameData = vm.favListingData?.gameData?[indexPath.row] else{return}
let sb = UIStoryboard(name: K.StoryBoard.Games, bundle: nil)
let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Games.gamesDetailVC) as! GamesDetailVC
vcPush.modalPresentationStyle = .overCurrentContext
vcPush.modalTransitionStyle = .crossDissolve
vcPush.gameData = gameData
self.present(vcPush, animated: true)
case 7: // audio books
guard let audioData = vm.favListingData?.audioData?[indexPath.row] else{return}
let sb = UIStoryboard(name: K.StoryBoard.audioBooks, bundle: nil)
let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.AudioBooks.audioBookDetailsVC) as! AudioBookDetailsVC
vcPush.modalPresentationStyle = .overCurrentContext
vcPush.modalTransitionStyle = .crossDissolve
vcPush.audioData = audioData
// vcPush.delegate = self
self.present(vcPush, animated: true)
case 8: //KAraoke
guard let karaokeData = vm.favListingData?.singKaraokeData?[indexPath.row] else{return}
let sb = UIStoryboard(name: K.StoryBoard.Karaoke, bundle: nil)
let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Karaoke.karaokeDetailsVC) as! KaraokeDetailsVC
vcPush.modalPresentationStyle = .overCurrentContext
vcPush.modalTransitionStyle = .crossDissolve
vcPush.karaokeData = karaokeData
self.present(vcPush, animated: true)
default:
break
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 230
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: K.CellIdentifier.Home.myListViewAllCell) as! MyListViewAllCell
switch vm.postType{
case 1: // Webseries
if let webSeriesData = vm.favListingData?.showData?[indexPath.row] {
cell.webSeriesData(data: webSeriesData)
}
case 6: // Games
if let gameData = vm.favListingData?.gameData?[indexPath.row] {
cell.gameData(data: gameData)
}
case 7:
if let karaokeData = vm.favListingData?.audioData?[indexPath.row] {
cell.audioData(data: karaokeData)
}
case 8: // Karaoke
if let karaokeData = vm.favListingData?.singKaraokeData?[indexPath.row] {
cell.setKaraokeData(data: karaokeData)
}
default:
break
}
return cell
}
}