KWMNewHomeVC.m 19.1 KB
Newer Older
houweibin committed
1 2 3 4 5 6 7 8 9 10
//
//  KWMNewHomeVC.m
//  iCemarose
//
//  Created by HouWeiBin on 2017/7/10.
//  Copyright © 2017年 kollway. All rights reserved.
//

#import "KWMNewHomeVC.h"
#import "KWMShopCartVC.h"
houweibin committed
11
#import "KWMSearchFeedbackVC.h"
houweibin committed
12 13
#import "KWMNewHomeCell.h"
#import "KWMSearchBar.h"
houweibin committed
14
#import "KWMHomeData.h"
houweibin committed
15
#import "KWMShoppingCart.h"
lee committed
16 17
#import <RegexKitLite/RegexKitLite.h>
#import <RXCollections/RXCollection.h>
lee committed
18
#import "KWMHomeVC.h"
lee committed
19 20
#import "KWMWishListVC.h"
#import <MJRefresh.h>
u  
lee committed
21
#import "KWMStringUtil.h"
22 23
#import "KWMPPCacheUtil.h"
#import "CacheKeyConstants.h"
houweibin committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

typedef enum{
    
    HeaderAd=0,
    
    HeaderMenu=1,
    
    HeaderRecommend=2,
    
    HeaderClothingSets=3,

    HeaderHotSales=4,
    
}Header;


@interface KWMNewHomeVC ()

@property(nonatomic,weak) IBOutlet UICollectionView *cvHome;

@property(nonatomic,strong) KWMAdHeader *adHeader;

@property(nonatomic,strong) KWMMenuHeader *menuHeader;

@property(nonatomic,strong) KWMRecommendHeader *recommendHeader;

@property(nonatomic,strong) KWMClothingSetsHeader *clothingSetsHeader;

@property(nonatomic,strong) KWMHotSalesHeader *hotSalesHeader;

@property(nonatomic,strong) KWMSearchBar *titleView;

houweibin committed
56 57
@property(nonatomic) KWMHomeData *homeData;

lee committed
58 59
@property(nonatomic) NSInteger page;

lee committed
60 61 62
@property(nonatomic) NSMutableArray<BUYProduct *>* productArray;

@property(nonatomic) NSMutableDictionary *dataMapping;
houweibin committed
63

64 65
@property(nonatomic) BOOL isRefreshUI;

r  
lee committed
66
//@property(nonatomic) NSString *clotingSetsHandle;
houweibin committed
67

houweibin committed
68 69
@end

houweibin committed
70 71 72
@implementation KWMNewHomeVC{
    CGFloat heightAdHeader;
    CGFloat heightClothingSets;
73
    CGFloat heightHotSale;
houweibin committed
74
}
houweibin committed
75 76 77 78

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
lee committed
79
    self.page = 1;
lee committed
80 81
//    [self requestProduct:@""];
    [self loadHomeData];
houweibin committed
82 83 84 85 86 87 88 89 90 91
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
    if (self.titleView) {
        NSInteger count = [[KWMShoppingCart sharedInstance] count].integerValue;
        self.titleView.count = count;
        [self.titleView resumeView];
    }
lee committed
92
    [self.cvHome reloadData];
93 94 95 96 97
    if(self.isRefreshUI){
        self.isRefreshUI = YES;
    }else{
        [self loadHomeData];
    }
houweibin committed
98 99 100 101 102 103
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}

houweibin committed
104

houweibin committed
105
- (void)initView{
lee committed
106
//    self.title = @"首页";
houweibin committed
107 108
    heightAdHeader = UI_SCREEN_WIDTH * 275 / 375;
    heightClothingSets = UI_SCREEN_WIDTH * 190 / 375 + 127; //127为图片外的布局高度
109
    heightHotSale = UI_SCREEN_WIDTH * 190 / 375 + 60;//60为图片外的布局高度
houweibin committed
110
    self.adHeader = [[KWMAdHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, heightAdHeader)];
houweibin committed
111 112
    self.menuHeader = [[KWMMenuHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 100)];
    self.recommendHeader = [[KWMRecommendHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 230)];
houweibin committed
113
    self.clothingSetsHeader = [[KWMClothingSetsHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, heightClothingSets)];
114
    self.hotSalesHeader = [[KWMHotSalesHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, heightHotSale)];
houweibin committed
115 116 117 118 119 120 121
    
    self.adHeader.delegate = self;
    self.menuHeader.delegate = self;
    self.recommendHeader.delegate = self;
    self.clothingSetsHeader.delegate = self;
    self.hotSalesHeader.delegate = self;
    
houweibin committed
122 123 124 125 126
    [self initTitleView];
    [self initCollectionView];
}

