2024-06-13 19:54:44 +05:30
|
|
|
//
|
|
|
|
|
// MyListVM.swift
|
|
|
|
|
// WOKA
|
|
|
|
|
//
|
|
|
|
|
// Created by MacBook Pro on 13/06/24.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
import Alamofire
|
|
|
|
|
|
2024-06-27 19:51:43 +05:30
|
|
|
enum CollectionSelectionMyList{
|
|
|
|
|
case webSeriesCV
|
|
|
|
|
case webSeriesHindiCV
|
|
|
|
|
case audioBooksCV
|
|
|
|
|
case karaokeCV
|
|
|
|
|
case gamesCV
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 19:54:44 +05:30
|
|
|
class MyListVM{
|
|
|
|
|
weak var vc : MyListVC!
|
|
|
|
|
var favListingData : FavouriteListingDM.ResultData?
|
|
|
|
|
|
|
|
|
|
var webSeriesHindi = [FavouriteListingDM.ResultData.ShowDatum]()
|
|
|
|
|
|
2024-06-14 21:27:18 +05:30
|
|
|
let refreshControl = UIRefreshControl()
|
|
|
|
|
let feedbackGenerator = UIImpactFeedbackGenerator(style: .light)
|
|
|
|
|
|
2024-06-27 19:51:43 +05:30
|
|
|
var selectedCollection : CollectionSelectionMyList?
|
|
|
|
|
|
2024-06-13 19:54:44 +05:30
|
|
|
func initView(){
|
2024-07-16 19:56:09 +05:30
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(languageChanged), name: .languageDidChange, object: nil)
|
|
|
|
|
|
|
|
|
|
if AuthFunc.shareInstance.getUserType() == 3{ // handle guest
|
|
|
|
|
vc.guestLoginView.isHidden = false
|
|
|
|
|
vc.guestLoginStack.isHidden = false
|
|
|
|
|
vc.scrollView.isHidden = true
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 19:54:44 +05:30
|
|
|
setupCell()
|
2024-06-14 21:27:18 +05:30
|
|
|
Utilities.startProgressHUD()
|
2024-06-13 19:54:44 +05:30
|
|
|
getFavouriteListing()
|
2024-06-14 21:27:18 +05:30
|
|
|
}
|
|
|
|
|
|
2024-07-01 20:00:12 +05:30
|
|
|
func addGradient(){
|
|
|
|
|
let color1 = #colorLiteral(red: 0.6745098039, green: 0.6235294118, blue: 0.1725490196, alpha: 1)
|
|
|
|
|
let color2 = #colorLiteral(red: 0.5450980392, green: 0.6745098039, blue: 0.1725490196, alpha: 1)
|
|
|
|
|
|
|
|
|
|
vc.gradientView.applyGradient(colors: [color2, color1], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0.8, y: 0))
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 21:27:18 +05:30
|
|
|
@objc func languageChanged(){
|
|
|
|
|
self.reloadCollections()
|
2024-06-13 19:54:44 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func setupCell(){
|
|
|
|
|
vc.webSeriesCV.register(UINib(nibName: K.CellIdentifier.Home.favouriteCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.Home.favouriteCell)
|
|
|
|
|
vc.webSeriesCV.delegate = vc.self
|
|
|
|
|
vc.webSeriesCV.dataSource = vc.self
|
|
|
|
|
|
|
|
|
|
vc.webSeriesHindiCV.register(UINib(nibName: K.CellIdentifier.Home.favouriteCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.Home.favouriteCell)
|
|
|
|
|
vc.webSeriesHindiCV.delegate = vc.self
|
|
|
|
|
vc.webSeriesHindiCV.dataSource = vc.self
|
|
|
|
|
|
|
|
|
|
vc.audioBooksCV.register(UINib(nibName: K.CellIdentifier.Home.favouriteCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.Home.favouriteCell)
|
|
|
|
|
vc.audioBooksCV.delegate = vc.self
|
|
|
|
|
vc.audioBooksCV.dataSource = vc.self
|
|
|
|
|
|
|
|
|
|
vc.karaokeCV.register(UINib(nibName: K.CellIdentifier.Home.favouriteCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.Home.favouriteCell)
|
|
|
|
|
vc.karaokeCV.delegate = vc.self
|
|
|
|
|
vc.karaokeCV.dataSource = vc.self
|
|
|
|
|
|
|
|
|
|
vc.gamesCV.register(UINib(nibName: K.CellIdentifier.Home.favouriteCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.Home.favouriteCell)
|
|
|
|
|
vc.gamesCV.delegate = vc.self
|
|
|
|
|
vc.gamesCV.dataSource = vc.self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - Get Favourite Listing
|
|
|
|
|
|
|
|
|
|
func getFavouriteListing(){
|
2024-06-14 21:27:18 +05:30
|
|
|
|
2024-06-13 19:54:44 +05:30
|
|
|
let headers : HTTPHeaders = ["Accept-Language" : AuthFunc.shareInstance.languageSelected == .english ? "English" : "Hindi",
|
|
|
|
|
"access-token": AuthFunc.shareInstance.getAccessToken()]
|
|
|
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Home.favourite_listing, method: .post, headers: headers) { [weak self](result : Result<BaseResponseModel<FavouriteListingDM>, NetworkManager.APIError>) in
|
|
|
|
|
switch result{
|
|
|
|
|
case .success(let data):
|
|
|
|
|
guard let self else{return}
|
|
|
|
|
switch data.success{
|
|
|
|
|
case 0:
|
2024-06-14 21:27:18 +05:30
|
|
|
self.refreshControl.endRefreshing()
|
2024-06-13 19:54:44 +05:30
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
2024-06-30 23:29:32 +05:30
|
|
|
webSeriesHindi.removeAll()
|
|
|
|
|
favListingData = nil
|
2024-06-14 21:27:18 +05:30
|
|
|
reloadCollections()
|
|
|
|
|
checkNil()
|
2024-06-13 19:54:44 +05:30
|
|
|
case 1:
|
2024-06-14 21:27:18 +05:30
|
|
|
self.refreshControl.endRefreshing()
|
2024-06-13 19:54:44 +05:30
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
guard let data = data.data?.result else{return}
|
2024-06-14 21:27:18 +05:30
|
|
|
favListingData = nil
|
|
|
|
|
webSeriesHindi.removeAll()
|
|
|
|
|
|
2024-06-13 19:54:44 +05:30
|
|
|
favListingData = data
|
|
|
|
|
|
|
|
|
|
if var hindiData = favListingData?.showData{
|
2024-06-30 23:29:32 +05:30
|
|
|
|
|
|
|
|
/*
|
2024-06-13 19:54:44 +05:30
|
|
|
Taking out the hindi series , 1-> English , 18-> Hindi
|
2024-06-30 23:29:32 +05:30
|
|
|
And the saving it to hindi series, also modify the bookmark category ids
|
2024-06-13 19:54:44 +05:30
|
|
|
*/
|
2024-06-30 23:29:32 +05:30
|
|
|
webSeriesHindi = hindiData.compactMap { $0 }.filter {
|
|
|
|
|
($0.bookmarkCategoryIDS?.components(separatedBy: ",").first == "18" || $0.bookmarkCategoryIDS?.components(separatedBy: ",").last == "18")
|
|
|
|
|
}.map { element -> FavouriteListingDM.ResultData.ShowDatum in
|
|
|
|
|
var modifiedElement = element
|
|
|
|
|
modifiedElement.bookmarkCategoryIDS = "18"
|
|
|
|
|
return modifiedElement
|
|
|
|
|
}
|
2024-06-13 19:54:44 +05:30
|
|
|
|
2024-06-20 19:51:39 +05:30
|
|
|
if let data = favListingData?.showData{
|
|
|
|
|
var indicesToRemove = [Int]()
|
|
|
|
|
|
|
|
|
|
// Deleting the hindi series from main (those with category ID "18")
|
|
|
|
|
for (index, element) in data.enumerated() {
|
|
|
|
|
if let bookMarkCatID = element.bookmarkCategoryIDS?.components(separatedBy: ","){
|
2024-06-25 11:29:00 +05:30
|
|
|
if bookMarkCatID.count > 1{ // means multiple language
|
|
|
|
|
/*
|
|
|
|
|
if its greater than one , its for sure we have extracted the hindi episode
|
|
|
|
|
*/
|
2024-06-20 19:51:39 +05:30
|
|
|
hindiData[index].bookmarkCategoryIDS = "1"
|
2024-06-25 11:29:00 +05:30
|
|
|
}else{ // means single language
|
|
|
|
|
if bookMarkCatID.first == "18"{
|
|
|
|
|
indicesToRemove.append(index)
|
|
|
|
|
}
|
2024-06-20 19:51:39 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-19 20:07:47 +05:30
|
|
|
|
2024-06-20 19:51:39 +05:30
|
|
|
// Remove items in reverse order to avoid index shifting issues
|
|
|
|
|
for index in indicesToRemove.reversed() {
|
|
|
|
|
hindiData.remove(at: index)
|
2024-06-19 20:07:47 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-20 19:51:39 +05:30
|
|
|
|
2024-06-13 19:54:44 +05:30
|
|
|
// Updating the showData with the filtered list
|
|
|
|
|
favListingData?.showData = hindiData
|
|
|
|
|
}
|
2024-06-14 21:27:18 +05:30
|
|
|
reloadCollections()
|
|
|
|
|
feedbackGenerator.impactOccurred()
|
|
|
|
|
checkNil()
|
2024-06-13 19:54:44 +05:30
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
case .failure(let error):
|
|
|
|
|
guard let self else{return}
|
2024-06-14 21:27:18 +05:30
|
|
|
self.refreshControl.endRefreshing()
|
2024-06-13 19:54:44 +05:30
|
|
|
Utilities.dismissProgressHUD()
|
2024-06-14 21:27:18 +05:30
|
|
|
checkNil()
|
2024-06-13 19:54:44 +05:30
|
|
|
self.vc.toast(msg: error.localizedDescription , time: 2)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-14 21:27:18 +05:30
|
|
|
|
|
|
|
|
// MARK: - Like , unlike
|
|
|
|
|
|
|
|
|
|
func likePost(postID : Int, postType : Int, index : Int , onCompletion : @escaping (Bool) -> Void){
|
|
|
|
|
Utilities.startProgressHUD()
|
|
|
|
|
let headers : HTTPHeaders = ["Accept-Language" : AuthFunc.shareInstance.languageSelected == .english ? "English" : "Hindi",
|
|
|
|
|
"access-token": AuthFunc.shareInstance.getAccessToken()]
|
|
|
|
|
|
|
|
|
|
let params : Parameters = ["post_id" : postID,
|
|
|
|
|
"post_type" : postType]
|
|
|
|
|
|
|
|
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Home.post_like, method: .post, parameters: params, headers: headers) { [weak self](result : Result<CommonResponseModel, NetworkManager.APIError>) in
|
|
|
|
|
switch result{
|
|
|
|
|
case .success(let data):
|
|
|
|
|
guard let self else{return}
|
|
|
|
|
switch data.success{
|
|
|
|
|
case 0:
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
|
|
|
onCompletion(false)
|
|
|
|
|
case 1:
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
onCompletion(true)
|
|
|
|
|
default:
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
onCompletion(false)
|
|
|
|
|
}
|
|
|
|
|
case .failure(let error):
|
|
|
|
|
guard let self else{return}
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
self.vc.toast(msg: error.localizedDescription , time: 2)
|
|
|
|
|
onCompletion(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func unlikePost(postID : Int, postType : Int , index : Int, onCompletion : @escaping (Bool) -> Void){
|
|
|
|
|
Utilities.startProgressHUD()
|
|
|
|
|
let headers : HTTPHeaders = ["Accept-Language" : AuthFunc.shareInstance.languageSelected == .english ? "English" : "Hindi",
|
|
|
|
|
"access-token": AuthFunc.shareInstance.getAccessToken()]
|
|
|
|
|
|
|
|
|
|
let params : Parameters = ["post_id" : postID,
|
|
|
|
|
"post_type" : postType]
|
|
|
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Home.post_unlike, method: .post, parameters: params, headers: headers) { [weak self](result : Result<BaseResponseModel<CommonResponseModel>, NetworkManager.APIError>) in
|
|
|
|
|
switch result{
|
|
|
|
|
case .success(let data):
|
|
|
|
|
guard let self else{return}
|
|
|
|
|
switch data.success{
|
|
|
|
|
case 0:
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
|
|
|
onCompletion(false)
|
|
|
|
|
case 1:
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
onCompletion(true)
|
|
|
|
|
default:
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
onCompletion(false)
|
|
|
|
|
}
|
|
|
|
|
case .failure(let error):
|
|
|
|
|
guard let self else{return}
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
self.vc.toast(msg: error.localizedDescription , time: 2)
|
|
|
|
|
onCompletion(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - Remove Favourite
|
|
|
|
|
|
|
|
|
|
func removeFavourite(postID : Int, postType : Int, categoryID : String, index : Int , onCompletion : @escaping (Bool) -> Void){
|
|
|
|
|
Utilities.startProgressHUD()
|
|
|
|
|
let headers : HTTPHeaders = ["Accept-Language" : AuthFunc.shareInstance.languageSelected == .english ? "English" : "Hindi",
|
|
|
|
|
"access-token": AuthFunc.shareInstance.getAccessToken()]
|
|
|
|
|
|
|
|
|
|
let params : Parameters = ["id" : postID,
|
|
|
|
|
"post_type" : postType,
|
|
|
|
|
"category_id" : categoryID]
|
|
|
|
|
NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Home.favourite_remove, method: .post, parameters: params, headers: headers) { [weak self](result : Result<CommonResponseModel, NetworkManager.APIError>) in
|
|
|
|
|
switch result{
|
|
|
|
|
case .success(let data):
|
|
|
|
|
guard let self else{return}
|
|
|
|
|
switch data.success{
|
|
|
|
|
case 0:
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
self.vc.toast(msg: data.message ?? "Unrecognised error" , time: 2)
|
|
|
|
|
onCompletion(false)
|
|
|
|
|
case 1:
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
onCompletion(true)
|
|
|
|
|
default:
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
onCompletion(false)
|
|
|
|
|
}
|
|
|
|
|
case .failure(let error):
|
|
|
|
|
guard let self else{return}
|
|
|
|
|
Utilities.dismissProgressHUD()
|
|
|
|
|
self.vc.toast(msg: error.localizedDescription , time: 2)
|
|
|
|
|
onCompletion(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func checkNil(){
|
|
|
|
|
guard let data = favListingData else{
|
|
|
|
|
self.vc.noDataStack.isHidden = false
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if data.showData?.count == 0 && data.singKaraokeData?.count == 0 && data.gameData?.count == 0 && data.audioData?.count == 0 && webSeriesHindi.count == 0{
|
|
|
|
|
self.vc.noDataStack.isHidden = false
|
|
|
|
|
}else{
|
|
|
|
|
self.vc.noDataStack.isHidden = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func reloadCollections(){
|
|
|
|
|
vc.webSeriesCV.reloadData()
|
|
|
|
|
vc.webSeriesHindiCV.reloadData()
|
|
|
|
|
vc.audioBooksCV.reloadData()
|
|
|
|
|
vc.karaokeCV.reloadData()
|
|
|
|
|
vc.gamesCV.reloadData()
|
|
|
|
|
}
|
2024-06-13 19:54:44 +05:30
|
|
|
}
|