diff --git a/WOKA/Assets/Assets.xcassets/Shop/Card.imageset/Contents.json b/WOKA/Assets/Assets.xcassets/Shop/Card.imageset/Contents.json new file mode 100644 index 0000000..3b6efdb --- /dev/null +++ b/WOKA/Assets/Assets.xcassets/Shop/Card.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Rectangle Copy 5.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/WOKA/Assets/Assets.xcassets/Shop/Card.imageset/Rectangle Copy 5.png b/WOKA/Assets/Assets.xcassets/Shop/Card.imageset/Rectangle Copy 5.png new file mode 100644 index 0000000..b4b7f11 Binary files /dev/null and b/WOKA/Assets/Assets.xcassets/Shop/Card.imageset/Rectangle Copy 5.png differ diff --git a/WOKA/Assets/Assets.xcassets/Shop/Contents.json b/WOKA/Assets/Assets.xcassets/Shop/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/WOKA/Assets/Assets.xcassets/Shop/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/WOKA/Shop/Controller/ShopProductsVC.swift b/WOKA/Shop/Controller/ShopProductsVC.swift index be805c5..4a29547 100644 --- a/WOKA/Shop/Controller/ShopProductsVC.swift +++ b/WOKA/Shop/Controller/ShopProductsVC.swift @@ -90,16 +90,28 @@ class ShopProductsVC: UIViewController { extension ShopProductsVC : CollectionViewSRC{ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return vm.subCategoryData.count + if collectionView == subCategoryCV{ + return vm.subCategoryData.count + }else{ + return vm.shopProductsData.count + } } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: K.CellIdentifier.WebSeries.seasonCategoryCell, for: indexPath) as! SeasonCategoryCell - - let data = vm.subCategoryData[indexPath.row] -// cell.setData(title: data.seasonNumber ?? "Season", iselected: data.id == vm.episodeSelectedCateogory) - cell.setSubCategory(data: data, isSelected: data.id == vm.selectedSubCategory) - return cell + if collectionView == subCategoryCV{ + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: K.CellIdentifier.WebSeries.seasonCategoryCell, for: indexPath) as! SeasonCategoryCell + + let data = vm.subCategoryData[indexPath.row] + // cell.setData(title: data.seasonNumber ?? "Season", iselected: data.id == vm.episodeSelectedCateogory) + cell.setSubCategory(data: data, isSelected: data.id == vm.selectedSubCategory) + return cell + }else{ + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: K.CellIdentifier.Shop.shopProductsCell, for: indexPath) as! ShopProductsCell + let data = vm.shopProductsData[indexPath.row] + cell.setData(data: data) + return cell + } + } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { @@ -118,21 +130,27 @@ extension ShopProductsVC : CollectionViewSRC{ extension ShopProductsVC : UICollectionViewDelegateFlowLayout{ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - // Generate a random string for testing purposes - let randomText = vm.subCategoryData[indexPath.row].subCategoryName! + + if collectionView == subCategoryCV{ + // Generate a random string for testing purposes + let randomText = vm.subCategoryData[indexPath.row].subCategoryName! - // Define the font for the text - let font = FontCustom.shareInstance.customFont(fontName: .Exo2_Bold, size: 18) // Adjust the font size as needed + // Define the font for the text + let font = FontCustom.shareInstance.customFont(fontName: .Exo2_Bold, size: 18) // Adjust the font size as needed - // Calculate the width of the text - let attributes = [NSAttributedString.Key.font: font] - let textWidth = (randomText as NSString).size(withAttributes: attributes).width + // Calculate the width of the text + let attributes = [NSAttributedString.Key.font: font] + let textWidth = (randomText as NSString).size(withAttributes: attributes).width - // Set the cell width based on the text width and any additional padding - // 14 for container view + 10 for inside spacing. - let padding: CGFloat = 24 + 20 // Adjust padding as needed - let cellWidth = textWidth + padding - return CGSize(width: cellWidth , height: 50) + // Set the cell width based on the text width and any additional padding + // 14 for container view + 10 for inside spacing. + let padding: CGFloat = 24 + 20 // Adjust padding as needed + let cellWidth = textWidth + padding + return CGSize(width: cellWidth , height: 60) + }else{ + return CGSize(width: 100, height: 100) + } + } } diff --git a/WOKA/Shop/Shop.storyboard b/WOKA/Shop/Shop.storyboard index b0e9650..b0020d3 100644 --- a/WOKA/Shop/Shop.storyboard +++ b/WOKA/Shop/Shop.storyboard @@ -105,10 +105,10 @@ - + - + @@ -119,7 +119,7 @@ - + @@ -150,7 +150,6 @@ - diff --git a/WOKA/Shop/View/ShopProductsCell.swift b/WOKA/Shop/View/ShopProductsCell.swift index ca550d3..64cb70d 100644 --- a/WOKA/Shop/View/ShopProductsCell.swift +++ b/WOKA/Shop/View/ShopProductsCell.swift @@ -9,9 +9,22 @@ import UIKit class ShopProductsCell: UICollectionViewCell { + @IBOutlet weak var productImage: UIImageView! + @IBOutlet weak var productTitle: UILabel! + @IBOutlet weak var productPrice: UILabel! + override func awakeFromNib() { super.awakeFromNib() // Initialization code } + + func setData(data : ShopProductDM.SabakDegiNaniSery){ + self.productTitle.text = data.productName + self.productPrice.text = data.productPrice + + if let url = data.productThumbnail{ + self.productImage.imageURL(url, color: .black) + } + } } diff --git a/WOKA/Shop/View/ShopProductsCell.xib b/WOKA/Shop/View/ShopProductsCell.xib index 0f71232..c858805 100644 --- a/WOKA/Shop/View/ShopProductsCell.xib +++ b/WOKA/Shop/View/ShopProductsCell.xib @@ -4,9 +4,15 @@ + + + + Exo2-Bold + + @@ -16,10 +22,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WOKA/Shop/ViewModel/ShopProductsVM.swift b/WOKA/Shop/ViewModel/ShopProductsVM.swift index 6d9fa17..d0c3c66 100644 --- a/WOKA/Shop/ViewModel/ShopProductsVM.swift +++ b/WOKA/Shop/ViewModel/ShopProductsVM.swift @@ -12,7 +12,7 @@ class ShopProductsVM{ weak var vc : ShopProductsVC! var subCategoryData = [ShopSubCategoryDM.ResultData]() - var shopProducts = [ShopProductDM.ResultData]() + var shopProductsData = [ShopProductDM.SabakDegiNaniSery]() var categoryID : Int? var selectedSubCategory = 0 @@ -35,6 +35,10 @@ class ShopProductsVM{ vc.subCategoryCV.register(UINib(nibName: K.CellIdentifier.WebSeries.seasonCategoryCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.WebSeries.seasonCategoryCell) vc.subCategoryCV.delegate = vc.self vc.subCategoryCV.dataSource = vc.self + + vc.productCV.register(UINib(nibName: K.CellIdentifier.Shop.shopProductsCell, bundle: nil), forCellWithReuseIdentifier: K.CellIdentifier.Shop.shopProductsCell) + vc.productCV.delegate = vc.self + vc.productCV.dataSource = vc.self } // MARK: - Get SuperCategory @@ -66,13 +70,13 @@ class ShopProductsVM{ case 1: Utilities.dismissProgressHUD() guard let data = data.data?.result else{return} - self.subCategoryData.append(ShopSubCategoryDM.ResultData(id: 0, categoryMasterID: 0, subCategoryName: "All", subCategoryThumbnail: "")) + self.subCategoryData.append(ShopSubCategoryDM.ResultData(id: 0, categoryMasterID: 0, subCategoryName: " All ", subCategoryThumbnail: "")) self.subCategoryData.append(contentsOf: data) self.selectedSubCategory = data.first?.id ?? 0 self.vc.subCategoryCV.reloadData() -// if let subCatID = data.first?.id{ -// self.getShopProducts(subCategoryID: nil) -// } + if let subCatID = data.first?.id{ + self.getShopProducts(subCategoryID: subCatID) + } default: Utilities.dismissProgressHUD() break @@ -119,7 +123,9 @@ class ShopProductsVM{ } case 1: Utilities.dismissProgressHUD() - guard let data = data.data?.result else{return} + guard let data = data.data?.result?.sabakDegiNaniSeries else{return} + self.shopProductsData = data + self.vc.productCV.reloadData() print(data) default: Utilities.dismissProgressHUD()