-(void)initTitleView{
houweibin committed
127
    self.titleView = [[KWMSearchBar alloc] init];
houweibin committed
128
    self.titleView.delegate = self;
houweibin committed
129
    self.titleView.btnSearch.hidden = NO;
houweibin committed
130
    [self.view addSubview:self.titleView];
houweibin committed
131
    [self initCustomTitleBarConstarints:self.titleView];
houweibin committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
}

- (void)initCollectionView{
    
    CHTCollectionViewWaterfallLayout *layout = [[CHTCollectionViewWaterfallLayout alloc] init];
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    layout.minimumColumnSpacing = 10;
    layout.minimumInteritemSpacing = 10;
    layout.columnCount = 2;
    self.cvHome.collectionViewLayout = layout;
    
    [self.cvHome registerNib:[UINib nibWithNibName:NSStringFromClass([KWMNewHomeCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([KWMNewHomeCell class])];
    
    [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMAdHeader kwmTag]];
    [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMHotSalesHeader kwmTag]];
    [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMRecommendHeader kwmTag]];
    [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMClothingSetsHeader kwmTag]];
    [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMMenuHeader kwmTag]];
lee committed
150
    
151 152 153
    MJRefreshAutoNormalFooter *refreshFooter = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
    [refreshFooter setTitle:NO_MORE_DATA forState:MJRefreshStateNoMoreData];
    self.cvHome.mj_footer = refreshFooter;
lee committed
154 155 156 157
}

- (void) loadMore {
    [self requestProductWithHandle:@"products-list-app-homepage" tags:nil valueKeyPath:@"productArray"];
houweibin committed
158 159
}

houweibin committed
160 161
#pragma mark - KWMAdDelegate
-(void)kwm_gotoWebView:(NSString *)url{
u  
lee committed
162 163 164
    if (![KWMStringUtil isBlank:url]) {
        [self openURLWithString:url];
    }
houweibin committed
165 166 167 168
}

#pragma mark - KWMMenuDelegate
-(void)kwm_onClickHotMenu{
169 170 171 172 173
//    if([TestModel isEqualToString:@"YES"]){
//        [self openURLWithString:[NSString stringWithFormat:@"https://cemarose.myshopify.com/products/%@",@"17618-01"]];
//    }else{
    [self openURLWithString:@"https://cemarose.myshopify.com/collections/new?title=最新单品"];
//    }
houweibin committed
174 175 176
}

-(void)kwm_onClickNewMenu{
lee committed
177 178
    KWMHomeVC* selectedGoodsVC = (KWMHomeVC *)[KWMBaseVC findControllerBy:[KWMHomeVC kwmTag] fromStoryboard:@"Main"];
    [self.navigationController pushViewController:selectedGoodsVC animated:YES];
houweibin committed
179 180 181
}

-(void)kwm_onClickWishMenu{
lee committed
182
    NSLog(@"wishmenu");
houweibin committed
183 184 185
    if(![self checkLogin]){
        return;
    }
lee committed
186 187
    KWMWishListVC* vc= (KWMWishListVC *)[KWMBaseVC findControllerBy:[KWMWishListVC kwmTag] fromStoryboard:@"NewProduct"];
    [self.navigationController pushViewController:vc animated:YES];
houweibin committed
188 189 190
}

-(void)kwm_onClickDeliveryMenu{
lee committed
191
    NSLog(@"deliverymenu");
u  
lee committed
192
    [self openURLWithString:@"https://www.cemarose.com/pages/service-description/?title=服务说明"];
houweibin committed
193 194
}

houweibin committed
195 196
#pragma mark - KWMRecommendDelegate
-(void)kwm_gotoRecommendPage{
197
    [self openURLWithString:@"https://cemarose.myshopify.com/collections/hot-sell-app?title=主推单品"];
houweibin committed
198 199
}

u  
lee committed
200
-(void)kwm_onClickHotSalesAd:(KWMAdvertisement *)ad {
lee committed
201 202 203
    if (![KWMStringUtil isBlank:ad.url]) {
        [self openURLWithString:ad.url];
    }
u  
lee committed
204 205 206
}

