From 1eb7727aa2261300b445c17c51b11ec080b6d700 Mon Sep 17 00:00:00 2001 From: Bilal Date: Fri, 9 Aug 2024 21:04:55 +0530 Subject: [PATCH] - 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 --- WOKA.xcodeproj/project.pbxproj | 20 +- WOKA/Audio Books/AudioBookHomeVC.swift | 3 +- WOKA/Audio Books/AudioBookHomeVM.swift | 57 +-- WOKA/Games/ViewModel/GamesListVM.swift | 46 ++- WOKA/Home/Controller/MyListVC.swift | 40 +- WOKA/Home/Controller/MyListViewAllVC.swift | 66 +++- WOKA/Home/Home.storyboard | 262 ++++++++++--- WOKA/Home/Model/FavouriteListingDM.swift | 3 + WOKA/Home/View/FavouriteCell.xib | 13 +- WOKA/Home/View/MyListViewAllCell.swift | 92 +++++ WOKA/Home/View/MyListViewAllCell.xib | 11 +- WOKA/Home/ViewModel/MyListVM.swift | 33 +- WOKA/Home/ViewModel/MyListViewAllVM.swift | 176 ++++++--- WOKA/Karaoke/Controller/AVAssetMods.swift | 21 +- .../Controller/JWKaraokePlayerVC.swift | 371 ++---------------- .../Karaoke/Controller/KaraokeDetailsVC.swift | 27 +- WOKA/Karaoke/Karaoke.storyboard | 29 +- WOKA/Karaoke/Model/KaraokeListingDM.swift | 4 +- .../Karaoke/ViewModel/JWKaraokePlayerVM.swift | 279 +++++++++++++ WOKA/Karaoke/ViewModel/KaraokeListingVM.swift | 69 ++-- .../Controller/MyOrderDetailsVC.swift | 17 +- WOKA/SideBarNav/Controller/MyOrdersVC.swift | 20 +- WOKA/SideBarNav/SideBarNav.storyboard | 49 ++- WOKA/SideBarNav/View/MyOrderCell.swift | 6 + WOKA/SideBarNav/ViewModel/MyOrdersVM.swift | 101 ++++- WOKA/Theme/Controller/MoreVC.swift | 6 +- WOKA/Theme/Controller/PlayerVC.swift | 67 +++- WOKA/Theme/Controller/ThemeOneVC.swift | 16 +- WOKA/Theme/Controller/ThemeTwoVC.swift | 2 +- WOKA/Theme/View/SongListCell.xib | 29 +- WOKA/Theme/ViewModel/MoreVM.swift | 2 +- WOKA/Theme/ViewModel/ThemeOneVM.swift | 12 +- WOKA/WebSeries/JWPlayerManager.swift | 30 +- 33 files changed, 1284 insertions(+), 695 deletions(-) create mode 100644 WOKA/Karaoke/ViewModel/JWKaraokePlayerVM.swift diff --git a/WOKA.xcodeproj/project.pbxproj b/WOKA.xcodeproj/project.pbxproj index 342756e..86a86a5 100644 --- a/WOKA.xcodeproj/project.pbxproj +++ b/WOKA.xcodeproj/project.pbxproj @@ -147,7 +147,6 @@ 52ACC1252C610CBC00791528 /* UserClicks+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52ACC1232C610CBC00791528 /* UserClicks+CoreDataClass.swift */; }; 52ACC1262C610CBC00791528 /* UserClicks+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52ACC1242C610CBC00791528 /* UserClicks+CoreDataProperties.swift */; }; 52ACC12A2C610EC900791528 /* PersistentStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52ACC1292C610EC900791528 /* PersistentStorage.swift */; }; - 52ACC12D2C63479300791528 /* WOKA.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 52ACC12B2C63479300791528 /* WOKA.xcdatamodeld */; }; 52ACC1302C639DBA00791528 /* MyOrderCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52ACC12E2C639DBA00791528 /* MyOrderCell.swift */; }; 52ACC1312C639DBA00791528 /* MyOrderCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 52ACC12F2C639DBA00791528 /* MyOrderCell.xib */; }; 52ACC1332C639F3800791528 /* OrderListingDM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52ACC1322C639F3800791528 /* OrderListingDM.swift */; }; @@ -308,6 +307,8 @@ 9C85A9F32C5CE1060031C365 /* FirebasePerformance in Frameworks */ = {isa = PBXBuildFile; productRef = 9C85A9F22C5CE1060031C365 /* FirebasePerformance */; }; 9C8C4FAE2C1315410017DD3B /* WebViewVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C8C4FAD2C1315410017DD3B /* WebViewVC.swift */; }; 9C8C4FB02C1328060017DD3B /* Disclaimer.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 9C8C4FAF2C1328060017DD3B /* Disclaimer.rtf */; }; + 9C9BE46C2C65DF2A00C48D6A /* WOKA.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 9C9BE46A2C65DF2A00C48D6A /* WOKA.xcdatamodeld */; }; + 9C9BE46E2C663B1600C48D6A /* JWKaraokePlayerVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C9BE46D2C663B1600C48D6A /* JWKaraokePlayerVM.swift */; }; 9C9BEEC72BEE1BBF004ECC2F /* CollectionViewCenteredFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C9BEEC62BEE1BBF004ECC2F /* CollectionViewCenteredFlowLayout.swift */; }; 9CA7C6C02C1093E500D73742 /* ProfileVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CA7C6BF2C1093E500D73742 /* ProfileVC.swift */; }; 9CA7C6C22C1095B600D73742 /* ProfileVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CA7C6C12C1095B600D73742 /* ProfileVM.swift */; }; @@ -511,7 +512,6 @@ 52ACC1232C610CBC00791528 /* UserClicks+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserClicks+CoreDataClass.swift"; sourceTree = SOURCE_ROOT; }; 52ACC1242C610CBC00791528 /* UserClicks+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserClicks+CoreDataProperties.swift"; sourceTree = SOURCE_ROOT; }; 52ACC1292C610EC900791528 /* PersistentStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistentStorage.swift; sourceTree = ""; }; - 52ACC12C2C63479300791528 /* WOKA.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = WOKA.xcdatamodel; sourceTree = ""; }; 52ACC12E2C639DBA00791528 /* MyOrderCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyOrderCell.swift; sourceTree = ""; }; 52ACC12F2C639DBA00791528 /* MyOrderCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MyOrderCell.xib; sourceTree = ""; }; 52ACC1322C639F3800791528 /* OrderListingDM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderListingDM.swift; sourceTree = ""; }; @@ -662,6 +662,8 @@ 9C85A9EB2C5CD5CD0031C365 /* MyListDataTemp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyListDataTemp.swift; sourceTree = ""; }; 9C8C4FAD2C1315410017DD3B /* WebViewVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewVC.swift; sourceTree = ""; }; 9C8C4FAF2C1328060017DD3B /* Disclaimer.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Disclaimer.rtf; sourceTree = ""; }; + 9C9BE46B2C65DF2A00C48D6A /* WOKA.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = WOKA.xcdatamodel; sourceTree = ""; }; + 9C9BE46D2C663B1600C48D6A /* JWKaraokePlayerVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JWKaraokePlayerVM.swift; sourceTree = ""; }; 9C9BEEC62BEE1BBF004ECC2F /* CollectionViewCenteredFlowLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewCenteredFlowLayout.swift; sourceTree = ""; }; 9CA7C6BF2C1093E500D73742 /* ProfileVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileVC.swift; sourceTree = ""; }; 9CA7C6C12C1095B600D73742 /* ProfileVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileVM.swift; sourceTree = ""; }; @@ -886,7 +888,7 @@ 9C535DC82C00C34000DA6DCD /* Theme */, 52DAC6462C21761700E2F85B /* WebSeries */, 9C834ED92C1C20EC00B29A9C /* WOKA.entitlements */, - 52ACC12B2C63479300791528 /* WOKA.xcdatamodeld */, + 9C9BE46A2C65DF2A00C48D6A /* WOKA.xcdatamodeld */, 52ACC1292C610EC900791528 /* PersistentStorage.swift */, ); path = WOKA; @@ -1801,6 +1803,7 @@ isa = PBXGroup; children = ( 9CB3D08C2C37CDD50062869D /* KaraokeListingVM.swift */, + 9C9BE46D2C663B1600C48D6A /* JWKaraokePlayerVM.swift */, ); path = ViewModel; sourceTree = ""; @@ -2270,7 +2273,6 @@ 52A6DCBC2C4EA46400F63C51 /* ShopProductsCell.swift in Sources */, 528BEF602C2C372900FFDAB8 /* ContinueWatchingVC.swift in Sources */, 9CBCB29B2BE4D614007D7934 /* LoginVC.swift in Sources */, - 52ACC12D2C63479300791528 /* WOKA.xcdatamodeld in Sources */, 52BC3BE82C0E04A9002FACA6 /* FaqListDM.swift in Sources */, 9C56E83B2BDBC6E600E4CA14 /* SelectAgeVM.swift in Sources */, 9C535DC02C00B36000DA6DCD /* HomeVC.swift in Sources */, @@ -2377,6 +2379,7 @@ 52C8B05F2BDA5AFA003B51D0 /* SplashVM.swift in Sources */, 52C1A4E12C05B69F007BAA50 /* UIApplicationSwitchRoot.swift in Sources */, 527A2BCC2C577F8A0080DF9B /* AnalyticsEventKeys.swift in Sources */, + 9C9BE46C2C65DF2A00C48D6A /* WOKA.xcdatamodeld in Sources */, 52663FF72BDFACF60001D8CE /* ShadowView.swift in Sources */, 522D65602C1ACD8D0021E505 /* UserNotificationVC.swift in Sources */, 52AC2D252C295A7900337473 /* TeaserDM.swift in Sources */, @@ -2385,6 +2388,7 @@ 9CB3D0912C37D6930062869D /* KaraokeDetailsVC.swift in Sources */, 52E214C72C2AD47F00BC2D29 /* EpisodeDetailsVC.swift in Sources */, 52D774F12BDFC53B001D87DE /* StringSubScript.swift in Sources */, + 9C9BE46E2C663B1600C48D6A /* JWKaraokePlayerVM.swift in Sources */, 9CBE1B3F2C0F37B300CA6E61 /* DPDConstants.swift in Sources */, 9CDAEB102C53F12800890C47 /* SwiftyInnerShadowLayer.swift in Sources */, 52A6DCA42C4E48AF00F63C51 /* ShopSuperCategoryDM.swift in Sources */, @@ -2875,14 +2879,14 @@ /* End XCSwiftPackageProductDependency section */ /* Begin XCVersionGroup section */ - 52ACC12B2C63479300791528 /* WOKA.xcdatamodeld */ = { + 9C9BE46A2C65DF2A00C48D6A /* WOKA.xcdatamodeld */ = { isa = XCVersionGroup; children = ( - 52ACC12C2C63479300791528 /* WOKA.xcdatamodel */, + 9C9BE46B2C65DF2A00C48D6A /* WOKA.xcdatamodel */, ); - currentVersion = 52ACC12C2C63479300791528 /* WOKA.xcdatamodel */; + currentVersion = 9C9BE46B2C65DF2A00C48D6A /* WOKA.xcdatamodel */; name = WOKA.xcdatamodeld; - path = /Users/macbookpro/Desktop/WOKA/WOKA/WOKA.xcdatamodeld; + path = /Users/bilal/Desktop/woka_native_ios_swift/WOKA/WOKA.xcdatamodeld; sourceTree = ""; versionGroupType = wrapper.xcdatamodel; }; diff --git a/WOKA/Audio Books/AudioBookHomeVC.swift b/WOKA/Audio Books/AudioBookHomeVC.swift index cfaeea3..b031bc6 100644 --- a/WOKA/Audio Books/AudioBookHomeVC.swift +++ b/WOKA/Audio Books/AudioBookHomeVC.swift @@ -151,7 +151,8 @@ extension AudioBookHomeVC : TableViewSRC{ cell.stopShimmer() } - cell.btnTapped = { [self] (type) -> Void in + cell.btnTapped = { [weak self] (type) -> Void in + guard let self else{return} let data = vm.audioListData[indexPath.row] guard let postID = data.id ,let postType = data.contentMoreDetails?.first?.postType else{return} let isFav = data.markAsFavourite diff --git a/WOKA/Audio Books/AudioBookHomeVM.swift b/WOKA/Audio Books/AudioBookHomeVM.swift index f66d964..dfd73a1 100644 --- a/WOKA/Audio Books/AudioBookHomeVM.swift +++ b/WOKA/Audio Books/AudioBookHomeVM.swift @@ -195,13 +195,14 @@ class AudioBookHomeVM{ audioListData[showListIndex].markAsFavourite = false vc.audioListingTableView.reloadRows(at: [IndexPath(row: showListIndex, section: 0)],with: .none) - // MyList Update - if MyListDataTemp.shareInstance.isDatafetched{ - if let indexRemove = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == postID}){ - MyListDataTemp.shareInstance.favListingData?.audioData?.remove(at: indexRemove) - K.GVar.myListSoftReload = true - } - } + K.GVar.reloadMyList = true +// // MyList Update +// if MyListDataTemp.shareInstance.isDatafetched{ +// if let indexRemove = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == postID}){ +// MyListDataTemp.shareInstance.favListingData?.audioData?.remove(at: indexRemove) +// K.GVar.myListSoftReload = true +// } +// } } /* @@ -210,14 +211,14 @@ class AudioBookHomeVM{ if let continueWatchingIndex = continueWatchingData.firstIndex(where: { $0.id == postID }){ continueWatchingData[continueWatchingIndex].markAsFavourite = false vc.continueWatchingCV.reloadItems(at: [IndexPath(row: continueWatchingIndex, section: 0)]) - + K.GVar.reloadMyList = true // MyList Update - if MyListDataTemp.shareInstance.isDatafetched{ - if let indexRemove = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == postID}){ - MyListDataTemp.shareInstance.favListingData?.audioData?.remove(at: indexRemove) - K.GVar.myListSoftReload = true - } - } +// if MyListDataTemp.shareInstance.isDatafetched{ +// if let indexRemove = MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == postID}){ +// MyListDataTemp.shareInstance.favListingData?.audioData?.remove(at: indexRemove) +// K.GVar.myListSoftReload = true +// } +// } } } } @@ -227,13 +228,13 @@ class AudioBookHomeVM{ if let showListIndex = audioListData.firstIndex(where: { $0.id == postID }){ audioListData[showListIndex].markAsFavourite = true vc.audioListingTableView.reloadRows(at: [IndexPath(row: showListIndex, section: 0)],with: .none) - + K.GVar.reloadMyList = true // MyList Update - if MyListDataTemp.shareInstance.isDatafetched{ - let audioData = audioListData[showListIndex] - MyListDataTemp.shareInstance.favListingData?.audioData?.append(audioData) - K.GVar.myListSoftReload = true - } +// if MyListDataTemp.shareInstance.isDatafetched{ +// let audioData = audioListData[showListIndex] +// MyListDataTemp.shareInstance.favListingData?.audioData?.append(audioData) +// K.GVar.myListSoftReload = true +// } } /* @@ -242,15 +243,15 @@ class AudioBookHomeVM{ if let continueWatchingIndex = continueWatchingData.firstIndex(where: { $0.id == postID }){ continueWatchingData[continueWatchingIndex].markAsFavourite = true vc.continueWatchingCV.reloadItems(at: [IndexPath(row: continueWatchingIndex, section: 0)]) - + K.GVar.reloadMyList = true // MyList Update - if MyListDataTemp.shareInstance.isDatafetched{ - if MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == postID}) == nil{ - let audioData = continueWatchingData[continueWatchingIndex] - MyListDataTemp.shareInstance.favListingData?.audioData?.append(audioData) - K.GVar.myListSoftReload = true - } - } +// if MyListDataTemp.shareInstance.isDatafetched{ +// if MyListDataTemp.shareInstance.favListingData?.audioData?.firstIndex(where: {$0.id == postID}) == nil{ +// let audioData = continueWatchingData[continueWatchingIndex] +// MyListDataTemp.shareInstance.favListingData?.audioData?.append(audioData) +// K.GVar.myListSoftReload = true +// } +// } } } diff --git a/WOKA/Games/ViewModel/GamesListVM.swift b/WOKA/Games/ViewModel/GamesListVM.swift index 40b3a8f..ae74cc9 100644 --- a/WOKA/Games/ViewModel/GamesListVM.swift +++ b/WOKA/Games/ViewModel/GamesListVM.swift @@ -13,9 +13,7 @@ class GamesListVM{ weak var vc : GamesListVC! var gameData = [GamesListDM.GameDatum]() var indexToLoad = 0 - var pageNo = 0 - var stopFetch = false func initView(){ setupCell() @@ -91,7 +89,7 @@ class GamesListVM{ // vc.toast(msg: data.message ?? "Unrecognised error" , time: 2) case 1: Utilities.dismissProgressHUD() - guard let data = data.data?.gameData else{return} + guard let dataCount = data.data?.totalRecords, let data = data.data?.gameData else{return} self.gameData.append(contentsOf: data) self.vc.gamesListingTableView.reloadData() self.vc.tableHeight.constant = self.vc.gamesListingTableView.contentSize.height + 100 @@ -107,13 +105,19 @@ class GamesListVM{ self.vc.loadMoreActivityIndicator.stopAnimating() self.vc.loadMoreActivityIndicator.hidesWhenStopped = true - if self.gameData.count.isMultiple(of: 5) && !self.stopFetch{ - // if not multiple of 10, means more data can be there, show more btn - self.vc.loadMoreBtn.isHidden = false - }else{ - self.stopFetch = true + if self.gameData.count == dataCount{ self.vc.loadMoreBtn.isHidden = true + }else{ + self.vc.loadMoreBtn.isHidden = false } + +// if self.gameData.count.isMultiple(of: 5) && !self.stopFetch{ +// // if not multiple of 10, means more data can be there, show more btn +// self.vc.loadMoreBtn.isHidden = false +// }else{ +// self.stopFetch = true +// self.vc.loadMoreBtn.isHidden = true +// } default: break } @@ -144,14 +148,14 @@ class GamesListVM{ if isDone{ gameData[index].markAsFavourite = false vc.gamesListingTableView.reloadRows(at: [IndexPath(row: index, section: 0)],with: .none) - + K.GVar.reloadMyList = true // MyList Update - if MyListDataTemp.shareInstance.isDatafetched{ - if let indexRemove = MyListDataTemp.shareInstance.favListingData?.gameData?.firstIndex(where: {$0.id == postID}){ - MyListDataTemp.shareInstance.favListingData?.gameData?.remove(at: indexRemove) - K.GVar.myListSoftReload = true - } - } +// if MyListDataTemp.shareInstance.isDatafetched{ +// if let indexRemove = MyListDataTemp.shareInstance.favListingData?.gameData?.firstIndex(where: {$0.id == postID}){ +// MyListDataTemp.shareInstance.favListingData?.gameData?.remove(at: indexRemove) +// K.GVar.myListSoftReload = true +// } +// } } } }else{ @@ -159,13 +163,13 @@ class GamesListVM{ if isDone{ gameData[index].markAsFavourite = true vc.gamesListingTableView.reloadRows(at: [IndexPath(row: index, section: 0)],with: .none) - + K.GVar.reloadMyList = true // MyList Update - if MyListDataTemp.shareInstance.isDatafetched{ - let gameData = gameData[index] - MyListDataTemp.shareInstance.favListingData?.gameData?.append(gameData) - K.GVar.myListSoftReload = true - } +// if MyListDataTemp.shareInstance.isDatafetched{ +// let gameData = gameData[index] +// MyListDataTemp.shareInstance.favListingData?.gameData?.append(gameData) +// K.GVar.myListSoftReload = true +// } } } } diff --git a/WOKA/Home/Controller/MyListVC.swift b/WOKA/Home/Controller/MyListVC.swift index e1f4a42..057b0eb 100644 --- a/WOKA/Home/Controller/MyListVC.swift +++ b/WOKA/Home/Controller/MyListVC.swift @@ -31,7 +31,10 @@ class MyListVC: UIViewController{ @IBOutlet weak var guestLoginView: UIView! @IBOutlet weak var guestLoginStack: UIStackView! - @IBOutlet weak var WebSeriesBtn: LocalisedElementsButton! + @IBOutlet weak var webSeriesBtn: LocalisedElementsButton! + @IBOutlet weak var webSeriesHindiBtn: LocalisedElementsButton! + @IBOutlet weak var audioBooksBtn: LocalisedElementsButton! + @IBOutlet weak var gamesBtn: LocalisedElementsButton! @IBOutlet weak var karaokeViewBtn: LocalisedElementsButton! var vm = MyListVM() @@ -72,17 +75,18 @@ class MyListVC: UIViewController{ override func viewDidAppear(_ animated: Bool) { K.GVar.topView = .myList + if K.GVar.reloadMyList{ + K.GVar.reloadMyList = false + K.GVar.myListSoftReload = false + Utilities.startProgressHUD() + vm.getFavouriteListing() + } + if K.GVar.myListSoftReload{ vm.reloadCollections() vm.checkNil() K.GVar.myListSoftReload = false } - - if K.GVar.reloadMyList{ - K.GVar.reloadMyList = false - Utilities.startProgressHUD() - vm.getFavouriteListing() - } } @IBAction func sideBarBtnTapped(_ sender: UIButton) { @@ -99,11 +103,33 @@ class MyListVC: UIViewController{ @IBAction func viewAllBtnTapped(_ sender: UIButton) { switch sender{ + case webSeriesHindiBtn: + let sb = UIStoryboard(name: K.StoryBoard.home, bundle: nil) + let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Home.MyListViewAllVC) as! MyListViewAllVC + vcPush.vm.postType = 1 + vcPush.vm.catID = "18" + self.navigationController?.pushViewController(vcPush, animated: true) + case webSeriesBtn: + let sb = UIStoryboard(name: K.StoryBoard.home, bundle: nil) + let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Home.MyListViewAllVC) as! MyListViewAllVC + vcPush.vm.postType = 1 + vcPush.vm.catID = "1" + self.navigationController?.pushViewController(vcPush, animated: true) case karaokeViewBtn: let sb = UIStoryboard(name: K.StoryBoard.home, bundle: nil) let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Home.MyListViewAllVC) as! MyListViewAllVC vcPush.vm.postType = 8 self.navigationController?.pushViewController(vcPush, animated: true) + case audioBooksBtn: + let sb = UIStoryboard(name: K.StoryBoard.home, bundle: nil) + let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Home.MyListViewAllVC) as! MyListViewAllVC + vcPush.vm.postType = 7 + self.navigationController?.pushViewController(vcPush, animated: true) + case gamesBtn: + let sb = UIStoryboard(name: K.StoryBoard.home, bundle: nil) + let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Home.MyListViewAllVC) as! MyListViewAllVC + vcPush.vm.postType = 6 + self.navigationController?.pushViewController(vcPush, animated: true) default: break } diff --git a/WOKA/Home/Controller/MyListViewAllVC.swift b/WOKA/Home/Controller/MyListViewAllVC.swift index 8c0dd4c..c6df38e 100644 --- a/WOKA/Home/Controller/MyListViewAllVC.swift +++ b/WOKA/Home/Controller/MyListViewAllVC.swift @@ -10,6 +10,11 @@ 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() @@ -44,6 +49,12 @@ class MyListViewAllVC: UIViewController { self.navigationController?.setColor(color: .black) } + @IBAction func loadMoreBtnTapped(_ sender: LocalisedElementsButton) { + loadMoreBtn.isHidden = true + vm.pageNo += 1 + loadMoreActivityIndicator.startAnimating() + vm.getFavouriteListing() + } } // MARK: - TableView DataSource , Delegates @@ -52,7 +63,11 @@ extension MyListViewAllVC : TableViewSRC{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch vm.postType{ case 1: // webSeries - return 0 + 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: @@ -60,15 +75,60 @@ extension MyListViewAllVC : TableViewSRC{ } } + 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 220 + 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 - break + 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) diff --git a/WOKA/Home/Home.storyboard b/WOKA/Home/Home.storyboard index 1581908..f8069b0 100644 --- a/WOKA/Home/Home.storyboard +++ b/WOKA/Home/Home.storyboard @@ -892,24 +892,93 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + + + + @@ -1006,7 +1075,7 @@ - + @@ -1015,7 +1084,7 @@ + @@ -1057,22 +1130,43 @@ - + - - + + + - + - + @@ -1088,22 +1182,43 @@ - + - - + + + - + - + @@ -1119,45 +1234,40 @@ - + - + - - - - - - - + + - + @@ -1176,22 +1286,43 @@ - + - - + + + - + - + @@ -1207,7 +1338,7 @@ - + @@ -1365,9 +1496,10 @@ - + + @@ -1378,8 +1510,10 @@ + + diff --git a/WOKA/Home/Model/FavouriteListingDM.swift b/WOKA/Home/Model/FavouriteListingDM.swift index fe67486..b4e4b44 100644 --- a/WOKA/Home/Model/FavouriteListingDM.swift +++ b/WOKA/Home/Model/FavouriteListingDM.swift @@ -13,17 +13,20 @@ struct FavouriteListingDM: Codable { // MARK: - Result struct ResultData: Codable { + let totalRecords: Int? var showData: [ShowDatum]? var videoData: [Datum]? var gameData: [GamesListDM.GameDatum]? var singKaraokeData : [KaraokeListingDM.KaraokeDatum]? var audioData : [ListenAudioListingDM.AudioDatum]? + enum CodingKeys: String, CodingKey { case showData = "show_data" case videoData = "video_data" case gameData = "game_data" case audioData = "audio_data" case singKaraokeData = "sing_karaoke_data" + case totalRecords = "total_records" } // MARK: - Datum diff --git a/WOKA/Home/View/FavouriteCell.xib b/WOKA/Home/View/FavouriteCell.xib index 625ab90..dee9644 100644 --- a/WOKA/Home/View/FavouriteCell.xib +++ b/WOKA/Home/View/FavouriteCell.xib @@ -42,19 +42,17 @@ - - + @@ -642,7 +664,6 @@ - @@ -664,7 +685,6 @@ - @@ -684,7 +704,6 @@ - @@ -709,8 +728,9 @@ + - + @@ -725,6 +745,7 @@ + diff --git a/WOKA/Karaoke/Model/KaraokeListingDM.swift b/WOKA/Karaoke/Model/KaraokeListingDM.swift index efeb4fd..d3fab7b 100644 --- a/WOKA/Karaoke/Model/KaraokeListingDM.swift +++ b/WOKA/Karaoke/Model/KaraokeListingDM.swift @@ -59,7 +59,8 @@ struct KaraokeListingDM: Codable { let title, description: String? let url: String? let tagsKeywords: String? - + let videoUrlHd : String? + enum CodingKeys: String, CodingKey { case id case contentID = "content_id" @@ -67,6 +68,7 @@ struct KaraokeListingDM: Codable { case languageMasterID = "language_master_id" case title, description, url case tagsKeywords = "tags_keywords" + case videoUrlHd = "video_url_hd" } } } diff --git a/WOKA/Karaoke/ViewModel/JWKaraokePlayerVM.swift b/WOKA/Karaoke/ViewModel/JWKaraokePlayerVM.swift new file mode 100644 index 0000000..b92e957 --- /dev/null +++ b/WOKA/Karaoke/ViewModel/JWKaraokePlayerVM.swift @@ -0,0 +1,279 @@ +// +// JWKaraokePlayerVM.swift +// WOKA +// +// Created by Bilal on 09/08/2024. +// + +import UIKit +import AVFAudio +import AVFoundation + +class JWKaraokePlayerVM{ + + weak var vc : JWKaraokePlayerVC! + var mixedAudioURL: URL? + var audioURLFromMP4 : URL? + var recordedAudioURL: URL? + var audioRecorder: AVAudioRecorder? + var videoTitle : String? + var videoUrl : String? + + //Start and end time for trimming the audio + var startTime : TimeInterval? + var endTime : TimeInterval? + + func initView(){ + vc.downloadRecordingBtn.isEnabled = false + hideShowKaraoke(isLoading: true) + } + + // MARK: - Document Directory Save & Fetch audio for recording + + func saveToFilesApp() { + guard let mixedAudioURL = mixedAudioURL else { return } + DispatchQueue.main.async { + let documentPicker = UIDocumentPickerViewController(url: mixedAudioURL, in: .exportToService) + documentPicker.delegate = self.vc + self.vc.present(documentPicker, animated: true, completion: nil) + } + } + + func setupKaraoke(){ + guard let videoUrl else{return} + let avURL = URL(string: videoUrl)! + let asset = AVAsset(url: avURL) + hideShowKaraoke(isLoading: true) + let outputURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("\(videoTitle?.trimmingCharacters(in: .whitespaces) ?? "extractedAudio").m4a") + FileManager.default.clearTmpDirectory() + asset.writeAudioTrackToURL(outputURL) { [weak self] isDone, error,url in + guard let self else{return} + print(isDone, error , url) + DispatchQueue.main.async { + if error == nil && isDone{ + self.hideShowKaraoke(isLoading: false) + self.audioURLFromMP4 = url + self.setupAudio() + }else{ + print("errrrrr", error) + self.vc.karaokeLoading.stopAnimating() + self.vc.karaokeStack.isHidden = true + self.vc.startStopRecordingStack.isHidden = true + + self.vc.retryKaraokeBtn.isHidden = false + } + } + } + } + + func hideShowKaraoke(isLoading : Bool){ + DispatchQueue.main.async { [weak self] in + guard let self else{return} + if isLoading{ + vc.karaokeLoading.startAnimating() + vc.karaokeStack.isHidden = false + vc.startStopRecordingStack.isHidden = true + }else{ + vc.karaokeLoading.stopAnimating() + vc.karaokeLoading.hidesWhenStopped = true + vc.karaokeStack.isHidden = true + vc.startStopRecordingStack.isHidden = false + } + } + } + + // MARK: - AudioRecording + + func setupAudio() { +// FileManager.default.clearTmpDirectory() + + let audioSession = AVAudioSession.sharedInstance() + do { + try audioSession.setCategory(.playAndRecord, mode: .default,options: .defaultToSpeaker) + try audioSession.setActive(true) + +// // URL of the downloaded M4A file +// guard let audioURL = Bundle.main.url(forResource: "Sample_audio", withExtension: "m4a") else { +// print("Audio file not found.") +// return +// } + + // Initialize AVAudioPlayer with the downloaded M4A file +// player = try AVAudioPlayer(contentsOf: audioURLFromMP4!) +// player?.prepareToPlay() + + // Define settings for the audio recorder + let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! + let outputURL = documentsDirectory.appendingPathComponent("recordedAudio.m4a") + let settings: [String: Any] = [ + AVFormatIDKey: kAudioFormatMPEG4AAC, + AVSampleRateKey: 44100, + AVNumberOfChannelsKey: 2, + AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue + ] + + // Initialize AVAudioRecorder with the output URL and settings + audioRecorder = try AVAudioRecorder(url: outputURL, settings: settings) + audioRecorder?.prepareToRecord() + recordedAudioURL = outputURL // Store the recorded audio URL + } catch { + print("Error setting up audio: \(error.localizedDescription)") + } + } + + func startRecording() { + startTime = vc.player.time.position.round(to: 1) + vc.interfaceBehavior = .hidden + guard let audioRecorder = audioRecorder else { return } + audioRecorder.record() + } + + func stopRecording() { + endTime = vc.player.time.position.round(to: 1) + vc.interfaceBehavior = .normal + guard let audioRecorder = audioRecorder else { return } + audioRecorder.stop() + vc.player.pause() + // Mix the recorded audio with the downloaded M4A file + guard let startTime , let endTime else{return} + mixAudio(start: startTime, stop: endTime) + } + + func playMixedAudio() { + guard let mixedAudioURL = mixedAudioURL else { return } + + do { + let documentsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! + let destinationURL = documentsDirectoryURL.appendingPathComponent("xyze.m4a") + + // Check if file already exists + if FileManager.default.fileExists(atPath: destinationURL.path) { + // Delete the existing file + try FileManager.default.removeItem(at: destinationURL) + } + + // Copy the new file + try FileManager.default.copyItem(at: mixedAudioURL, to: destinationURL) + + // Play the audio + let playerKAraoke = AVPlayer(url: destinationURL) + + // Adding a completion handler to check if the player starts playing + let playerObserver = playerKAraoke.addPeriodicTimeObserver(forInterval: CMTime(seconds: 1, preferredTimescale: 1), queue: .main) { time in + print("Playing audio at time: \(time.seconds)") + } + + // Observing when playback finishes + NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: playerKAraoke.currentItem, queue: .main) { [weak self] _ in + print("Audio finished playing") + guard let self else{return} + self.vc.playBtn.setTitle("Play", for: .normal) + self.vc.playBtn.setImage(UIImage(named: "PlayButtonSmall"), for: .normal) + + // Disable Recording while playing, hide controls for jwplayer + self.vc.interfaceBehavior = .normal + self.vc.startRecordBtn.isEnabled = true + self.vc.downloadRecordingBtn.isEnabled = true + // Remove observer + playerKAraoke.removeTimeObserver(playerObserver) + } + + playerKAraoke.volume = 1.0 + playerKAraoke.play() + print("Audio is playing...") + // Uncomment this block if you need to configure the audio session and play using AVAudioPlayer + /* + // Configure the audio session + let audioSession = AVAudioSession.sharedInstance() + try audioSession.setCategory(.playAndRecord, mode: .default, options: [.defaultToSpeaker]) + try audioSession.setActive(true) + + let audioPlayer = try AVAudioPlayer(contentsOf: mixedAudioURL) + audioPlayer.volume = 1.0 + audioPlayer.play() + */ + + } catch { + print("Error: \(error.localizedDescription)") + } + } + + func mixAudio(start : TimeInterval, stop : TimeInterval) { + let totalTime = stop - start + guard let recordedAudioURL = recordedAudioURL else { return } + guard let playerURL = audioURLFromMP4 else { return } + Utilities.startProgressHUD(msg: "Mixing Audio") + let composition = AVMutableComposition() + let compositionDuration = CMTime(seconds: totalTime, preferredTimescale: 1) + + // Add the recorded audio from 0 to 10 seconds + let recordedAudioAsset = AVURLAsset(url: recordedAudioURL) + let recordedAudioTrack = composition.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid) + + do { + try recordedAudioTrack?.insertTimeRange(CMTimeRangeMake(start: CMTime.zero, duration: compositionDuration), of: recordedAudioAsset.tracks(withMediaType: .audio)[0], at: CMTime.zero) + } catch { + Utilities.dismissProgressHUD() + print("Error adding recorded audio track: \(error.localizedDescription)") + } + + // Add the downloaded M4A file from 10 to 20 seconds + let playerAsset = AVURLAsset(url: playerURL) + let playerTrack = composition.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid) + + do { + try playerTrack?.insertTimeRange(CMTimeRangeMake(start: CMTime(seconds: start, preferredTimescale: 1), duration: compositionDuration), of: playerAsset.tracks(withMediaType: .audio)[0], at: CMTime.zero) + } catch { + Utilities.dismissProgressHUD() + print("Error adding player audio track: \(error.localizedDescription)") + } + + // Example usage: + + + // Export the mixed audio + let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! + let fileName = "\((self.videoTitle?.replacingOccurrences(of: " ", with: "").replacingOccurrences(of: ".", with: "") ?? "Audio") + Date().timeIntervalSince1970.toString()).m4a" + let filePath = documentsDirectory.appendingPathComponent(fileName) + deleteFileIfExist(at: filePath) + + mixedAudioURL = filePath + + guard let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetAppleM4A) else { return } + exportSession.outputURL = mixedAudioURL + exportSession.outputFileType = .m4a + + exportSession.exportAsynchronously { + if exportSession.status == .completed { + print("Mixing audio completed.") + Utilities.dismissProgressHUD() + DispatchQueue.main.async { [weak self] in + guard let self else{return} + vc.playBtn.isEnabled = true + vc.downloadRecordingBtn.isEnabled = true + } + + + } else if exportSession.status == .failed { + print("Mixing audio failed.", exportSession.error?.localizedDescription) + } + } + } + + func deleteFileIfExist(at url: URL) { + let fileManager = FileManager.default + + do { + // Check if the file exists + if fileManager.fileExists(atPath: url.path) { + // Attempt to delete the file + try fileManager.removeItem(at: url) + print("File deleted successfully.") + } else { + print("File does not exist at path: \(url.path)") + } + } catch { + print("Error deleting file: \(error.localizedDescription)") + } + } +} diff --git a/WOKA/Karaoke/ViewModel/KaraokeListingVM.swift b/WOKA/Karaoke/ViewModel/KaraokeListingVM.swift index 36a0df2..7162653 100644 --- a/WOKA/Karaoke/ViewModel/KaraokeListingVM.swift +++ b/WOKA/Karaoke/ViewModel/KaraokeListingVM.swift @@ -190,15 +190,15 @@ class KaraokeListingVM{ if let showListIndex = karaokeListData.firstIndex(where: { $0.id == postID }){ karaokeListData[showListIndex].markAsFavourite = false vc.karaokeListingTableView.reloadRows(at: [IndexPath(row: showListIndex, section: 0)],with: .none) - - // MyList Update - if MyListDataTemp.shareInstance.isDatafetched{ - if let indexRemove = MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.firstIndex(where: {$0.id == postID}){ - MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.remove(at: indexRemove) - K.GVar.myListSoftReload = true - - } - } + K.GVar.reloadMyList = true +// // MyList Update +// if MyListDataTemp.shareInstance.isDatafetched{ +// if let indexRemove = MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.firstIndex(where: {$0.id == postID}){ +// MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.remove(at: indexRemove) +// K.GVar.myListSoftReload = true +// +// } +// } } /* @@ -207,15 +207,15 @@ class KaraokeListingVM{ if let continueWatchingIndex = continueWatchingData.firstIndex(where: { $0.id == postID }){ continueWatchingData[continueWatchingIndex].markAsFavourite = false vc.continueWatchingCV.reloadItems(at: [IndexPath(row: continueWatchingIndex, section: 0)]) - + K.GVar.reloadMyList = true // MyList Update - if MyListDataTemp.shareInstance.isDatafetched{ - if let indexRemove = MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.firstIndex(where: {$0.id == postID}){ - MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.remove(at: indexRemove) - K.GVar.myListSoftReload = true - - } - } +// if MyListDataTemp.shareInstance.isDatafetched{ +// if let indexRemove = MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.firstIndex(where: {$0.id == postID}){ +// MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.remove(at: indexRemove) +// K.GVar.myListSoftReload = true +// +// } +// } } } } @@ -225,13 +225,14 @@ class KaraokeListingVM{ if let showListIndex = karaokeListData.firstIndex(where: { $0.id == postID }){ karaokeListData[showListIndex].markAsFavourite = true vc.karaokeListingTableView.reloadRows(at: [IndexPath(row: showListIndex, section: 0)],with: .none) + K.GVar.reloadMyList = true // MyList Update - if MyListDataTemp.shareInstance.isDatafetched{ - let karaokeData = karaokeListData[showListIndex] - MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.append(karaokeData) - K.GVar.myListSoftReload = true - - } +// if MyListDataTemp.shareInstance.isDatafetched{ +// let karaokeData = karaokeListData[showListIndex] +// MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.append(karaokeData) +// K.GVar.myListSoftReload = true +// +// } } /* @@ -240,17 +241,17 @@ class KaraokeListingVM{ if let continueWatchingIndex = continueWatchingData.firstIndex(where: { $0.id == postID }){ continueWatchingData[continueWatchingIndex].markAsFavourite = true vc.continueWatchingCV.reloadItems(at: [IndexPath(row: continueWatchingIndex, section: 0)]) - + K.GVar.reloadMyList = true // MyList Update - if MyListDataTemp.shareInstance.isDatafetched{ - // if data is updated for main list this ill not work - if MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.firstIndex(where: {$0.id == postID}) == nil{ - let audioData = continueWatchingData[continueWatchingIndex] - MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.append(audioData) - K.GVar.myListSoftReload = true - - } - } +// if MyListDataTemp.shareInstance.isDatafetched{ +// // if data is updated for main list this ill not work +// if MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.firstIndex(where: {$0.id == postID}) == nil{ +// let audioData = continueWatchingData[continueWatchingIndex] +// MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.append(audioData) +// K.GVar.myListSoftReload = true +// +// } +// } } } } @@ -307,7 +308,7 @@ class KaraokeListingVM{ } /* - Check if the data is in karaoke + Check if the data is in karaoke mylist */ if let index = MyListDataTemp.shareInstance.favListingData?.singKaraokeData?.firstIndex(where: {$0.id == postID}){ MyListDataTemp.shareInstance.favListingData?.singKaraokeData?[index].isLiked = true diff --git a/WOKA/SideBarNav/Controller/MyOrderDetailsVC.swift b/WOKA/SideBarNav/Controller/MyOrderDetailsVC.swift index 06fbe1c..c675175 100644 --- a/WOKA/SideBarNav/Controller/MyOrderDetailsVC.swift +++ b/WOKA/SideBarNav/Controller/MyOrderDetailsVC.swift @@ -16,6 +16,9 @@ class MyOrderDetailsVC: UIViewController { @IBOutlet weak var expectedDate: UILabel! @IBOutlet weak var tableView: UITableView! + @IBOutlet weak var noDataStack: UIStackView! + @IBOutlet weak var mainStack: UIStackView! + var orderID : String? var data : OrderDetailsDM.ResultData? @@ -34,6 +37,12 @@ class MyOrderDetailsVC: UIViewController { tableView.dataSource = self } + @IBAction func retryBtnTapped(_ sender: UIButton) { + if let orderID{ + getOrdersDetails(orderID: orderID) + } + } + // MARK: - Get MyORders func getOrdersDetails(orderID : String){ @@ -47,6 +56,8 @@ class MyOrderDetailsVC: UIViewController { switch data.success{ case 0: Utilities.dismissProgressHUD() + self?.toast(msg: K.ConstantString.unRecognised, time: 1.5) + self?.noDataStack.isHidden = false return case 1: Utilities.dismissProgressHUD() @@ -54,12 +65,16 @@ class MyOrderDetailsVC: UIViewController { self.data = data self.tableView.reloadData() setData() + self.mainStack.isHidden = false + self.tableView.isHidden = false + self.noDataStack.isHidden = true default: break } case .failure(let error): Utilities.dismissProgressHUD() - print(error) + self?.noDataStack.isHidden = false + self?.toast(msg: error.localizedDescription, time: 2) } } } diff --git a/WOKA/SideBarNav/Controller/MyOrdersVC.swift b/WOKA/SideBarNav/Controller/MyOrdersVC.swift index fa58f0c..24bbccb 100644 --- a/WOKA/SideBarNav/Controller/MyOrdersVC.swift +++ b/WOKA/SideBarNav/Controller/MyOrdersVC.swift @@ -52,14 +52,24 @@ extension MyOrdersVC : TableViewSRC{ let cell = tableView.dequeueReusableCell(withIdentifier: K.CellIdentifier.SideBarNav.myOrderCell) as! MyOrderCell let data = vm.orderData[indexPath.row] cell.setData(data: data) + + cell.btnTapped = { [weak self] in + guard let self else{return} + + let sb = UIStoryboard(name: K.StoryBoard.sideBarNav, bundle: nil) + let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.SideBarNav.myOrderDetailsVC) as! MyOrderDetailsVC + let orderID = vm.orderData[indexPath.row].orderID + vcPush.orderID = orderID + self.navigationController?.present(vcPush, animated: true) + } return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - let sb = UIStoryboard(name: K.StoryBoard.sideBarNav, bundle: nil) - let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.SideBarNav.myOrderDetailsVC) as! MyOrderDetailsVC - let orderID = vm.orderData[indexPath.row].orderID - vcPush.orderID = orderID - self.navigationController?.present(vcPush, animated: true) +// let sb = UIStoryboard(name: K.StoryBoard.sideBarNav, bundle: nil) +// let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.SideBarNav.myOrderDetailsVC) as! MyOrderDetailsVC +// let orderID = vm.orderData[indexPath.row].orderID +// vcPush.orderID = orderID +// self.navigationController?.present(vcPush, animated: true) } } diff --git a/WOKA/SideBarNav/SideBarNav.storyboard b/WOKA/SideBarNav/SideBarNav.storyboard index 83db267..27edcdf 100644 --- a/WOKA/SideBarNav/SideBarNav.storyboard +++ b/WOKA/SideBarNav/SideBarNav.storyboard @@ -710,14 +710,43 @@ - + +