- added activity indicators for more vm with retry handling - fixed a issue where karaoke user view was not reflecting when the player closed
264 lines
11 KiB
Swift
264 lines
11 KiB
Swift
//
|
|
// WebSeriesVM.swift
|
|
// WOKA
|
|
//
|
|
// Created by MacBook Pro on 18/06/24.
|
|
//
|
|
|
|
import Foundation
|
|
import Alamofire
|
|
|
|
class WebSeriesVM{
|
|
|
|
weak var vc : WebSeriesVC!
|
|
var continueWatchingData = [ContinueWatchingDM.ResultData]()
|
|
var categoryListingData = [CategoryListingDM.ResultData]()
|
|
|
|
var showData = [WebSeriesShowListDM.ShowDatum]()
|
|
|
|
let dropDownModule = DropDown()
|
|
var dataSource = [String]()
|
|
|
|
//Static url for masila
|
|
//// var masilaUrl = "https://content.jwplatform.com/videos/Iygt11AD-Ysj2G4DQ.mp4"
|
|
// var masilaUrl = "https://cdn.jwplayer.com/manifests/Iygt11AD.m3u8"
|
|
var pageNo = 0
|
|
var stopFetch = false
|
|
|
|
func initView(){
|
|
setupCell()
|
|
startShimmer()
|
|
vc.scrollView.indicatorStyle = .white // or .white
|
|
|
|
let color1 = #colorLiteral(red: 0.5921568627, green: 0.2588235294, blue: 0.8941176471, alpha: 1)
|
|
let color2 = #colorLiteral(red: 0.368627451, green: 0.1215686275, blue: 0.768627451, alpha: 1)
|
|
|
|
vc.title = "WEB SERIES".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue)
|
|
vc.view.applyGradient(colors: [color2, color1], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0.8, y: 0))
|
|
|
|
getCategoryListing()
|
|
getContinueWatching()
|
|
|
|
// for the first load always send hindi as it is default category
|
|
self.getShowListing(categoryID: 18)
|
|
|
|
vc.languageStack.addTapGesture { [weak self] in
|
|
guard let self else {return}
|
|
dropDownModule.show()
|
|
self.vc.expandBtn.setImage(UIImage(named: "SupportUpArrow"), for: .normal)
|
|
}
|
|
}
|
|
|
|
func startShimmer(){
|
|
vc.headerView.startShimmer()
|
|
vc.masilaTrailerView.startShimmer()
|
|
vc.videoLanguageView.startShimmer()
|
|
}
|
|
|
|
func stopShimmer(){
|
|
self.vc.headerView.stopShimmer()
|
|
self.vc.masilaTrailerView.stopShimmer()
|
|
self.vc.videoLanguageView.stopShimmer()
|
|
}
|
|
|
|
func setupCell(){
|
|
vc.continueWatchingCV.register(UINib(nibName: K.CellIdentifier.WebSeries.webSeriesCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.WebSeries.webSeriesCell)
|
|
vc.continueWatchingCV.delegate = vc.self
|
|
vc.continueWatchingCV.dataSource = vc.self
|
|
|
|
vc.showListingTableView.register(UINib(nibName: K.CellIdentifier.WebSeries.webSeriesShowListingCell, bundle: nil), forCellReuseIdentifier: K.CellIdentifier.WebSeries.webSeriesShowListingCell)
|
|
vc.showListingTableView.delegate = vc.self
|
|
vc.showListingTableView.dataSource = vc.self
|
|
}
|
|
|
|
func updateTableHeight(){
|
|
self.vc.tableHeight.constant = self.vc.showListingTableView.contentSize.height + 100
|
|
self.vc.showListingTableView.layoutIfNeeded()
|
|
self.vc.tableHeight.constant = self.vc.showListingTableView.contentSize.height
|
|
}
|
|
|
|
// MARK: - DropDown
|
|
|
|
func initDropDown(){
|
|
dropDownModule.anchorView = vc.languageStack
|
|
dropDownModule.dataSource = dataSource
|
|
dropDownModule.cornerRadius = 10
|
|
dropDownModule.bottomOffset = CGPoint(x: 0, y:(dropDownModule.anchorView?.plainView.bounds.height)!)
|
|
dropDownModule.topOffset = CGPoint(x: 0, y:-(dropDownModule.anchorView?.plainView.bounds.height)!)
|
|
dropDownModule.direction = .bottom
|
|
dropDownModule.textFont = FontCustom.shareInstance.customFont(fontName: .Exo2_Bold, size: 14)
|
|
dropDownModule.shadowColor = UIColor.appColor(.TextDarkBlue)!
|
|
dropDownModule.backgroundColor = .white
|
|
dropDownModule.shadowOffset = CGSize(width: 0, height: 1)
|
|
dropDownModule.separatorColor = UIColor.lightGray
|
|
dropDownModule.width = vc.languageStack.frame.width
|
|
dropDownModule.selectionBackgroundColor = UIColor.appColor(.TextDarkBlue)!
|
|
dropDownModule.selectedTextColor = .white
|
|
dropDownModule.selectRow(at: 0)
|
|
|
|
// handle if user clicks outside
|
|
dropDownModule.cancelAction = { [weak self] in
|
|
guard let self else{return}
|
|
PersistentStorage.shared.addOthersCount()
|
|
vc.expandBtn.setImage(UIImage(named: "SupportBottomArrow"), for: .normal)
|
|
}
|
|
|
|
dropDownModule.selectionAction = { [weak self] (index: Int, item: String) in
|
|
PersistentStorage.shared.addOthersCount()
|
|
guard let self else{return}
|
|
vc.languageLabel.text = item
|
|
vc.expandBtn.setImage(UIImage(named: "SupportBottomArrow"), for: .normal)
|
|
|
|
//if the language is changed call the showlisting api
|
|
if let id = categoryListingData[index].id {
|
|
Utilities.startProgressHUD()
|
|
pageNo = 0
|
|
getShowListing(categoryID: id,languageChange: true)
|
|
}
|
|
|
|
}
|
|
}
|
|
// MARK: - Api Calls
|
|
|
|
func getContinueWatching(){
|
|
let headers : HTTPHeaders = ["access-token" : AuthFunc.shareInstance.getAccessToken()]
|
|
let params : Parameters = ["post_type" : 3] // 3- webseries
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.WebSeries.continue_watching, method: .post,parameters: params,headers : headers) { [weak self](result : Result<BaseResponseModel<ContinueWatchingDM>, NetworkManager.APIError>) in
|
|
switch result{
|
|
case .success(let data):
|
|
guard let self else{
|
|
Utilities.dismissProgressHUD()
|
|
return
|
|
}
|
|
switch data.success{
|
|
case 0:
|
|
/*
|
|
Error
|
|
*/
|
|
Utilities.dismissProgressHUD()
|
|
// vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
self.vc.continueWatchingStack.isHidden = true
|
|
case 1:
|
|
Utilities.dismissProgressHUD()
|
|
guard let data = data.data?.result else{return}
|
|
if data.count == 0{
|
|
self.vc.continueWatchingStack.isHidden = true
|
|
}else{
|
|
self.vc.continueWatchingStack.isHidden = false
|
|
}
|
|
self.continueWatchingData = data
|
|
self.vc.continueWatchingCV.reloadData()
|
|
default:
|
|
break
|
|
}
|
|
case .failure(let error):
|
|
guard let self else{
|
|
Utilities.dismissProgressHUD()
|
|
return
|
|
}
|
|
Utilities.dismissProgressHUD()
|
|
self.vc.continueWatchingStack.isHidden = true
|
|
vc.toast(msg: error.localizedDescription , time: 2)
|
|
}
|
|
}
|
|
}
|
|
|
|
func getShowListing(categoryID : Int, isBtnClick : Bool = false, languageChange : Bool = false){
|
|
// Utilities.startProgressHUD()
|
|
let headers : HTTPHeaders = ["access-token" : AuthFunc.shareInstance.getAccessToken()]
|
|
let params : Parameters = ["category_id" : categoryID,
|
|
"api_version" : "v2",
|
|
"start" : pageNo,
|
|
"limit": 6] // from category listing api , default will be 1
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.WebSeries.watch_show_listing, method: .post,parameters: params,headers: headers, queue: QueueHelper.utilityGroup) { [weak self](result : Result<BaseResponseModel<WebSeriesShowListDM>, NetworkManager.APIError>) in
|
|
switch result{
|
|
case .success(let data):
|
|
guard let self else{
|
|
Utilities.dismissProgressHUD()
|
|
return
|
|
}
|
|
switch data.success{
|
|
case 0:
|
|
/*
|
|
Error
|
|
*/
|
|
Utilities.dismissProgressHUD()
|
|
vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
case 1:
|
|
Utilities.dismissProgressHUD()
|
|
guard let dataCount = data.data?.totalRecords , let data = data.data?.showData else{return}
|
|
if languageChange{
|
|
self.showData.removeAll()
|
|
self.showData.append(contentsOf: data)
|
|
}else{
|
|
self.showData.append(contentsOf: data)
|
|
}
|
|
self.vc.showListingTableView.reloadData()
|
|
self.vc.tableHeight.constant = self.vc.showListingTableView.contentSize.height + 100
|
|
self.vc.showListingTableView.layoutIfNeeded()
|
|
self.vc.tableHeight.constant = self.vc.showListingTableView.contentSize.height
|
|
|
|
self.stopShimmer()
|
|
|
|
self.vc.loadMoreActivityIndicator.stopAnimating()
|
|
self.vc.loadMoreActivityIndicator.hidesWhenStopped = true
|
|
|
|
if self.showData.count == dataCount{
|
|
self.vc.loadMoreBtn.isHidden = true
|
|
}else{
|
|
self.vc.loadMoreBtn.isHidden = false
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
case .failure(let error):
|
|
guard let self else{
|
|
Utilities.dismissProgressHUD()
|
|
return
|
|
}
|
|
Utilities.dismissProgressHUD()
|
|
vc.toast(msg: error.localizedDescription , time: 2)
|
|
}
|
|
}
|
|
}
|
|
|
|
func getCategoryListing(){
|
|
// Utilities.startProgressHUD()
|
|
let headers : HTTPHeaders = ["access-token" : AuthFunc.shareInstance.getAccessToken()]
|
|
let params : Parameters = ["module_id" : 7] // 7 - webseries
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.WebSeries.category_listing, method: .post,parameters: params,headers : headers) { [weak self](result : Result<BaseResponseModel<CategoryListingDM>, NetworkManager.APIError>) in
|
|
switch result{
|
|
case .success(let data):
|
|
guard let self else{
|
|
Utilities.dismissProgressHUD()
|
|
return
|
|
}
|
|
switch data.success{
|
|
case 0:
|
|
/*
|
|
Error
|
|
*/
|
|
Utilities.dismissProgressHUD()
|
|
vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
case 1:
|
|
Utilities.dismissProgressHUD()
|
|
guard let data = data.data?.result else{return}
|
|
self.categoryListingData = data
|
|
dataSource = categoryListingData.map({$0.categoryName ?? "Unknown"})
|
|
initDropDown()
|
|
default:
|
|
break
|
|
}
|
|
case .failure(let error):
|
|
guard let self else{
|
|
Utilities.dismissProgressHUD()
|
|
return
|
|
}
|
|
Utilities.dismissProgressHUD()
|
|
vc.toast(msg: error.localizedDescription , time: 2)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|