-(void)kwm_onClickFocusImage {
u  
lee committed
207 208 209 210
//#if DEBUG
//    [self openURLWithString:@"https://test.cemarose.com/static/wd/weeklydeal.htm"];
//    return;
//#endif
u  
lee committed
211 212 213 214 215
    if (![KWMStringUtil isBlank:self.homeData.clothing_sets.action]) {
        [self openURLWithString:self.homeData.clothing_sets.action];
    }
}

houweibin committed
216
-(void)kwm_gotoClothingSetsPage{
r  
lee committed
217
//    [self openURLWithString:[NSString stringWithFormat:@"https://cemarose.myshopify.com/collections/%@",self.clotingSetsHandle]];
lee committed
218 219 220
    if (![KWMStringUtil isBlank:self.homeData.clothing_sets.url]) {
        [self openURLWithString:self.homeData.clothing_sets.url];
    }
houweibin committed
221 222 223
}

#pragma mark - KWMRecommendDelegate KWMClothingSetsDelegate KWMHotSalesDelegate
houweibin committed
224
-(void)kwm_onClickProduct:(BUYProduct *)product{
lee committed
225 226
//    NSLog(@"product");
    [self openURLWithString:[NSString stringWithFormat:@"https://cemarose.myshopify.com/products/%@",product.handle]];
227
//    [self openURLWithString:[NSString stringWithFormat:@"https://cemarose.myshopify.com/products/19247-01"]];
houweibin committed
228 229
}

houweibin committed
230 231 232 233 234 235 236
#pragma mark - UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 5;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if(section == HeaderHotSales){
houweibin committed
237
        return self.productArray ? self.productArray.count:0;
houweibin committed
238 239 240 241 242 243
    }
    return 0;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    KWMNewHomeCell *homeCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KWMNewHomeCell class]) forIndexPath:indexPath];
houweibin committed
244 245
    BUYProduct *product = [self.productArray objectAtIndex:indexPath.row];
    homeCell.product = product;
houweibin committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
    return homeCell;
}

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    UICollectionReusableView *headerView;
    if (kind == CHTCollectionElementKindSectionHeader) {
        switch (indexPath.section) {
            case HeaderAd:
                headerView = [collectionView dequeueReusableSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMAdHeader kwmTag] forIndexPath:indexPath];
                if(headerView.subviews.count == 0){
                    [headerView addSubview:self.adHeader];
                }
                break;
            case HeaderMenu:
                headerView = [collectionView dequeueReusableSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMMenuHeader kwmTag] forIndexPath:indexPath];
                if(headerView.subviews.count == 0){
                    [headerView addSubview:self.menuHeader];
                }
                break;
            case HeaderRecommend:
                headerView = [collectionView dequeueReusableSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMRecommendHeader kwmTag] forIndexPath:indexPath];
                if(headerView.subviews.count == 0){
                    [headerView addSubview:self.recommendHeader];
                }
                break;
            case HeaderClothingSets:
                headerView = [collectionView dequeueReusableSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMClothingSetsHeader kwmTag] forIndexPath:indexPath];
                if(headerView.subviews.count == 0){
                    [headerView addSubview:self.clothingSetsHeader];
                }
                break;
            case HeaderHotSales:
                headerView = [collectionView dequeueReusableSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMHotSalesHeader kwmTag] forIndexPath:indexPath];
                if(headerView.subviews.count == 0){
                    [headerView addSubview:self.hotSalesHeader];
                }
                break;
            default:
                break;
        }
    }
    return headerView;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout heightForHeaderInSection:(NSInteger)section{
    NSInteger height = 0;
    switch (section) {
        case HeaderAd:
houweibin committed
294
            height = heightAdHeader;
houweibin committed
295 296 297 298 299 300 301 302
            break;
        case HeaderMenu:
            height = 100;
            break;
        case HeaderRecommend:
            height = 230;
            break;
        case HeaderClothingSets:
houweibin committed
303
            height = heightClothingSets;
houweibin committed
304 305
            break;
        case HeaderHotSales:
306
            height = heightHotSale;
houweibin committed
307 308 309 310 311 312 313 314 315
            break;
        default:
            break;
    }
    return height;
}

#pragma mark - CHTCollectionViewDelegateWaterfallLayout
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
lee committed
316
    [self kwm_onClickProduct:self.productArray[indexPath.item]];
