Commit 3416b732 by houweibin

首页loading显示与隐藏调整为

与homedata api数据的获取相关
parent 8220b199
......@@ -339,15 +339,13 @@ typedef enum{
#pragma makr - api
- (void) requestProductWithHandle:(NSString *) handle tags:(NSArray *) tags valueKeyPath:(NSString *) valueKeyPath {
[self showLoading];
BOOL isHome = [handle isEqualToString:@"products-list-app-homepage"];
NSInteger cpage = isHome ? self.page : 1;
NSDictionary *parameters = [self getProductCacheKeyDictionary:cpage tags:tags handle:handle];
if(!self.isRefreshUI){
BOOL useHomeDataCache = [self useProductDataCache:parameters valueKeyPath:valueKeyPath page:cpage isHome:isHome];
BOOL useProductDataCache = [self useProductDataCache:parameters valueKeyPath:valueKeyPath page:cpage isHome:isHome];
}
[self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
[self hideLoading];
if (!error) {
[self.client getProductsPage:cpage inCollection:collection.identifier withTags:tags sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) {
if (!error) {
......@@ -370,10 +368,12 @@ typedef enum{
- (void) loadHomeData{
[self requestProductWithHandle:@"hot-sell-app" tags:nil valueKeyPath:@"recommendHeader.productArray"];
[self showLoading];
if(!self.isRefreshUI){
BOOL useCache = [self useHomeDataCache];
}
[self.api getHomeDataWithSuccess:^(NSURLSessionDataTask *task, KWMHomeDataResult *result) {
[self hideLoading];
[KWMPPCacheUtil saveDataToCache:nil urlKey:CACHE_KEY_getHomeDataWithSuccess homeData:result.data];
self.homeData = result.data;
[self.cvHome reloadData];
......@@ -430,6 +430,7 @@ typedef enum{
-(BOOL)useHomeDataCache{
KWMHomeData *homeData = [KWMPPCacheUtil getHomeDataByCache:nil urlKey:CACHE_KEY_getHomeDataWithSuccess];
if(homeData){
[self hideLoading];
self.homeData = homeData;
[self.cvHome reloadData];
return true;
......@@ -458,7 +459,6 @@ typedef enum{
//缓存规则:网络请求数据照常,如果没网络,并且缓存有数据,会拿缓存的数据显示。
-(BOOL)useProductDataCache:(NSDictionary *)cacheKeyDictionary valueKeyPath:(NSString *)valueKeyPath page:(NSUInteger)page isHome:(BOOL)isHome{
if(!kIsNetwork || page == 1){
[self hideLoading];
NSArray *products = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage];
if(products && products.count > 0){
[self setValue:products forKeyPath:valueKeyPath];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment