- added api for fetching the episode as per the selected category
- made the category collection cells dynamic - handled the category selection will call the episode api - solved activity indicator view at the splash start-up - handled the app lifecycle for live tv app going in foreground and background - handled play pause while the live tv view apperas and disappears - Made the likes and favourites dynamic on episode screen
This commit is contained in:
@@ -12,29 +12,86 @@ class WebSeriesSeasonVM{
|
||||
|
||||
weak var vc : WebSeriesSeasonVC!
|
||||
|
||||
var watchShowID : Int?
|
||||
// var watchShowID : Int?
|
||||
var categoryID : Int?
|
||||
|
||||
var selectedCateogory = 0
|
||||
var episodeSelectedCateogory : Int?
|
||||
|
||||
var seasonListingData = [SeasonListingDM.Result]()
|
||||
|
||||
var seasonEpisodeData = [SeasonEpisodeListingDM.ResultData]()
|
||||
|
||||
var showData : WebSeriesShowListDM.ShowDatum?
|
||||
|
||||
func initView(){
|
||||
getSeasonListing()
|
||||
setupCell()
|
||||
setShowData()
|
||||
|
||||
vc.shareStack.addTapGesture {
|
||||
print("share")
|
||||
}
|
||||
}
|
||||
|
||||
func setShowData(){
|
||||
guard let showData else{return}
|
||||
vc.totalLikes.text = showData.likesCount?.toString() ?? "0"
|
||||
if let like = showData.isLiked{
|
||||
switch like{
|
||||
case true:
|
||||
vc.likeIcon.image = UIImage(systemName: "hand.thumbsup.fill")
|
||||
vc.likeLabel.text = "Liked"
|
||||
case false:
|
||||
vc.likeIcon.image = UIImage(systemName: "hand.thumbsup")
|
||||
vc.likeLabel.text = "Like"
|
||||
}
|
||||
}
|
||||
|
||||
if let favourite = showData.markAsFavourite{
|
||||
if let categoryIds = showData.favouriteCategoryIDS?.rawValue { // if string, it means category is selected for multiple language
|
||||
let components = categoryIds.components(separatedBy: ",")
|
||||
if favourite == true && (components.first == categoryID?.toString() || components.last == categoryID?.toString()){
|
||||
vc.addIcon.image = UIImage(systemName: "heart.fill")
|
||||
vc.addLabel.text = "Added"
|
||||
}else{
|
||||
vc.addIcon.image = UIImage(systemName: "heart")
|
||||
vc.addLabel.text = "Add"
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if favourite == true && showData.favouriteCategoryIDS?.intValue == categoryID{
|
||||
vc.addIcon.image = UIImage(systemName: "heart.fill")
|
||||
vc.addLabel.text = "Added"
|
||||
}else{
|
||||
vc.addIcon.image = UIImage(systemName: "heart")
|
||||
vc.addLabel.text = "Add"
|
||||
}
|
||||
// switch favourite{
|
||||
// case true:
|
||||
// favBtn.setImage(UIImage(systemName: "heart.fill"), for: .normal)
|
||||
// case false:
|
||||
// favBtn.setImage(UIImage(systemName: "heart"), for: .normal)
|
||||
//
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
func setupCell(){
|
||||
vc.categoryCV.register(UINib(nibName: K.CellIdentifier.WebSeries.seasonCategoryCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.WebSeries.seasonCategoryCell)
|
||||
vc.categoryCV.delegate = vc.self
|
||||
vc.categoryCV.dataSource = vc.self
|
||||
|
||||
vc.episodeTableView.register(UINib(nibName: K.CellIdentifier.WebSeries.webSeriesEpisodeCell, bundle: nil), forCellReuseIdentifier: K.CellIdentifier.WebSeries.webSeriesEpisodeCell)
|
||||
vc.episodeTableView.delegate = vc.self
|
||||
vc.episodeTableView.dataSource = vc.self
|
||||
}
|
||||
|
||||
// MARK: - Api Calls
|
||||
|
||||
func getSeasonListing(){
|
||||
Utilities.startProgressHUD()
|
||||
guard let watchShowID, let categoryID else{return}
|
||||
guard let watchShowID = showData?.id, let categoryID else{return}
|
||||
let headers : HTTPHeaders = ["access-token" : AuthFunc.shareInstance.getAccessToken()]
|
||||
let params : Parameters = ["watch_show_id" : watchShowID,
|
||||
"category_id" : categoryID]
|
||||
@@ -57,6 +114,8 @@ class WebSeriesSeasonVM{
|
||||
guard let data = data.data?.result else{return}
|
||||
self.seasonListingData = data
|
||||
setSeasonData()
|
||||
episodeSelectedCateogory = seasonListingData.first?.id
|
||||
getSeasonEpisode()
|
||||
self.vc.categoryCV.reloadData()
|
||||
default:
|
||||
break
|
||||
@@ -99,4 +158,48 @@ class WebSeriesSeasonVM{
|
||||
vc.seasonEpisodes.text = data.noOfEpisodes?.toString()
|
||||
vc.seasonMediaType.text = data.mediaType
|
||||
}
|
||||
|
||||
func getSeasonEpisode(){
|
||||
Utilities.startProgressHUD()
|
||||
guard let watchShowID = showData?.id, let episodeSelectedCateogory else{return}
|
||||
let headers : HTTPHeaders = ["access-token" : AuthFunc.shareInstance.getAccessToken()]
|
||||
let params : Parameters = ["watch_show_id" : watchShowID,
|
||||
"season_id" : episodeSelectedCateogory]
|
||||
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.WebSeries.season_episode_listing, method: .post,parameters: params,headers : headers) { [weak self](result : Result<BaseResponseModel<SeasonEpisodeListingDM>, 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.seasonEpisodeData.removeAll()
|
||||
self.seasonEpisodeData = data
|
||||
|
||||
self.vc.episodeTableView.reloadData()
|
||||
self.vc.tableHeight.constant = self.vc.episodeTableView.contentSize.height + 100
|
||||
self.vc.episodeTableView.layoutIfNeeded()
|
||||
self.vc.tableHeight.constant = self.vc.episodeTableView.contentSize.height
|
||||
default:
|
||||
break
|
||||
}
|
||||
case .failure(let error):
|
||||
guard let self else{
|
||||
Utilities.dismissProgressHUD()
|
||||
return
|
||||
}
|
||||
Utilities.dismissProgressHUD()
|
||||
vc.toast(msg: error.localizedDescription , time: 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user