houweibin committed
317 318 319
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
houweibin committed
320 321 322 323
    BUYProduct *product = [self.productArray objectAtIndex:indexPath.row];
    NSInteger width = (UI_SCREEN_WIDTH-30)/2;
    NSInteger height = [KWMNewHomeCell acturlHeight:product width:width];
    CGSize size = CGSizeMake(width, height);
houweibin committed
324 325 326 327 328 329 330 331 332 333
    return size;
}

#pragma mark - KWMSearchBarDelegate
- (void)kwm_onClickShopCar{
    //购物车
    KWMShopCartVC *contactVC = (KWMShopCartVC *)[KWMBaseVC findControllerBy:[KWMShopCartVC kwmTag] fromStoryboard:@"ShopCart"];
    [self.navigationController pushViewController:contactVC animated:YES];
}

houweibin committed
334 335 336 337 338
-(void)kwm_startSearch{
    KWMSearchFeedbackVC *vc = (KWMSearchFeedbackVC *)[KWMBaseVC findControllerBy:[KWMSearchFeedbackVC kwmTag] fromStoryboard:@"New"];
    [self.navigationController pushViewController:vc animated:YES];
}

houweibin committed
339
#pragma makr - api
lee committed
340
- (void) requestProductWithHandle:(NSString *) handle tags:(NSArray *) tags valueKeyPath:(NSString *) valueKeyPath {
houweibin committed
341
    [self showLoading];
lee committed
342 343
    BOOL isHome = [handle isEqualToString:@"products-list-app-homepage"];
    NSInteger cpage = isHome ? self.page : 1;
344
    NSDictionary *parameters = [self getProductCacheKeyDictionary:cpage tags:tags handle:handle];
345 346 347
    if(!self.isRefreshUI){
        BOOL useHomeDataCache = [self useProductDataCache:parameters valueKeyPath:valueKeyPath page:cpage isHome:isHome];
    }
lee committed
348
    [self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
349
        [self hideLoading];
lee committed
350
        if (!error) {
lee committed
351
            [self.client getProductsPage:cpage inCollection:collection.identifier withTags:tags sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) {
lee committed
352
                if (!error) {
353
                    [KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage products:products];
354 355
                    [self setValue:products forKeyPath:valueKeyPath];
                    [self.cvHome reloadData];
lee committed
356
                }else{
houweibin committed
357
//                    [self showError:error];
lee committed
358
                }
lee committed
359 360 361 362
                if (isHome) {
                    self.page = self.page + 1;
                    products.count ? [self.cvHome.mj_footer endRefreshing] : [self.cvHome.mj_footer endRefreshingWithNoMoreData];
                }
lee committed
363 364 365
            }];
        }else{
            [self showError:error];
houweibin committed
366
        }
lee committed
367
    }];
houweibin committed
368 369
}

370
- (void) loadHomeData{
lee committed
371
    [self requestProductWithHandle:@"hot-sell-app" tags:nil valueKeyPath:@"recommendHeader.productArray"];
372 373 374
    if(!self.isRefreshUI){
        BOOL useCache = [self useHomeDataCache];
    }
lee committed
375
    [self.api getHomeDataWithSuccess:^(NSURLSessionDataTask *task, KWMHomeDataResult *result) {
376
        [KWMPPCacheUtil saveDataToCache:nil urlKey:CACHE_KEY_getHomeDataWithSuccess homeData:result.data];
houweibin committed
377 378
            self.homeData = result.data;
            [self.cvHome reloadData];
lee committed
379
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
houweibin committed
380
//        [self showError:error];
lee committed
381 382
    }];
}
houweibin committed
383

