- removed toast msg for guest signup.

- fixed the product listing issue inside shop products
This commit is contained in:
2024-10-17 19:25:38 +05:30
parent 4ef01bafd7
commit 821988ff41
9 changed files with 89 additions and 51 deletions

View File

@@ -94,16 +94,16 @@ extension ShopProductsVC : CollectionViewSRC{
}
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if collectionView == productCV{
if vm.stopFetch{return}
if indexPath.row == productCV.numberOfItems(inSection: 0) - 1{
spinnerView.startAnimating()
vm.pageNo += 1
vm.getShopProducts(subCategoryID: vm.selectedSubCategory)
}
}
}
// func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
// if collectionView == productCV{
// if indexPath.row == productCV.numberOfItems(inSection: 0) - 1{
// print("Next Page")
// spinnerView.startAnimating()
// vm.pageNo += 1
// vm.getShopProducts(subCategoryID: vm.selectedSubCategory)
// }
// }
// }
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
switch collectionView{
@@ -144,7 +144,7 @@ extension ShopProductsVC : GADBannerViewDelegate{
func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
adView.isHidden = false
bannerView.alpha = 0
bannerView.backgroundColor = #colorLiteral(red: 0.01960784314, green: 0, blue: 0.2196078431, alpha: 1)
// bannerView.backgroundColor = #colorLiteral(red: 0.01960784314, green: 0, blue: 0.2196078431, alpha: 1)
UIView.animate(withDuration: 0.2, animations: {
bannerView.alpha = 1
})

View File

@@ -179,7 +179,7 @@
<rect key="frame" x="0.0" y="557.33333333333337" width="393" height="294.66666666666663"/>
</imageView>
<stackView hidden="YES" opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="3kd-PT-FOP">
<rect key="frame" x="0.0" y="377.66666666666669" width="393" height="241.00000000000006"/>
<rect key="frame" x="0.0" y="360.66666666666669" width="393" height="241.00000000000006"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="SupportGirlImage" translatesAutoresizingMaskIntoConstraints="NO" id="zin-kU-oRx">
<rect key="frame" x="0.0" y="0.0" width="393" height="166"/>
@@ -205,10 +205,10 @@
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="ZzE-T4-HYp" userLabel="ContentStack">
<rect key="frame" x="0.0" y="144" width="393" height="708"/>
<rect key="frame" x="0.0" y="144" width="393" height="674"/>
<subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="hin-ei-TV5">
<rect key="frame" x="0.0" y="0.0" width="393" height="678"/>
<rect key="frame" x="0.0" y="0.0" width="393" height="644"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="MDX-db-Lz1">
<size key="itemSize" width="128" height="128"/>
@@ -219,14 +219,14 @@
<cells/>
</collectionView>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="medium" translatesAutoresizingMaskIntoConstraints="NO" id="Sr3-9L-8Fz">
<rect key="frame" x="0.0" y="688" width="393" height="20"/>
<rect key="frame" x="0.0" y="654" width="393" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="4bZ-Eh-Yno"/>
</constraints>
<color key="color" red="0.035294117649999998" green="0.0" blue="0.36470588240000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</activityIndicatorView>
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="OHh-gC-1V1">
<rect key="frame" x="0.0" y="708" width="393" height="100"/>
<rect key="frame" x="0.0" y="674" width="393" height="100"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="100" id="lBm-68-JUi"/>
@@ -257,7 +257,7 @@
<constraint firstItem="ZzE-T4-HYp" firstAttribute="leading" secondItem="EEU-2F-lPA" secondAttribute="leading" id="2lw-fJ-dUv"/>
<constraint firstItem="3kd-PT-FOP" firstAttribute="leading" secondItem="EEU-2F-lPA" secondAttribute="leading" id="CE5-R0-xNG"/>
<constraint firstItem="EEU-2F-lPA" firstAttribute="trailing" secondItem="3kd-PT-FOP" secondAttribute="trailing" id="CwP-3o-fkv"/>
<constraint firstAttribute="bottom" secondItem="ZzE-T4-HYp" secondAttribute="bottom" id="IN5-0y-F3R"/>
<constraint firstItem="EEU-2F-lPA" firstAttribute="bottom" secondItem="ZzE-T4-HYp" secondAttribute="bottom" id="IN5-0y-F3R"/>
<constraint firstAttribute="trailing" secondItem="03T-HE-97c" secondAttribute="trailing" id="JDD-fl-tqc"/>
<constraint firstItem="03T-HE-97c" firstAttribute="leading" secondItem="EEU-2F-lPA" secondAttribute="leading" id="KUx-kz-pc7"/>
<constraint firstItem="03T-HE-97c" firstAttribute="trailing" secondItem="EEU-2F-lPA" secondAttribute="trailing" id="Nxy-l1-wKb"/>
@@ -330,7 +330,7 @@
<rect key="frame" x="0.0" y="59" width="393" height="793"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wxy-J9-S7w">
<rect key="frame" x="0.0" y="0.0" width="393" height="690"/>
<rect key="frame" x="0.0" y="0.0" width="393" height="793"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="14" translatesAutoresizingMaskIntoConstraints="NO" id="2Hi-i7-d5A">
<rect key="frame" x="0.0" y="0.0" width="393" height="422"/>
@@ -407,6 +407,7 @@
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="249" verticalHuggingPriority="251" horizontalCompressionResistancePriority="749" text="" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iAp-gN-dq2">
<rect key="frame" x="64.666666666666657" y="0.0" width="308.33333333333337" height="0.0"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" name="ImageDarkBlue"/>
<nil key="highlightedColor"/>
</label>
@@ -466,8 +467,8 @@
<viewLayoutGuide key="contentLayoutGuide" id="3Kq-bf-nlH"/>
<viewLayoutGuide key="frameLayoutGuide" id="fDN-IE-ujI"/>
</scrollView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5An-pm-UM9">
<rect key="frame" x="0.0" y="693" width="393" height="100"/>
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5An-pm-UM9">
<rect key="frame" x="0.0" y="0.0" width="393" height="100"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
</subviews>

View File

@@ -19,8 +19,14 @@ class ShopProductsVM{
var selectedSubCategory = 0
var pageTitle : String?
// var pageNo = 0
// var stopFetch = false
// PAgination variables
var pageNo = 0
var stopFetch = false
var isShopDataLoading = false
var totalDataCount = 0 // this will hold the total count from api
var cartButton: UIBarButtonItem!
var bottomBanner = GADBannerView()
@@ -92,10 +98,11 @@ class ShopProductsVM{
self.subCategoryData.append(contentsOf: data)
self.selectedSubCategory = -1
self.vc.subCategoryCV.reloadData()
if let subCatID = data.first?.id{
Utilities.startProgressHUD()
self.getShopProducts(subCategoryID: subCatID)
}
// if let subCatID = data.first?.id{
// }
Utilities.startProgressHUD()
self.getShopProducts(subCategoryID: selectedSubCategory)
self.vc.noDataStack.isHidden = true
default:
Utilities.dismissProgressHUD()
@@ -131,6 +138,7 @@ class ShopProductsVM{
case .success(let data):
guard let self else{
Utilities.dismissProgressHUD()
self?.isShopDataLoading = false
return
}
switch data.success{
@@ -140,7 +148,7 @@ class ShopProductsVM{
*/
Utilities.dismissProgressHUD()
vc.spinnerView.stopAnimating()
if stopFetch == true { return}
self.isShopDataLoading = false
Utilities.alertWithBtnCompletion(title: "Error", msgBody: data.message ?? K.ConstantString.unRecognised, okBtnStr: "Retry?", vc: self.vc) { isDone in
if isDone{
self.getShopProducts(subCategoryID: subCategoryID)
@@ -149,15 +157,18 @@ class ShopProductsVM{
case 1:
Utilities.dismissProgressHUD()
vc.spinnerView.stopAnimating()
self.isShopDataLoading = false
guard let count = data.data?.totalRecords ,let data = data.data?.result else{return}
self.totalDataCount = count
if pageNo == 0{
self.shopProductsData.removeAll()
}
pageNo += 1
self.shopProductsData.append(contentsOf: data)
self.vc.productCV.reloadData()
if self.shopProductsData.count == count{
stopFetch = true
}
/*
check for single product
@@ -174,27 +185,28 @@ class ShopProductsVM{
/*
If ads found then only load it or else directly append the data and reload
*/
if let adsData = AuthFunc.shareInstance.adsData{
// check if ads data contains ad for webseries
if let shopSuperCatAd = adsData.result?.filter({$0.slug == AdsEnum.shop_super_category.rawValue}).first{
if shopSuperCatAd.googleAd != nil{
//setup google banner ads.
AdReusable.sharedInstance.setupBannerAd(bannerView: self.bottomBanner, in: vc.adView, adUnitID: K.GoogleAdIDs.shop, viewController: self.vc, height: 8, width: 15)
}
if bottomBanner.isHidden == false {return}
if let adsData = AuthFunc.shareInstance.adsData, let shopSuperCatAd = adsData.result?.filter({$0.slug == AdsEnum.shop_super_category.rawValue}).first {
if shopSuperCatAd.googleAd != nil{
//setup google banner ads.
AdReusable.sharedInstance.setupBannerAd(bannerView: self.bottomBanner, in: vc.adView, adUnitID: K.GoogleAdIDs.shop, viewController: self.vc, height: 8, width: 15)
}
}
default:
Utilities.dismissProgressHUD()
vc.spinnerView.stopAnimating()
self.isShopDataLoading = false
break
}
case .failure(let error):
guard let self else{
Utilities.dismissProgressHUD()
self?.vc.spinnerView.stopAnimating()
self?.isShopDataLoading = false
return
}
Utilities.dismissProgressHUD()
self.isShopDataLoading = false
vc.spinnerView.stopAnimating()
Utilities.alertWithBtnCompletion(title: "Error", msgBody: error.localizedDescription, okBtnStr: "Retry?", vc: self.vc) { isDone in
// if isDone{
@@ -206,6 +218,36 @@ class ShopProductsVM{
}
}
// MARK: - Animating scrollView
extension ShopProductsVC: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// dont do network call if the showdata count is same as the total count provided by api
// also check if already the api call is done
if vm.shopProductsData.count == vm.totalDataCount || vm.isShopDataLoading == true {return}
let contentHeight = scrollView.contentSize.height
let height = scrollView.frame.size.height
// Get the current vertical offset of the scroll view
let y = scrollView.contentOffset.y
// Check if the user scrolled to the bottom
if y > contentHeight - height * 1.6{
// check if internet is available
if CheckReachability.reachability?.isReachable == false{
return
}
spinnerView.startAnimating()
vm.isShopDataLoading = true
vm.getShopProducts(subCategoryID: vm.selectedSubCategory)
}
}
}
class FooterSpinnerView: UICollectionReusableView {
override init(frame: CGRect) {