diff --git a/WOKA/Audio Books/AudioBookDetailsVC.swift b/WOKA/Audio Books/AudioBookDetailsVC.swift index 947583e..e1978e0 100644 --- a/WOKA/Audio Books/AudioBookDetailsVC.swift +++ b/WOKA/Audio Books/AudioBookDetailsVC.swift @@ -7,10 +7,6 @@ import UIKit -//protocol ReloadAudioBooksFavLike{ -// func updateAudioRows(id : Int, type : FavCellCLick, isFav : Bool? , isLike : Bool? ) -//} - class AudioBookDetailsVC : UIViewController{ @IBOutlet weak var watchingImage: UIImageView! @@ -34,7 +30,7 @@ class AudioBookDetailsVC : UIViewController{ var audioData : ListenAudioListingDM.AudioDatum? - var continueAudioData : ListenAudioListingDM.AudioDatum? +// var continueAudioData : ListenAudioListingDM.AudioDatum? var audioIndex = 0 override func viewDidLoad() { @@ -69,40 +65,57 @@ class AudioBookDetailsVC : UIViewController{ if isFav { LikeFavCommonFunc.shareInstance.removeFavourite(postID: showID, postType: postType, categoryID: 0, vc: self) { isDone in self.audioData?.markAsFavourite = false - K.GVar.reloadMyList = true + + if let index = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == showID}){ + MyListDataTemp.shareInstance.favListingData?.audioData?.remove(at: index) + K.GVar.myListSoftReload = true + } + self.delegate?.updateRows(index: self.audioIndex, type: .favourite, isFav: false, isLike: nil, id: showID) self.initView() } }else{ LikeFavCommonFunc.shareInstance.addFavourite(postID: showID, postType: postType, categoryID: 0, vc: self) { isDone in self.audioData?.markAsFavourite = true - K.GVar.reloadMyList = true - self.delegate?.updateRows(index: self.audioIndex, type: .favourite, isFav: true, isLike: nil, id: showID) - self.initView() - } - } - } - - if let continueAudioData{ - guard let showID = continueAudioData.id, let isFav = continueAudioData.markAsFavourite, let postType = continueAudioData.contentMoreDetails?.first?.postType else{return} - - if isFav { - LikeFavCommonFunc.shareInstance.removeFavourite(postID: showID, postType: postType, categoryID: 0, vc: self) { isDone in - self.continueAudioData?.markAsFavourite = false - K.GVar.reloadMyList = true - self.delegate?.updateRows(index: self.audioIndex, type: .favourite, isFav: false, isLike: nil, id: showID) - self.initView() - } - }else{ - LikeFavCommonFunc.shareInstance.addFavourite(postID: showID, postType: postType, categoryID: 0, vc: self) { isDone in - self.continueAudioData?.markAsFavourite = true - K.GVar.reloadMyList = true + + if let audioData = self.audioData{ + MyListDataTemp.shareInstance.favListingData?.audioData?.append(audioData) + K.GVar.myListSoftReload = true + } + self.delegate?.updateRows(index: self.audioIndex, type: .favourite, isFav: true, isLike: nil, id: showID) self.initView() } } } +// if let continueAudioData{ +// guard let showID = continueAudioData.id, let isFav = continueAudioData.markAsFavourite, let postType = continueAudioData.contentMoreDetails?.first?.postType else{return} +// +// if isFav { +// LikeFavCommonFunc.shareInstance.removeFavourite(postID: showID, postType: postType, categoryID: 0, vc: self) { isDone in +// self.continueAudioData?.markAsFavourite = false +// if let index = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == showID}){ +// MyListDataTemp.shareInstance.favListingData?.audioData?.remove(at: index) +// K.GVar.myListSoftReload = true +// } +// self.delegate?.updateRows(index: self.audioIndex, type: .favourite, isFav: false, isLike: nil, id: showID) +// self.initView() +// } +// }else{ +// LikeFavCommonFunc.shareInstance.addFavourite(postID: showID, postType: postType, categoryID: 0, vc: self) { isDone in +// self.continueAudioData?.markAsFavourite = true +// if let audioData = self.audioData{ +// if MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == showID}) == nil{ +// MyListDataTemp.shareInstance.favListingData?.audioData?.append(audioData) +// K.GVar.myListSoftReload = true +// } +// } +// self.delegate?.updateRows(index: self.audioIndex, type: .favourite, isFav: true, isLike: nil, id: showID) +// self.initView() +// } +// } +// } } likeView.addTapGesture { [weak self] in @@ -116,51 +129,70 @@ class AudioBookDetailsVC : UIViewController{ if isLiked{ LikeFavCommonFunc.shareInstance.unlikePost(postID: showID, postType: postType, vc: self) { isDone in self.audioData?.isLiked = false - if self.audioData?.likesCount != nil{ - self.audioData?.likesCount! -= 1 + self.audioData?.likesCount! -= 1 + + if let index = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == showID}){ + MyListDataTemp.shareInstance.favListingData?.audioData?[index].isLiked = false + MyListDataTemp.shareInstance.favListingData?.audioData?[index].likesCount! -= 1 + K.GVar.myListSoftReload = true } - K.GVar.reloadMyList = true self.delegate?.updateRows(index: self.audioIndex, type: .liked, isFav: nil, isLike: false, id: showID) self.initView() } }else{ LikeFavCommonFunc.shareInstance.likePost(postID: showID, postType: postType, vc: self) { isDone in self.audioData?.isLiked = true - if self.audioData?.likesCount != nil{ - self.audioData?.likesCount! += 1 + self.audioData?.likesCount! += 1 + + if let index = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == showID}){ + MyListDataTemp.shareInstance.favListingData?.audioData?[index].isLiked = true + MyListDataTemp.shareInstance.favListingData?.audioData?[index].likesCount! += 1 + K.GVar.myListSoftReload = true } - K.GVar.reloadMyList = true + self.delegate?.updateRows(index: self.audioIndex, type: .liked, isFav: nil, isLike: true, id: showID) self.initView() } } } - if let continueAudioData{ - guard let showID = continueAudioData.id, let isLiked = continueAudioData.isLiked, let postType = continueAudioData.contentMoreDetails?.first?.postType else{return} - - if isLiked{ - LikeFavCommonFunc.shareInstance.unlikePost(postID: showID, postType: postType, vc: self) { isDone in - self.continueAudioData?.isLiked = false - if self.audioData?.likesCount != nil{ - self.audioData?.likesCount! -= 1 - } - K.GVar.reloadMyList = true - self.delegate?.updateRows(index: self.audioIndex, type: .liked, isFav: nil, isLike: false, id: showID) - self.initView() - } - }else{ - LikeFavCommonFunc.shareInstance.likePost(postID: showID, postType: postType, vc: self) { isDone in - self.continueAudioData?.isLiked = true - if self.audioData?.likesCount != nil{ - self.audioData?.likesCount! += 1 - } - K.GVar.reloadMyList = true - self.delegate?.updateRows(index: self.audioIndex, type: .liked, isFav: nil, isLike: true, id: showID) - self.initView() - } - } - } +// if let continueAudioData{ +// guard let showID = continueAudioData.id, let isLiked = continueAudioData.isLiked, let postType = continueAudioData.contentMoreDetails?.first?.postType else{return} +// +// if isLiked{ +// LikeFavCommonFunc.shareInstance.unlikePost(postID: showID, postType: postType, vc: self) { isDone in +// self.continueAudioData?.isLiked = false +// if self.audioData?.likesCount != nil{ +// self.audioData?.likesCount! -= 1 +// } +// +// if let index = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == showID}){ +// MyListDataTemp.shareInstance.favListingData?.audioData?[index].isLiked = false +// MyListDataTemp.shareInstance.favListingData?.audioData?[index].likesCount! -= 1 +// K.GVar.myListSoftReload = true +// } +// +// self.delegate?.updateRows(index: self.audioIndex, type: .liked, isFav: nil, isLike: false, id: showID) +// self.initView() +// } +// }else{ +// LikeFavCommonFunc.shareInstance.likePost(postID: showID, postType: postType, vc: self) { isDone in +// self.continueAudioData?.isLiked = true +// if self.audioData?.likesCount != nil{ +// self.audioData?.likesCount! += 1 +// } +// +// if let index = MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.firstIndex(where: {$0.id == showID}){ +// MyListDataTemp.shareInstance.favListingData?.audioData?[index].isLiked = true +// MyListDataTemp.shareInstance.favListingData?.audioData?[index].likesCount! += 1 +// K.GVar.myListSoftReload = true +// } +// +// self.delegate?.updateRows(index: self.audioIndex, type: .liked, isFav: nil, isLike: true, id: showID) +// self.initView() +// } +// } +// } } @@ -218,53 +250,53 @@ class AudioBookDetailsVC : UIViewController{ } } - if let continueAudioData{ - if let url = continueAudioData.thumbnailPath{ - watchingImage.imageURL(url, color: .white) - } - - totalLikes.text = continueAudioData.likesCount?.toString() ?? "0" - if let like = continueAudioData.isLiked{ - switch like{ - case true: - likeIcon.image = UIImage(systemName: "hand.thumbsup.fill") - likeLabel.text = "LIKED".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue) - case false: - likeIcon.image = UIImage(systemName: "hand.thumbsup") - likeLabel.text = "LIKE".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue) - } - } - - if let favourite = continueAudioData.markAsFavourite{ - if favourite == true{ - addIcon.image = UIImage(systemName: "heart.fill") - addLabel.text = "ADDED".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue) - }else{ - addIcon.image = UIImage(systemName: "heart") - addLabel.text = "ADD".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue) - } - } - - if AuthFunc.shareInstance.getDefaultLanguage() == .english{ - if let englishData = continueAudioData.contentMoreDetails?.filter({$0.languageMasterID == 1}).first{ - watchingTitle.text = englishData.title - if let desc = englishData.description?.replacingOccurrences(of: "
", with: "").htmlToAttributedString{ - let sizeText = NSMutableAttributedString(attributedString: desc) - sizeText.setFontFace(font: FontCustom.shareInstance.customFont(fontName: .Exo2_Regular, size: 15),color: UIColor.appColor(.TextDarkBlue)!) - self.watchingDesc.attributedText = sizeText - } - } - }else{ - if let hindiData = continueAudioData.contentMoreDetails?.filter({$0.languageMasterID == 2}).first{ - watchingTitle.text = hindiData.title - if let desc = hindiData.description?.replacingOccurrences(of: "
", with: "").htmlToAttributedString{ - let sizeText = NSMutableAttributedString(attributedString: desc) - sizeText.setFontFace(font: FontCustom.shareInstance.customFont(fontName: .Exo2_Regular, size: 15),color: UIColor.appColor(.TextDarkBlue)!) - self.watchingDesc.attributedText = sizeText - } - } - } - } +// if let continueAudioData{ +// if let url = continueAudioData.thumbnailPath{ +// watchingImage.imageURL(url, color: .white) +// } +// +// totalLikes.text = continueAudioData.likesCount?.toString() ?? "0" +// if let like = continueAudioData.isLiked{ +// switch like{ +// case true: +// likeIcon.image = UIImage(systemName: "hand.thumbsup.fill") +// likeLabel.text = "LIKED".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue) +// case false: +// likeIcon.image = UIImage(systemName: "hand.thumbsup") +// likeLabel.text = "LIKE".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue) +// } +// } +// +// if let favourite = continueAudioData.markAsFavourite{ +// if favourite == true{ +// addIcon.image = UIImage(systemName: "heart.fill") +// addLabel.text = "ADDED".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue) +// }else{ +// addIcon.image = UIImage(systemName: "heart") +// addLabel.text = "ADD".localized(loc: AuthFunc.shareInstance.languageSelected.rawValue) +// } +// } +// +// if AuthFunc.shareInstance.getDefaultLanguage() == .english{ +// if let englishData = continueAudioData.contentMoreDetails?.filter({$0.languageMasterID == 1}).first{ +// watchingTitle.text = englishData.title +// if let desc = englishData.description?.replacingOccurrences(of: "
", with: "").htmlToAttributedString{ +// let sizeText = NSMutableAttributedString(attributedString: desc) +// sizeText.setFontFace(font: FontCustom.shareInstance.customFont(fontName: .Exo2_Regular, size: 15),color: UIColor.appColor(.TextDarkBlue)!) +// self.watchingDesc.attributedText = sizeText +// } +// } +// }else{ +// if let hindiData = continueAudioData.contentMoreDetails?.filter({$0.languageMasterID == 2}).first{ +// watchingTitle.text = hindiData.title +// if let desc = hindiData.description?.replacingOccurrences(of: "
", with: "").htmlToAttributedString{ +// let sizeText = NSMutableAttributedString(attributedString: desc) +// sizeText.setFontFace(font: FontCustom.shareInstance.customFont(fontName: .Exo2_Regular, size: 15),color: UIColor.appColor(.TextDarkBlue)!) +// self.watchingDesc.attributedText = sizeText +// } +// } +// } +// } } @IBAction func watchBtnTapped(_ sender: LocalisedElementsButton) { @@ -282,17 +314,17 @@ class AudioBookDetailsVC : UIViewController{ } } - if let continueAudioData{ - if AuthFunc.shareInstance.getDefaultLanguage() == .english{ - if let englishData = continueAudioData.contentMoreDetails?.filter({$0.languageMasterID == 1}).first, let url = englishData.url{ - playerItems.append(JwPlayerItemCreate(url: url, poster: continueAudioData.thumbnailPath, titles: englishData.title)) - } - }else{ - if let hindiData = continueAudioData.contentMoreDetails?.filter({$0.languageMasterID == 2}).first, let url = hindiData.url{ - playerItems.append(JwPlayerItemCreate(url: url, poster: continueAudioData.thumbnailPath, titles: hindiData.title)) - } - } - } +// if let continueAudioData{ +// if AuthFunc.shareInstance.getDefaultLanguage() == .english{ +// if let englishData = continueAudioData.contentMoreDetails?.filter({$0.languageMasterID == 1}).first, let url = englishData.url{ +// playerItems.append(JwPlayerItemCreate(url: url, poster: continueAudioData.thumbnailPath, titles: englishData.title)) +// } +// }else{ +// if let hindiData = continueAudioData.contentMoreDetails?.filter({$0.languageMasterID == 2}).first, let url = hindiData.url{ +// playerItems.append(JwPlayerItemCreate(url: url, poster: continueAudioData.thumbnailPath, titles: hindiData.title)) +// } +// } +// } JWPlayerManager.shared.presentPlayer(from: self, playerItems: playerItems, startIndex: 0, contentType: .audioBooks) } diff --git a/WOKA/Audio Books/AudioBookHomeVC.swift b/WOKA/Audio Books/AudioBookHomeVC.swift index 55191d8..cfaeea3 100644 --- a/WOKA/Audio Books/AudioBookHomeVC.swift +++ b/WOKA/Audio Books/AudioBookHomeVC.swift @@ -103,7 +103,6 @@ extension AudioBookHomeVC : ReloadSeriesFavLike{ if let audioListDataIndex = vm.audioListData.firstIndex(where:{$0.id == id}) { vm.audioListData[audioListDataIndex].markAsFavourite = isFav audioListingTableView.reloadRows(at: [IndexPath(row: audioListDataIndex, section: 0)],with: .none) - K.GVar.reloadMyList = true } } @@ -126,7 +125,6 @@ extension AudioBookHomeVC : ReloadSeriesFavLike{ vm.audioListData[audioListDataIndex].likesCount! -= 1 } audioListingTableView.reloadRows(at: [IndexPath(row: audioListDataIndex, section: 0)],with: .none) - K.GVar.reloadMyList = true } } @@ -216,7 +214,7 @@ extension AudioBookHomeVC : CollectionViewSRC{ let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.AudioBooks.audioBookDetailsVC) as! AudioBookDetailsVC vcPush.modalPresentationStyle = .overCurrentContext vcPush.modalTransitionStyle = .crossDissolve - vcPush.continueAudioData = data + vcPush.audioData = data vcPush.delegate = self self.present(vcPush, animated: true) diff --git a/WOKA/Home/Controller/MyListVC.swift b/WOKA/Home/Controller/MyListVC.swift index 725a5cc..0459970 100644 --- a/WOKA/Home/Controller/MyListVC.swift +++ b/WOKA/Home/Controller/MyListVC.swift @@ -188,7 +188,7 @@ extension MyListVC : CollectionViewSRC{ guard let data = MyListDataTemp.shareInstance.favListingData?.showData?[index] else{return} switch type { case .favourite: - guard let isFav = data.markAsFavourite ,let postID = data.id,let postType = data.contentMoreDetails?.first?.postType,let categoryID = data.bookmarkCategoryIDS else{return} + guard let isFav = data.markAsFavourite ,let postID = data.id,let postType = data.contentMoreDetails?.first?.postType,let categoryID = data.categoryMasterID else{return} if isFav{ vm.removeFavourite(postID: postID, postType: postType, categoryID: categoryID, index: index) { [unowned self] isDone in if isDone{ @@ -238,7 +238,7 @@ extension MyListVC : CollectionViewSRC{ let data = MyListDataTemp.shareInstance.webSeriesHindi[index] switch type { case .favourite: - guard let isFav = data.markAsFavourite ,let postID = data.id,let postType = data.contentMoreDetails?.first?.postType,let categoryID = data.bookmarkCategoryIDS else{return} + guard let isFav = data.markAsFavourite ,let postID = data.id,let postType = data.contentMoreDetails?.first?.postType,let categoryID = data.categoryMasterID else{return} if isFav{ vm.removeFavourite(postID: postID, postType: postType, categoryID: categoryID, index: index) { [unowned self] isDone in if isDone{ @@ -475,36 +475,6 @@ extension MyListVC : CollectionViewSRC{ } // MARK: - Delegate for reload -//extension MyListVC : ReloadAudioBooksFavLike{ -// -// func updateAudioRows(id: Int, type: FavCellCLick, isFav: Bool?, isLike: Bool?) { -// -// switch vm.selectedCollection { -// case .karaokeCV: -// break -// default: -// if let isFav{ -// -// if let audioListDataIndex = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where:{$0.id == id}) { -// MyListDataTemp.shareInstance.favListingData?.audioData?[audioListDataIndex].markAsFavourite = isFav -// audioBooksCV.reloadItems(at: [IndexPath(row: audioListDataIndex, section: 0)]) -// K.GVar.reloadMyList = true -// } -// } -// -// if let isLike{ -// -// if let audioListDataIndex = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where:{$0.id == id}) { -// MyListDataTemp.shareInstance.favListingData?.audioData?[audioListDataIndex].isLiked = isLike -// audioBooksCV.reloadItems(at: [IndexPath(row: audioListDataIndex, section: 0)]) -// K.GVar.reloadMyList = true -// } -// } -// } -// -// } -//} - extension MyListVC : ReloadSeriesFavLike{ //Updates from details func updateRows(index: Int, type: FavCellCLick, isFav: Bool?, isLike: Bool?, id: Int?) { @@ -604,12 +574,8 @@ extension MyListVC : ReloadSeriesFavLike{ if let isLike{ switch isLike{ case true: - MyListDataTemp.shareInstance.favListingData?.singKaraokeData?[index].isLiked = true - MyListDataTemp.shareInstance.favListingData?.singKaraokeData?[index].likesCount! += 1 karaokeCV.reloadItems(at: [IndexPath(row: index, section: 0)]) case false: - MyListDataTemp.shareInstance.favListingData?.singKaraokeData?[index].isLiked = false - MyListDataTemp.shareInstance.favListingData?.singKaraokeData?[index].likesCount! -= 1 karaokeCV.reloadItems(at: [IndexPath(row: index, section: 0)]) } } @@ -620,11 +586,30 @@ extension MyListVC : ReloadSeriesFavLike{ self.karaokeCV.reloadData() self.vm.checkNil() case false: - MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.remove(at: index) self.karaokeCV.reloadData() self.vm.checkNil() } } + case .audioBooksCV: + if let isLike{ + switch isLike{ + case true: + audioBooksCV.reloadItems(at: [IndexPath(row: index, section: 0)]) + case false: + audioBooksCV.reloadItems(at: [IndexPath(row: index, section: 0)]) + } + } + + if let isFav{ + switch isFav{ + case true: + self.audioBooksCV.reloadData() + self.vm.checkNil() + case false: + self.audioBooksCV.reloadData() + self.vm.checkNil() + } + } default: break diff --git a/WOKA/Karaoke/Controller/KaraokeDetailsVC.swift b/WOKA/Karaoke/Controller/KaraokeDetailsVC.swift index 4904b51..28c9913 100644 --- a/WOKA/Karaoke/Controller/KaraokeDetailsVC.swift +++ b/WOKA/Karaoke/Controller/KaraokeDetailsVC.swift @@ -135,9 +135,6 @@ class KaraokeDetailsVC: UIViewController { K.GVar.myListSoftReload = true } - //if coming from audio list -// self.delegate?.updateAudioRows(id: showID, type: .favourite, isFav: false, isLike: nil) - //if coming from mylist self.delegate?.updateRows(index: self.karaokeIndex, type: .favourite, isFav: false, isLike: nil, id: showID) self.initView() @@ -150,8 +147,6 @@ class KaraokeDetailsVC: UIViewController { MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.append(karaokeData) K.GVar.myListSoftReload = true } - //if coming from audio list -// self.delegate?.updateAudioRows(id: showID, type: .favourite, isFav: true, isLike: nil) //if coming from mylist self.delegate?.updateRows(index: self.karaokeIndex, type: .favourite, isFav: true, isLike: nil, id: showID) @@ -172,20 +167,21 @@ class KaraokeDetailsVC: UIViewController { if isLiked{ LikeFavCommonFunc.shareInstance.unlikePost(postID: showID, postType: postType, vc: self) { isDone in self.karaokeData?.isLiked = false + self.karaokeData?.likesCount! -= 1 if let index = MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.firstIndex(where: {$0.id == showID}){ MyListDataTemp.shareInstance.favListingData?.singKaraokeData?[index].isLiked = false MyListDataTemp.shareInstance.favListingData?.singKaraokeData?[index].likesCount! -= 1 K.GVar.myListSoftReload = true } -// self.delegate?.updateAudioRows(id: showID, type: .liked, isFav: nil, isLike: false) - self.delegate?.updateRows(index: self.karaokeIndex, type: .favourite, isFav: nil, isLike: false, id: showID) + self.delegate?.updateRows(index: self.karaokeIndex, type: .liked, isFav: nil, isLike: false, id: showID) self.initView() } }else{ LikeFavCommonFunc.shareInstance.likePost(postID: showID, postType: postType, vc: self) { isDone in self.karaokeData?.isLiked = true + self.karaokeData?.likesCount! += 1 if let index = MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.firstIndex(where: {$0.id == showID}){ MyListDataTemp.shareInstance.favListingData?.singKaraokeData?[index].isLiked = true @@ -193,9 +189,7 @@ class KaraokeDetailsVC: UIViewController { K.GVar.myListSoftReload = true } -// self.delegate?.updateAudioRows(id: showID, type: .liked, isFav: nil, isLike: true) - self.delegate?.updateRows(index: self.karaokeIndex, type: .favourite, isFav: nil, isLike: true, id: showID) - + self.delegate?.updateRows(index: self.karaokeIndex, type: .liked, isFav: nil, isLike: true, id: showID) self.initView() } } diff --git a/WOKA/Karaoke/Controller/KaraokeListingVC.swift b/WOKA/Karaoke/Controller/KaraokeListingVC.swift index 3885831..86c8acd 100644 --- a/WOKA/Karaoke/Controller/KaraokeListingVC.swift +++ b/WOKA/Karaoke/Controller/KaraokeListingVC.swift @@ -187,6 +187,8 @@ extension KaraokeListingVC : TableViewSRC{ } } +// MARK: - Protocol Listener + extension KaraokeListingVC : ReloadSeriesFavLike{ func updateRows(index: Int, type: FavCellCLick, isFav: Bool?, isLike: Bool? , id : Int?) { @@ -206,44 +208,19 @@ extension KaraokeListingVC : ReloadSeriesFavLike{ if let isLike{ if let continueDataIndex = vm.continueWatchingData.firstIndex(where:{$0.id == id}) { vm.continueWatchingData[continueDataIndex].isLiked = isLike + vm.continueWatchingData[continueDataIndex].likesCount! += isLike ? 1 : -1 continueWatchingCV.reloadItems(at: [IndexPath(row: continueDataIndex, section: 0)]) } if let audioListDataIndex = vm.karaokeListData.firstIndex(where:{$0.id == id}) { vm.karaokeListData[audioListDataIndex].isLiked = isLike + vm.karaokeListData[audioListDataIndex].likesCount! += isLike ? 1 : -1 karaokeListingTableView.reloadRows(at: [IndexPath(row: audioListDataIndex, section: 0)],with: .none) } } } - -// func updateAudioRows(id: Int, type: FavCellCLick, isFav: Bool?, isLike: Bool?) { -// if let isFav{ -// if let continueDataIndex = vm.continueWatchingData.firstIndex(where:{$0.id == id}) { -// vm.continueWatchingData[continueDataIndex].markAsFavourite = isFav -// continueWatchingCV.reloadItems(at: [IndexPath(row: continueDataIndex, section: 0)]) -// } -// -// if let audioListDataIndex = vm.karaokeListData.firstIndex(where:{$0.id == id}) { -// vm.karaokeListData[audioListDataIndex].markAsFavourite = isFav -// karaokeListingTableView.reloadRows(at: [IndexPath(row: audioListDataIndex, section: 0)],with: .none) -// } -// } -// -// if let isLike{ -// if let continueDataIndex = vm.continueWatchingData.firstIndex(where:{$0.id == id}) { -// vm.continueWatchingData[continueDataIndex].isLiked = isLike -// continueWatchingCV.reloadItems(at: [IndexPath(row: continueDataIndex, section: 0)]) -// } -// -// if let audioListDataIndex = vm.karaokeListData.firstIndex(where:{$0.id == id}) { -// vm.karaokeListData[audioListDataIndex].isLiked = isLike -// karaokeListingTableView.reloadRows(at: [IndexPath(row: audioListDataIndex, section: 0)],with: .none) -// } -// } -// } - - } + // MARK: - Animating scrollView extension KaraokeListingVC: UIScrollViewDelegate { diff --git a/WOKA/WebSeries/Controller/WebSeriesVC.swift b/WOKA/WebSeries/Controller/WebSeriesVC.swift index bcb8589..b9b65c8 100644 --- a/WOKA/WebSeries/Controller/WebSeriesVC.swift +++ b/WOKA/WebSeries/Controller/WebSeriesVC.swift @@ -137,14 +137,14 @@ extension WebSeriesVC : TableViewSRC{ // Update for mylist if let id = vm.categoryListingData[vm.dropDownModule.indexForSelectedRow ?? 0].id{ if id == 1{ // english - K.GVar.myListSoftReload = true - - + if let index = MyListDataTemp.shareInstance.favListingData?.showData?.firstIndex(where: {$0.id == postID}){ + MyListDataTemp.shareInstance.favListingData?.showData?.remove(at: index) + K.GVar.myListSoftReload = true + } }else{ // hindi if let index = MyListDataTemp.shareInstance.webSeriesHindi.firstIndex(where: {$0.id == postID}){ MyListDataTemp.shareInstance.webSeriesHindi.remove(at: index) K.GVar.myListSoftReload = true - } } } @@ -162,16 +162,14 @@ extension WebSeriesVC : TableViewSRC{ if let id = vm.categoryListingData[vm.dropDownModule.indexForSelectedRow ?? 0].id{ if id == 1{ // english K.GVar.myListSoftReload = true - - + let showData = vm.showData[index] + MyListDataTemp.shareInstance.favListingData?.showData?.append(FavouriteListingDM.ResultData.ShowDatum(id: showData.id, title: showData.title, description: showData.description, thumbnailPath: showData.thumbnailPath, showType: showData.showType, totalSeasons: showData.totalSeasons, totalEpisodes: showData.totalEpisodes, categoryMasterID: showData.categoryMasterID, ageRangeMasterID: showData.ageRangeMasterID, genderMasterID: showData.genderMasterID, contentMoreDetails: showData.contentMoreDetails, markAsFavourite: showData.markAsFavourite, isLiked: showData.isLiked, likesCount: showData.likesCount, viewsCount: showData.viewsCount, bookmarkCount: showData.bookmarkCount, bookmarkCategoryIDS: "1")) }else{ // hindi // return if the data is not fetched. IT means user has not loaded mylist yet if !MyListDataTemp.shareInstance.isDatafetched {return} let showData = vm.showData[index] - MyListDataTemp.shareInstance.webSeriesHindi.append(FavouriteListingDM.ResultData.ShowDatum(id: showData.id, title: showData.title, description: showData.description, thumbnailPath: showData.thumbnailPath, showType: showData.showType, totalSeasons: showData.totalSeasons, totalEpisodes: showData.totalEpisodes, categoryMasterID: showData.categoryMasterID, ageRangeMasterID: showData.ageRangeMasterID, genderMasterID: showData.genderMasterID, contentMoreDetails: showData.contentMoreDetails, markAsFavourite: showData.markAsFavourite, isLiked: showData.isLiked, likesCount: showData.likesCount, viewsCount: showData.viewsCount, bookmarkCount: showData.bookmarkCount, bookmarkCategoryIDS: "18")) K.GVar.myListSoftReload = true - } } @@ -261,7 +259,6 @@ extension WebSeriesVC : ReloadSeriesFavLike{ vm.showData[index].favouriteCategoryIDS = ValueWrapper.stringValue("") showListingTableView.reloadRows(at: [IndexPath(row: index, section: 0)],with: .none) } - K.GVar.reloadMyList = true } if let isLike{ @@ -275,7 +272,6 @@ extension WebSeriesVC : ReloadSeriesFavLike{ vm.showData[index].likesCount! -= 1 showListingTableView.reloadRows(at: [IndexPath(row: index, section: 0)],with: .none) } - K.GVar.reloadMyList = true } } } diff --git a/WOKA/WebSeries/ViewModel/WebSeriesSeasonVM.swift b/WOKA/WebSeries/ViewModel/WebSeriesSeasonVM.swift index 3f17c25..c0652fc 100644 --- a/WOKA/WebSeries/ViewModel/WebSeriesSeasonVM.swift +++ b/WOKA/WebSeries/ViewModel/WebSeriesSeasonVM.swift @@ -45,20 +45,42 @@ class WebSeriesSeasonVM{ guard let self ,let indexSelected, let categoryID, let showData, let showID = showData.id, let isFav = showData.markAsFavourite, let postType = showData.contentMoreDetails?.first?.postType else{return} if isFav { + //remove LikeFavCommonFunc.shareInstance.removeFavourite(postID: showID, postType: postType, categoryID: categoryID, vc: self.vc) { isDone in self.showData?.markAsFavourite = false self.showData?.favouriteCategoryIDS = ValueWrapper.stringValue("") self.setShowData() self.vc.likeFavDelegate?.updateRows(index: indexSelected, type: .favourite, isFav: false, isLike: nil, id: showID) - K.GVar.reloadMyList = true + + if self.categoryID == 18{ // hindi + if let index = MyListDataTemp.shareInstance.webSeriesHindi.firstIndex(where: {$0.id == showID}){ + MyListDataTemp.shareInstance.webSeriesHindi.remove(at: index) + K.GVar.myListSoftReload = true + } + }else{ // english + if let index = MyListDataTemp.shareInstance.favListingData?.showData?.firstIndex(where: {$0.id == showID}){ + MyListDataTemp.shareInstance.favListingData?.showData?.remove(at: index) + K.GVar.myListSoftReload = true + } + } } }else{ + //add LikeFavCommonFunc.shareInstance.addFavourite(postID: showID, postType: postType, categoryID: categoryID, vc: self.vc) { isDone in self.showData?.markAsFavourite = true self.showData?.favouriteCategoryIDS = ValueWrapper.stringValue(categoryID.toString()) self.setShowData() self.vc.likeFavDelegate?.updateRows(index: indexSelected, type: .favourite, isFav: true, isLike: nil, id: showID) - K.GVar.reloadMyList = true + + if self.categoryID == 18{ // hindi + guard let showData = self.showData else{return} + MyListDataTemp.shareInstance.webSeriesHindi.append(FavouriteListingDM.ResultData.ShowDatum(id: showData.id, title: showData.title, description: showData.description, thumbnailPath: showData.thumbnailPath, showType: showData.showType, totalSeasons: showData.totalSeasons, totalEpisodes: showData.totalEpisodes, categoryMasterID: showData.categoryMasterID, ageRangeMasterID: showData.ageRangeMasterID, genderMasterID: showData.genderMasterID, contentMoreDetails: showData.contentMoreDetails, markAsFavourite: showData.markAsFavourite, isLiked: showData.isLiked, likesCount: showData.likesCount, viewsCount: showData.viewsCount, bookmarkCount: showData.bookmarkCount, bookmarkCategoryIDS: "18")) + K.GVar.myListSoftReload = true + }else{ // english + guard let showData = self.showData else{return} + MyListDataTemp.shareInstance.webSeriesHindi.append(FavouriteListingDM.ResultData.ShowDatum(id: showData.id, title: showData.title, description: showData.description, thumbnailPath: showData.thumbnailPath, showType: showData.showType, totalSeasons: showData.totalSeasons, totalEpisodes: showData.totalEpisodes, categoryMasterID: showData.categoryMasterID, ageRangeMasterID: showData.ageRangeMasterID, genderMasterID: showData.genderMasterID, contentMoreDetails: showData.contentMoreDetails, markAsFavourite: showData.markAsFavourite, isLiked: showData.isLiked, likesCount: showData.likesCount, viewsCount: showData.viewsCount, bookmarkCount: showData.bookmarkCount, bookmarkCategoryIDS: "1")) + K.GVar.myListSoftReload = true + } } } } @@ -74,6 +96,20 @@ class WebSeriesSeasonVM{ self.showData?.likesCount! -= 1 self.setShowData() self.vc.likeFavDelegate?.updateRows(index: indexSelected, type: .liked, isFav: nil, isLike: false, id: showID) + + if self.categoryID == 18{ // hindi + if let index = MyListDataTemp.shareInstance.webSeriesHindi.firstIndex(where: {$0.id == showID}){ + MyListDataTemp.shareInstance.webSeriesHindi[index].isLiked = false + MyListDataTemp.shareInstance.webSeriesHindi[index].likesCount! -= 1 + K.GVar.myListSoftReload = true + } + }else{ // english + if let index = MyListDataTemp.shareInstance.favListingData?.showData?.firstIndex(where: {$0.id == showID}){ + MyListDataTemp.shareInstance.favListingData?.showData?[index].isLiked = false + MyListDataTemp.shareInstance.favListingData?.showData?[index].likesCount! -= 1 + K.GVar.myListSoftReload = true + } + } } }else{ LikeFavCommonFunc.shareInstance.likePost(postID: showID, postType: postType, vc: self.vc) { isDone in @@ -81,6 +117,20 @@ class WebSeriesSeasonVM{ self.showData?.likesCount! += 1 self.setShowData() self.vc.likeFavDelegate?.updateRows(index: indexSelected, type: .liked, isFav: nil, isLike: true, id: showID) + + if self.categoryID == 18{ // hindi + if let index = MyListDataTemp.shareInstance.webSeriesHindi.firstIndex(where: {$0.id == showID}){ + MyListDataTemp.shareInstance.webSeriesHindi[index].isLiked = true + MyListDataTemp.shareInstance.webSeriesHindi[index].likesCount! += 1 + K.GVar.myListSoftReload = true + } + }else{ // english + if let index = MyListDataTemp.shareInstance.favListingData?.showData?.firstIndex(where: {$0.id == showID}){ + MyListDataTemp.shareInstance.favListingData?.showData?[index].isLiked = true + MyListDataTemp.shareInstance.favListingData?.showData?[index].likesCount! += 1 + K.GVar.myListSoftReload = true + } + } } } }