lee committed
384 385
- (void)setHomeData:(KWMHomeData *)homeData {
    _homeData = homeData;
u  
lee committed
386 387 388
//#if DEBUG
//    [self.homeData.ad_banner[0] setUrl:@"https://www.cemarose.com/pages/sale_test_111"];
//#endif
u  
lee committed
389
//    [self.homeData.ad_banner[0] setUrl:@"https://www.cemarose.cn/collections/skirts/girls"];
lee committed
390
    self.adHeader.adArray = self.homeData.ad_banner;
u  
lee committed
391
    self.hotSalesHeader.bannerArray = self.homeData.hot_sales_ads;
392
//    self.homeData.hot_sales.single_show_count = @(1);
lee committed
393
    self.clothingSetsHeader.headerImage = self.homeData.clothing_sets.image;
u  
lee committed
394 395 396
//    self.homeData.clothing_sets.url =@"https://www.cemarose.cn/collections/skirts/girls+spring-summer-2016?title=ml";
    NSURL *url = [[NSURL alloc] initWithString:self.homeData.clothing_sets.url];
    NSArray *clothingParam = [url.path arrayOfCaptureComponentsMatchedByRegex:@"collections\\/([^/]*+)\\/?(.*)$"];
lee committed
397 398 399 400 401
    if (clothingParam.count) {
        clothingParam = clothingParam.firstObject;
        NSString *handle = clothingParam.count > 1 ? clothingParam[1] : nil;
        NSArray *tags = clothingParam.count > 2 ? [clothingParam[2] componentsSeparatedByString:@"+"] : nil;
        if (handle) {
r  
lee committed
402
//            self.clotingSetsHandle = handle;
lee committed
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
            [self requestProductWithHandle:handle tags:tags valueKeyPath:@"clothingSetsHeader.productArray"];
        }
    }
    [self requestProductWithHandle:@"products-list-app-homepage" tags:nil valueKeyPath:@"productArray"];
}

- (void)setProductArray:(NSArray<BUYProduct *> *)productArray {
    if (!_productArray) {
        NSInteger ssize = self.homeData.hot_sales.single_show_count.integerValue;
        NSInteger count = productArray.count;
        self.hotSalesHeader.singleShowArray = count <= ssize ? productArray : [productArray subarrayWithRange:NSMakeRange(0, ssize)];
        _productArray = [[NSMutableArray alloc] init];
//        [_productArray addObjectsFromArray:[productArray subarrayWithRange:NSMakeRange(self.homeData.hot_sales.single_show_count.integerValue, 99)]];
        if (count > ssize) {
        [_productArray addObjectsFromArray:[productArray subarrayWithRange:NSMakeRange(ssize, count - ssize)]];
        }
    }else{
        [_productArray addObjectsFromArray:productArray];
    }
//    _productArray = productArray;
    
}
houweibin committed
425

426 427
#pragma mark -cache
/** 因为homedata api的url是动态的,url上的时间戳随时间的改变,所以需要手动保存,和获取 **/
houweibin committed
428
//缓存规则:网络请求数据照常,如果没网络,并且缓存有数据,会拿缓存的数据显示。
429
-(BOOL)useHomeDataCache{
430 431 432 433
        KWMHomeData *homeData = [KWMPPCacheUtil getHomeDataByCache:nil urlKey:CACHE_KEY_getHomeDataWithSuccess];
        if(homeData){
            self.homeData = homeData;
            [self.cvHome reloadData];
434
            return true;
435
        }else{
houweibin committed
436
            return false;
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
        }
}

//初始化缓存parameters key
- (NSDictionary *)getProductCacheKeyDictionary:(NSUInteger)page
                                   tags:(nullable NSArray <NSString *> *)tags
                           handle:(nullable NSString *)handle{
    NSMutableDictionary *params = @{
                                    @"limit"         : @(self.client.pageSize),
                                    @"page"          : @(page)
                                    }.mutableCopy;
    if (tags) {
        params[@"tag"] = [tags componentsJoinedByString:@","];
    }
    if (handle) {
        params[@"handle"] = handle;
    }
    return params;
}

houweibin committed
457
//缓存规则:网络请求数据照常,如果没网络,并且缓存有数据,会拿缓存的数据显示。
458 459
-(BOOL)useProductDataCache:(NSDictionary *)cacheKeyDictionary valueKeyPath:(NSString *)valueKeyPath page:(NSUInteger)page isHome:(BOOL)isHome{
    if(!kIsNetwork || page == 1){
460 461 462 463 464 465 466 467 468 469
        [self hideLoading];
        NSArray *products = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage];
        if(products && products.count > 0){
            [self setValue:products forKeyPath:valueKeyPath];
            [self.cvHome reloadData];
            if (isHome) {
                self.page = self.page + 1;
                products.count ? [self.cvHome.mj_footer endRefreshing] : [self.cvHome.mj_footer endRefreshingWithNoMoreData];
            }
        }else{
houweibin committed
470
            return false;
471 472 473 474 475
        }
    }
    return !kIsNetwork;
}

houweibin committed
476
@end