123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940 |
- //
- // FKRecommendContoller.m
- // FirstLink
- //
- // Created by jack on 15/11/30.
- // Copyright © 2015年 FirstLink. All rights reserved.
- //
- #import "FKRecommendController.h"
- #import "FKRecommendViewModel.h"
- #import "FKAdvertiseViewCell.h"
- #import "FKOperationImageCell.h"
- #import "FKRecoIconListCell.h"
- #import "FKRecoNewsCell.h"
- #import "FKRecoHeaderCell.h"
- #import "FKRecoLimitBuyCell.h"
- #import "FKRecoPromotionLimitCell.h"
- #import "FKRecoPromotionCategoryCell.h"
- #import "FKRecoOfficalActivityCell.h"
- #import "FKRecoBrandListCell.h"
- #import "FKExploreTableViewCell.h"
- #import "FKRecoUserRecoProductCell.h"
- #import "FKRecoScanRecoProductCell.h"
- #import "FKRecoHotProductCell.h"
- #import "GuideView.h"
- #import "FKRecommendRequest.h"
- #import "FKRecommendReform.h"
- #import "FKWeakTimerTarget.h"
- #import "SchemaManager.h"
- #import "FloatDownView.h"
- #import "FLControllerHelper.h"
- #import "WebViewController.h"
- #import "FKRecoNewsController.h"
- #import "FKHotSaleController.h"
- #import "FKTopicController.h"
- #import "FKTopicListController.h"
- #import "FKTopicListController.h"
- #import "FKEntireCategoryController.h"
- #import "FLExploreController.h"
- #import "FKExploreListController.h"
- #import "PindanDetailController.h"
- #import "FKProDetailController.h"
- #import "FKRecommendPageController.h"
- #import "FKProDetailController.h"
- #import "FKWindowViewManager.h"
- @interface FKRecommendController () <UITableViewDelegate, UITableViewDataSource, FLNetworkDelegate, FKRecoCustomCellDelegate>
- @property (nonatomic, strong) FKAdvertiseViewCell *advertiseView;
- @property (nonatomic, strong) FKRecoPromotionLimitCell *promotionLimitCell;
- @property (nonatomic, strong) FKRecommendViewModel *viewModel;
- @property (nonatomic, strong) UIButton *backTopBtn;
- @property (nonatomic, strong) GuideView *dsNewsGuideView;
- @property (nonatomic, strong) GuideView *haoHuoGuideView;
- @end
- @implementation FKRecommendController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self addAllSubviews];
- [self configRiseView];
-
- if (([FKUserManager isUserLogin]
- || [FKUserManager sharedManager].applicationMode == ApplicationModeVisitor)) {
- [self.hudView show:YES];
- [self requestInitialData];
- }
-
- [FKWeakTimerTarget scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeCountDownCallback) userInfo:nil repeats:YES];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
-
- [self reqDynamicMessage];
- // [self.tableView reloadData];
- }
- #pragma mark - Reuqest
- - (void)autoRefresh {
- [self.refreshControl startRefreshingDirection:RefreshDirectionTop];
- }
- - (void)refreshControl:(FKRefreshControl *)refreshControl didEngageRefreshDirection:(RefreshDirection)direction {
- [self resetTableViewStatus];
- [self.advertiseView.banerView stopAutoSwitch];
- if (direction == RefreshDirectionTop) {
- [self.viewModel.contensOffsetDict removeAllObjects];
- [self requestInitialData];
-
- if (self.handlePageRefreshEvent) {
- self.handlePageRefreshEvent();
- }
- } else if (direction == RefreshDirectionBottom){
- [self requestMoreDailyData];
- }
- }
- - (void)requestMoreDailyData {
- [FKRecommendRequest requestMoreDataWithStartRow:[self.viewModel getAllRecommendItemCount]
- updateTime:self.viewModel.updateTime
- delegate:self];
- }
- - (void)requestInitialData {
- [FKRecommendRequest requestRecommendDataWithDelegate:self];
- [self reqDynamicMessage];
- }
- - (void)requestActivityData {
- [FKRecommendRequest requestActivityShareWithDelegate:self];
- }
- - (void)requestPromotionData {
- [FKRecommendRequest requestPromotionInfoWithDelegate:self];
- }
- - (void)requestScanRecoData {
- [FKRecommendRequest requestScanRecommendDataWithDelegate:self];
- }
- - (void)requestUserRecoData {
- if ([FKUserManager isUserLogin]) {
- [FKRecommendRequest requestUserRecommendDataWithDelegate:self];
- }
- }
- - (void)reqPointMessage {
- if ([FKUserManager sharedManager].applicationMode == ApplicationModeVisitor) return;
- [FKRecommendRequest requestPointMessage:REC_POINT_MESSAGE delegate:self];
- }
- - (void)reqDynamicMessage {
- if ([FKUserManager sharedManager].applicationMode == ApplicationModeVisitor) return;
- [FKRecommendRequest requestDynamicMsgWithIdentify:REC_DYNAMIC_MESSAGE deleagate:self];
- }
- #pragma mark - Response
- - (void)networkDidSuccessResponse:(NSDictionary *)response identify:(int)identify header:(MSGHeader *)header {
- [self.hudView hide:YES];
- [self finishLoadingData];
- [self.statusView removeFromSuperview];
- [self.advertiseView.banerView startAutoSwitch];
-
- if (header.code.intValue == RESPONSE_MSG_NORMAL) {
- if (identify == REC_INITIAL_DATA_REQ) {
- self.viewModel.elapseSecond = 0;
- self.viewModel = [FKRecommendReform parserViewModelWithDict:response];
-
- [self configAdvertiseView];
- [self requestUserRecoData];
- [self requestScanRecoData];
- [self requestActivityData];
- [self requestPromotionData];
- } else if (identify == REC_MORE_DATA_REQ) {
- NSInteger count = [FKRecommendReform parserHotProductForViewModel:self.viewModel withDict:response];
- if (count == 0 || count%PAGE_RECORD_COUNT > 0) {
- [self configTableViewNoMoreData];
- }
- } else if (identify == REC_ACTIVITY_SHARE) {
- self.viewModel.recoNewsItem = [FKRecommendReform parserActivityData:response];
- } else if (identify == REC_PROMOTION_INFO) {
- self.viewModel.flashSaleItem = [FKRecommendReform parserFlashSaleData:response];
- self.viewModel.haoHuoItem = [FKRecommendReform parserHaoHuoData:response];
- self.viewModel.operActivityArray = [FKRecommendReform parserOperateActivityData:response];
- } else if (identify == REC_POINT_MESSAGE) {
- NSString *pointMessage = [FKRecommendReform parserPointMessage:response];
- NSString *serveTime = [FKRecommendReform parserServeTimeStr:response];
- [self showMessage:pointMessage
- serveTime:serveTime
- identifyKey:LAST_SHOW_SCORE_MESSAGE_TIME
- riseType:RiseViewTypeAutoClose];
- return;
- } else if (identify == REC_DYNAMIC_MESSAGE){
- FKDynamicMessageItem *item = [FKRecommendReform parserDynamicItemWithDict:response];
- NSString *serveTime = [FKRecommendReform parserServeTimeStr:response];
- BOOL showRes = [self showMessage:item.message
- serveTime:serveTime
- identifyKey:LAST_SHOW_MESSAGE_TIME
- riseType:RiseViewTypeClickClose];
- if (!showRes) {
- // 优先展示新人及代金券提示
- [self reqPointMessage];
- }
- return;
- } else if (identify == REC_RANDOM_BRAND) {
- FKRecAreaItem *brandArea = [FKRecommendReform parserDateAreaWithDict:response
- arrayKey:@"list"
- idKey:nil
- descKey:nil
- className:[FKRecoBrandItem class]];
- self.viewModel.brandRecommendArea.dataArray = brandArea.dataArray;
- } else if (identify == REC_USER_DATA_REQ) {
- FKRecAreaItem *userRecoItem = [FKRecommendReform parserDateAreaWithDict:response
- arrayKey:@"list"
- idKey:nil
- descKey:@"list_desc"
- className:[FKHotProductItem class]];
- if (userRecoItem.dataArray.count > 0) {
- self.viewModel.userRecoArea = userRecoItem;
- }
- } else if (identify == REC_SCAN_DATA_REQ) {
- FKRecAreaItem *scanRecoItem = [FKRecommendReform parserDateAreaWithDict:response
- arrayKey:@"list"
- idKey:nil
- descKey:@"list_desc"
- className:[FKHotProductItem class]];
- if (scanRecoItem.dataArray.count > 0) {
- self.viewModel.scanRecoArea = scanRecoItem;
- }
- }
- }
-
- if (!self.viewModel || [self.viewModel allEmpty]) {
- [self showStatusTipInView:self.tableView image:[UIImage imageNamed:@"StatusNoOrderIcon"] title:@"没有发现商品哦"];
- }
-
- [self.tableView reloadData];
- }
- - (void)networkDidReceiveError:(NSError *)error identify:(int)identify header:(MSGHeader *)header {
- [self.hudView hide:NO];
- [self finishLoadingData];
- [self.advertiseView.banerView startAutoSwitch];
- [FLProgressHUDHelper showText:header.msg inView:self.view];
-
- if (identify == REC_DYNAMIC_MESSAGE){
- [self reqPointMessage];
- }
- }
- #pragma mark - tableView dataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- if (!self.viewModel) return 0;
- return [self.viewModel numberOfSections];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [self.viewModel numberOfRowsInSection:section];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 10;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return [self.viewModel heightForRowAtIndexPath:indexPath];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- self.backTopBtn.hidden = ([self.viewModel sectionTypeForSection:indexPath.section] != kRecoSectionTypeHotProduct);
-
- kRecoCellType cellType = [self.viewModel cellTypeForIndexPath:indexPath];
-
- switch (cellType) {
- case kRecoCellTypeAdvertise: {
- return self.advertiseView;
- }
- case kRecoCellTypeOperationImage: {
- FKOperationImageCell *operationCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKOperationImageCell class])];
- [operationCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- return operationCell;
- }
- case kRecoCellTypeIconList: {
- FKRecoIconListCell *iconCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoIconListCell class])];
- [iconCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- iconCell.delegate = self;
- iconCell.indexPath = indexPath;
- return iconCell;
- }
- case kRecoCellTypeRecoNews: {
- FKRecoNewsCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoNewsCell class])];
- [cell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- return cell;
- }
- case kRecoCellTypPromotionLimit: {
- FKRecoPromotionLimitCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoPromotionLimitCell class])];
- [cell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- cell.delegate = self;
- cell.indexPath = indexPath;
- self.promotionLimitCell = cell;
- return cell;
- }
- case kRecoCellTypPromotionCategory: {
- FKRecoPromotionCategoryCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoPromotionCategoryCell class])];
- [cell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- cell.delegate = self;
- cell.indexPath = indexPath;
- return cell;
- }
- case kRecoCellTypeHeader:{
- FKRecoHeaderCell *headerCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoHeaderCell class])];
- [headerCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- headerCell.delegate = self;
- headerCell.indexPath = indexPath;
- return headerCell;
- }
- case kRecoCellTypeLimitBuy:{
- FKRecoLimitBuyCell *limitCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoLimitBuyCell class])];
- [limitCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- limitCell.delegate = self;
- limitCell.indexPath = indexPath;
- return limitCell;
- }
- case kRecoCellTypeOfficalActivity:{
- FKRecoOfficalActivityCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoOfficalActivityCell class])];
- [cell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- cell.delegate = self;
- cell.indexPath = indexPath;
- return cell;
- }
- case kRecoCellTypeBrandReco: {
- FKRecoBrandListCell *brandCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoBrandListCell class])];
- [brandCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- brandCell.delegate = self;
- brandCell.indexPath = indexPath;
- return brandCell;
- break;
- }
- case kRecoCellTypeOperationActivity: {
- FKExploreTableViewCell *operationCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKExploreTableViewCell class])];
- [operationCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- operationCell.delegate = self;
- operationCell.indexPath = indexPath;
-
- CGFloat offset = [self.viewModel contentOffsetForKey:indexPath.hash];
- [operationCell.collectionView setContentOffset:CGPointMake(offset, 0) animated:NO];
- return operationCell;
- break;
- }
- case kRecoCellTypeUserRecoProduct: {
- FKRecoUserRecoProductCell *productCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoUserRecoProductCell class])];
- [productCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- productCell.delegate = self;
- productCell.indexPath = indexPath;
- return productCell;
- break;
- }
- case kRecoCellTypeScanRecoProduct: {
- FKRecoScanRecoProductCell *productCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoScanRecoProductCell class])];
- [productCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- return productCell;
- break;
- }
- case kRecoCellTypeHotProduct: {
- FKRecoHotProductCell *productCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKRecoHotProductCell class])];
- [productCell fk_configWithViewModel:self.viewModel indexPath:indexPath];
- return productCell;
- break;
- }
- default:
- break;
- }
- return nil;
- }
- - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- if ([cell isKindOfClass:[FKExploreTableViewCell class]]) {
- FKExploreTableViewCell *exploreCell = (FKExploreTableViewCell*)cell;
- [self.viewModel setContentOffset:exploreCell.collectionView.contentOffset.x forKey:indexPath.hash];
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- kRecoCellType cellType = [self.viewModel cellTypeForIndexPath:indexPath];
-
- switch (cellType) {
- case kRecoCellTypeOperationImage: {
- if ([FLStringHelper isValidString:self.viewModel.operationItem.targetUrl]){
- [self parseURLSchema:self.viewModel.operationItem.targetUrl];
-
- [FKRecommendRequest requestBehavior:@"index_activity_banner" objType:@"activity_banner" objID:nil positionV1:nil positionV2:nil];
- }
- break;
- }
- case kRecoCellTypeRecoNews: {
- [self pushViewController:[FKRecoNewsController new]];
- [FKRecommendRequest requestBehavior:@"index_headline_banner" objType:@"headline_banner" objID:nil positionV1:nil positionV2:nil];
- break;
- }
- case kRecoCellTypeScanRecoProduct: {
- FKHotProductItem *item = [self.viewModel.scanRecoArea dataItemAtIndex:(indexPath.row - 1)];
- if (item) {
- [self pushProductDetailController:item.recoItemID];
-
- [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPageDailyRecommendAlgo
- itemID:nil
- value:nil];
-
- [FKRecommendRequest requestBehavior:@"index_algo_product"
- objType:@"product"
- objID:item.recoItemID
- positionV1:[NSString stringWithFormat:@"%ld", (long)(indexPath.row - 1)]
- positionV2:nil];
-
- }
- break;
- }
- case kRecoCellTypeHotProduct: {
- FKHotProductItem *item = [self.viewModel.hotProductArea dataItemAtIndex:(indexPath.row - 1)];
- if (item) {
- [self pushProductDetailController:item.itemID];
-
- [FKRecommendRequest requestBehavior:@"index_hot_product"
- objType:@"product"
- objID:item.itemID
- positionV1:[NSString stringWithFormat:@"%ld", (long)(indexPath.row - 1)]
- positionV2:nil];
- }
- break;
- }
- default:
- break;
- }
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- if (self.viewModel.recoNewsItem && self.viewModel.flashSaleItem && self.viewModel.haoHuoItem) {
- if (scrollView.contentOffset.y > [self dsNewsGuideViewOffset]) {
- [self showDSNewsGuideView];
- }
- }
- }
- #pragma mark - FKRecommendBaseCellDelegate
- - (void)recommendClickHeaderButton:(UIButton *)button atIndexPath:(NSIndexPath *)indexPath {
- kRecoSectionType sectionType = [self.viewModel sectionTypeForSection:indexPath.section];
- switch (sectionType) {
- case kRecoSectionTypeOfficalActivity: {
- [self pushTopicListController:self.viewModel.officalActivityArea.areaID title:@"更多官网活动"];
- break;
- }
- case kRecoSectionTypeBrandReco: {
- [FKRecommendRequest requestRandomBrandWithDelegate:self];
- break;
- }
- case kRecoSectionTypeScanReco: {
- [self requestScanRecoData];
- break;
- }
- case kRecoSectionTypeOperationActivity: {
- FKTopicListController *controller = [[FKTopicListController alloc] initWithID:self.viewModel.operationActivityArea.areaID title:@"专题列表"];
- [self pushViewController:controller];
- break;
- }
- default:
- break;
- }
- }
- - (void)recommendClickCell:(id)cell atIndexPath:(NSIndexPath *)indexPath offset:(NSInteger)offset {
- kRecoCellType cellType = [self.viewModel cellTypeForIndexPath:indexPath];
- switch (cellType) {
- case kRecoCellTypeAdvertise: {
- FKAdvertiseItem *item = [self.viewModel advertiseItemAtIndex:offset];
- if (item && item.targetURL.length > 0) {
- [self parseURLSchema:item.targetURL];
- [FKRecommendRequest requestBehavior:@"index_banner" objType:@"banner" objID:item.itemID positionV1:[NSString stringWithFormat:@"%ld", (long)offset] positionV2:nil];
- }
- break;
- }
- case kRecoCellTypeIconList: {
- FKIconItem *item = [self.viewModel iconItemAtIndex:offset];
- if (item && item.targetUrl.length > 0) {
- [self.viewModel didClickNewTagAtIndex:offset];
- [self parseURLSchema:item.targetUrl];
-
- [FKRecommendRequest requestBehavior:@"index_icon_menu"
- objType:@"icon_menu"
- objID:item.itemID
- positionV1:[NSString stringWithFormat:@"%ld", (long)offset]
- positionV2:nil];
- }
- break;
- }
- case kRecoCellTypeLimitBuy: {
- FKLimitBuyItem *item = [self.viewModel limitBuyItemAtIndex:offset];
- if (item && item.targetUrl.length) {
- [self parseURLSchema:item.targetUrl];
-
- [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPageDailyRecommendLimitBuy
- itemID:nil
- value:nil];
-
- [FKRecommendRequest requestBehavior:@"index_promotion"
- objType:@"product"
- objID:item.objectID
- positionV1:[NSString stringWithFormat:@"%ld", (long)offset]
- positionV2:nil];
- }
- break;
- }
- case kRecoCellTypPromotionLimit: {
- NSString *targetURL = self.viewModel.flashSaleItem.targetURL;
- if (offset == 1) {
- targetURL = self.viewModel.haoHuoItem.targetURL;
- [FKRecommendRequest requestBehavior:@"index_haohuo_banner" objType:@"haohuo_banner" objID:nil positionV1:nil positionV2:nil];
- } else {
- [FKRecommendRequest requestBehavior:@"index_promotion_banner" objType:@"promotion_banner" objID:nil positionV1:nil positionV2:nil];
- }
- [self parseURLSchema:targetURL];
- break;
- }
- case kRecoCellTypPromotionCategory: {
- if (offset < self.viewModel.operActivityArray.count) {
- FKOperateActivityItem *item = self.viewModel.operActivityArray[offset];
- [self parseURLSchema:item.targetURL];
- }
- if (offset == (self.viewModel.operActivityArray.count - 1)) {
- [FKRecommendRequest requestBehavior:@"index_hotsale_banner" objType:@"hotsale_banner" objID:nil positionV1:nil positionV2:nil];
- } else {
- [FKRecommendRequest requestBehavior:@"index_block_banner" objType:@"block_banner" objID:nil positionV1:nil positionV2:nil];
- }
- break;
- }
- case kRecoCellTypeOfficalActivity: {
- FKActivityItem *item = [self.viewModel officalActivityItemAtIndex:(indexPath.row - 1)*2 + offset];
- if (item && item.targetUrl.length > 0) {
- [self parseURLSchema:item.targetUrl];
- } else {
- [self pushTopicController:item.itemID];
- }
-
- [FKRecommendRequest requestBehavior:@"index_official_activity"
- objType:@"topic"
- objID:item.itemID
- positionV1:[NSString stringWithFormat:@"%ld", (long)(indexPath.row - 1)]
- positionV2:nil];
- break;
- }
- case kRecoCellTypeUserRecoProduct: {
- FKHotProductItem *item = [self.viewModel.userRecoArea dataItemAtIndex:offset];
- if (item) {
- [self pushProductDetailController:item.recoItemID];
-
- [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPageDailyUserRecoAlgo
- itemID:nil
- value:nil];
- //
- [FKRecommendRequest requestBehavior:@"index_engine_product"
- objType:@"product"
- objID:item.itemID
- positionV1:[NSString stringWithFormat:@"%ld", (long)(offset)]
- positionV2:nil];
-
- }
-
- break;
- }
- case kRecoCellTypeBrandReco: {
- FKRecoBrandItem *item = [self.viewModel recoBrandItemAtIndex:offset];
- if (item && item.name.length) {
- [self pushExploreListController:item.name];
-
- [FKRecommendRequest requestBehavior:@"index_brand_recommend"
- objType:@"brand"
- objID:item.itemID
- positionV1:[NSString stringWithFormat:@"%ld", (long)offset]
- positionV2:nil];
- }
- break;
- }
- case kRecoCellTypeOperationActivity: {
- FKActivityItem *item = [self.viewModel operationActivityItemAtIndex:(indexPath.row - 1)];
- if (item) {
- if (offset < item.productArray.count) {
- FKActivityProductItem *productItem = item.productArray[offset];
- [self pushProductDetailController:productItem.itemID];
-
- [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPageDailyRecommendActivity
- itemID:item.itemID
- value:item.name];
-
- [FKRecommendRequest requestBehavior:@"index_activity_list"
- objType:@"product"
- objID:productItem.itemID
- positionV1:[NSString stringWithFormat:@"%ld", (long)(indexPath.row - 1)]
- positionV2:[NSString stringWithFormat:@"%ld", (long)offset]];
- } else if (offset == -1) { // -1 表示点击大图或者是更多按钮
- if (item && item.targetUrl.length > 0) {
- [self parseURLSchema:item.targetUrl];
- } else {
- [self pushTopicController:item.itemID];
- }
-
- [FKRecommendRequest requestBehavior:@"index_activity_list"
- objType:@"topic"
- objID:item.itemID
- positionV1:[NSString stringWithFormat:@"%ld", (long)(indexPath.row - 1)]
- positionV2:nil];
- }
- }
- break;
- }
- default:
- break;
- }
- }
- #pragma mark - FKRecommendActivityAreaCell
- - (void)clickActivityCellAtIndex:(NSInteger)index {
- if (index < self.viewModel.activityArea.count) {
- FKActivityItem *item = self.viewModel.activityArea[index];
- [self parseURLSchema:item.targetUrl];
- }
- }
- #pragma mark - action
- - (void)clickMoreTopicBtn:(UIButton *)sender{
- FLExploreController *controller = [FLExploreController new];
- controller.hidesBottomBarWhenPushed = YES;
- [self pushViewController:controller];
- }
- - (void)backTopAction:(UIButton *)sender {
- [self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
- }
- - (void)timeCountDownCallback {
- self.viewModel.elapseSecond += 1;
- NSTimeInterval endTime = [FLStringHelper timeIntervalFromString:self.viewModel.flashSaleItem.endTime];
- NSTimeInterval serverTime = [FLStringHelper timeIntervalFromString:self.viewModel.serverTime];
- [self.promotionLimitCell setRemindTime:(MAX(0, endTime - serverTime) - self.viewModel.elapseSecond)];
- }
- - (BOOL)showMessage:(NSString *)message
- serveTime:(NSString *)serveTime
- identifyKey:(NSString *)identifyKey
- riseType:(RiseViewType)riseType{
-
- if (!message.length) return NO;
-
- if ([self.viewModel needShowMsgWithServeTime:serveTime key:identifyKey]){
- FloatDownCommand *command = [[FloatDownCommand alloc] init];
- command.type = riseType;
- command.content = message;
- [[FloatDownView sharedInstance] sendCommand:command];
- [self.viewModel didShowMsgWithServeTime:serveTime key:identifyKey];
- return YES;
- }
- return NO;
- }
- #pragma mark - method
- - (void)configTableViewNoMoreData {
- self.isPageHasMoreData = NO;
- self.refreshControl.bottomEnabled = NO;
- self.refreshControl.autoRefreshBottom = NO;
- self.tableView.tableFooterView = self.emptyFooterView;
- }
- - (void)resetTableViewStatus {
- self.isPageHasMoreData = YES;
- self.refreshControl.autoRefreshBottom = YES;
- self.refreshControl.bottomEnabled = YES;
- self.tableView.tableFooterView = nil;
- }
- - (void)configRiseView {
- CGRect frame = CGRectMake(0, 0, UISCREENWIDTH, DOWN_COMMAND_HEIGHT);
- [[FloatDownView sharedInstance] prepareFloatDownViewFrame:frame
- inView:self.view
- clickCallBack:^(id object)
- {
-
- }];
- }
- - (void)configAdvertiseView {
- if (self.viewModel.advertiseItems.count > 0) {
- BOOL reload = [self.viewModel isNeedReloadAdvForOldUrls:self.advertiseView.banerView.imageUrls];
- if (reload == YES) {
- self.advertiseView.banerView.imageUrls = self.viewModel.advertiseUrlArray;
- self.advertiseView.pageControl.numberOfPages = self.viewModel.advertiseItems.count;
- self.advertiseView.pageControl.currentPage = 0;
- }
- }
- }
- - (void)parseURLSchema:(NSString *)urlString {
- if (urlString.length > 0) {
- NSURL *url = [NSURL URLWithString:urlString];
- if ([url.scheme rangeOfString:@"HTTP" options:NSCaseInsensitiveSearch].length > 0) {
- [self pushWebViewController:urlString];
- } else {
- [[SchemaManager sharedManager] parserURL:url shouldCache:NO];
- }
- }
- }
- - (void)addAllSubviews{
- [self.view addSubview:self.tableView];
- [self.view addSubview:self.backTopBtn];
-
- [self.backTopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.view).offset(-20);
- make.bottom.equalTo(self.view).offset(-10);
- make.size.mas_equalTo(CGSizeMake(40, 40));
- }];
-
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.insets(UIEdgeInsetsZero);
- }];
- }
-
- #pragma mark - Show Guide View
- - (CGFloat)dsNewsGuideViewOffset {
- CGFloat offset = 0;
- CGFloat fixOffset = 0;
- if (IS_IPHONE_6P) {
- fixOffset = 290;
- } else if (IS_IPHONE_6) {
- fixOffset = 230;
- } else if (IS_IPHONE_5) {
- fixOffset = 162;
- } else if (IS_IPHONE_X) {
- fixOffset = 230;
- }
- for (NSInteger section = 0; section < [self.viewModel numberOfSections]; section++) {
- for (NSInteger row = 0; row < [self.viewModel numberOfRowsInSection:section]; row++) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
- offset += [self.viewModel heightForRowAtIndexPath:indexPath];
- if ([self.viewModel cellTypeForIndexPath:indexPath] == kRecoCellTypeRecoNews) {
- return offset - fixOffset;
- }
- }
- }
- return 0;
- }
-
- - (void)showDSNewsGuideView {
- BOOL isShown = [[[NSUserDefaults standardUserDefaults] objectForKey:kShowDSNewsGuideViewKey] boolValue];
- if (!isShown && !IS_IPHONE_4) {
- self.tableView.scrollEnabled = NO;
-
- [self.tableView setContentOffset:CGPointMake(0, [self dsNewsGuideViewOffset]) animated:NO];
-
- GuideView *guideView = [[GuideView alloc] init];
- self.dsNewsGuideView = guideView;
-
- UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"guide_ds_news_img"]];
- imageView.userInteractionEnabled = YES;
- [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeDSNewsGuideView:)]];
- CGFloat offset = 0;
- if (IS_IPHONE_6P) {
- offset = 0;
- } else if (IS_IPHONE_6) {
- offset = -24;
- } else if (IS_IPHONE_5) {
- offset = -36;
- } else if (IS_IPHONE_X) {
- offset = 0;
- }
- [guideView addMaskView:imageView withRect:CGRectMake(0, offset, UISCREENWIDTH, UISCREENWIDTH*1334/750)];
-
- UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
- UIImage *image = [UIImage imageNamed:@"guide_close_button"];
- [closeButton setImage:image forState:UIControlStateNormal];
- [closeButton setImage:image forState:UIControlStateHighlighted];
- [closeButton addTarget:self action:@selector(closeDSNewsGuideView:) forControlEvents:UIControlEventTouchUpInside];
- [guideView addMaskView:closeButton withRect:CGRectMake(UISCREENWIDTH - 60, IS_IPHONE_X ? 44 : 20, 30, 31)];
-
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kShowDSNewsGuideViewKey];
- [[NSUserDefaults standardUserDefaults] synchronize];
-
- self.tableView.scrollEnabled = YES;
- }
- }
-
- - (IBAction)closeDSNewsGuideView:(id)sender {
- [self.dsNewsGuideView removeFromSuperview];
-
- [self showHaoHuoGuideView];
- }
- - (void)showHaoHuoGuideView {
- BOOL isShown = [[[NSUserDefaults standardUserDefaults] objectForKey:kShowHaoHuoGuideViewKey] boolValue];
- if (!isShown && !IS_IPHONE_4) {
- GuideView *guideView = [[GuideView alloc] init];
- self.haoHuoGuideView = guideView;
-
- UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"guide_hao_huo_img"]];
- imageView.userInteractionEnabled = YES;
- [imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeHaoHuoGuideView:)]];
- CGFloat offset = 0;
- if (IS_IPHONE_5) {
- offset = -36;
- } else if (IS_IPHONE_6) {
- offset = -24;
- } else if (IS_IPHONE_6P) {
- offset = 0;
- } else if (IS_IPHONE_X) {
- offset = 0;
- }
- [guideView addMaskView:imageView withRect:CGRectMake(0, offset, UISCREENWIDTH, UISCREENWIDTH*1334/750)];
-
- UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
- UIImage *image = [UIImage imageNamed:@"guide_close_button"];
- [closeButton setImage:image forState:UIControlStateNormal];
- [closeButton setImage:image forState:UIControlStateHighlighted];
- [closeButton addTarget:self action:@selector(closeHaoHuoGuideView:) forControlEvents:UIControlEventTouchUpInside];
- [guideView addMaskView:closeButton withRect:CGRectMake(UISCREENWIDTH - 60, IS_IPHONE_X ? 44 : 20, 30, 31)];
-
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kShowHaoHuoGuideViewKey];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
- }
- - (IBAction)closeHaoHuoGuideView:(id)sender {
- [self.haoHuoGuideView removeFromSuperview];
- }
- #pragma mark - Push Controller
- - (void)pushWebViewController:(NSString *)urlString {
- WebViewController *newViewController = [[FLControllerHelper currentStoryBoard] instantiateViewControllerWithIdentifier:@"WebViewController"];
- newViewController.url = urlString;
- [self pushViewController:newViewController];
- }
- - (void)pushPindanDetailController:(NSString *)postId userID:(NSString *)userId{
- PindanDetailController *detail = [[PindanDetailController alloc]initWithUserID:userId postID:postId];
- [self pushViewController:detail];
- }
- - (void)pushProductDetailController:(NSString *)productID {
-
- FKProDetailController *controller = [[FKProDetailController alloc] initWithProductID:productID];
- [self pushViewController:controller];
- }
- - (void)pushExploreListController:(NSString *)brandname {
- FKExploreListController *controller = [[FKExploreListController alloc] initWithSource:FKExploreListSourceKeyword];
- [controller.conditionManager addConditionWithType:FKExploreConditionTypeBrand
- itemID:nil
- value:brandname];
- [self pushViewController:controller];
- }
- - (void)pushTopicController:(NSString *)topicID {
- FKTopicController *controller = [[FKTopicController alloc] init];
- controller.topicId = topicID;
- [self pushViewController:controller];
- }
- - (void)pushTopicListController:(NSString *)itemID title:(NSString *)title {
- FKEntireCategoryController *controller = [[FKEntireCategoryController alloc] init];
- controller.segmentIndex = 2;
- controller.isShowLeftBarItem = YES;
- [self pushViewController:controller];
- }
- - (void)pushViewController:(UIViewController *)controller{
- if ([FLControllerHelper currentController].navigationController && controller) {
- controller.hidesBottomBarWhenPushed = YES;
- [[FLControllerHelper currentController].navigationController pushViewController:controller animated:YES];
- }
- }
- #pragma mark - property
- - (UITableView *)tableView {
- if (_tableView == nil) {
- _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.sectionHeaderHeight = 0;
- _tableView.backgroundColor = UIColorFromRGB(0xf9f9f9);
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
-
- [_tableView registerClass:[FKOperationImageCell class] forCellReuseIdentifier:NSStringFromClass([FKOperationImageCell class])];
- [_tableView registerClass:[FKRecoIconListCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoIconListCell class])];
- [_tableView registerClass:[FKRecoNewsCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoNewsCell class])];
- [_tableView registerClass:[FKRecoHeaderCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoHeaderCell class])];
- [_tableView registerClass:[FKRecoLimitBuyCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoLimitBuyCell class])];
- [_tableView registerClass:[FKRecoPromotionLimitCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoPromotionLimitCell class])];
- [_tableView registerClass:[FKRecoPromotionCategoryCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoPromotionCategoryCell class])];
- [_tableView registerClass:[FKRecoOfficalActivityCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoOfficalActivityCell class])];
- [_tableView registerClass:[FKRecoBrandListCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoBrandListCell class])];
- [_tableView registerClass:[FKExploreTableViewCell class] forCellReuseIdentifier:NSStringFromClass([FKExploreTableViewCell class])];
-
- [_tableView registerClass:[FKRecoUserRecoProductCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoUserRecoProductCell class])];
- [_tableView registerClass:[FKRecoScanRecoProductCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoScanRecoProductCell class])];
- [_tableView registerClass:[FKRecoHotProductCell class] forCellReuseIdentifier:NSStringFromClass([FKRecoHotProductCell class])];
-
- [self initRefreshControlWithTableView:_tableView];
-
- if (@available(iOS 11.0, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- }
- return _tableView;
- }
- - (FKAdvertiseViewCell*)advertiseView {
- if (!_advertiseView) {
- _advertiseView = [[FKAdvertiseViewCell alloc] initWithStyle:UITableViewCellStyleDefault
- reuseIdentifier:nil];
- _advertiseView.backgroundColor = UIColorFromRGB(0xf4f4f4);
- _advertiseView.delegate = self;
- }
- return _advertiseView;
- }
- - (UIButton *)backTopBtn {
- if (_backTopBtn == nil) {
- _backTopBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_backTopBtn setImage:[UIImage imageNamed:@"fanhuidingbu"] forState:UIControlStateNormal];
- [_backTopBtn addTarget:self
- action:@selector(backTopAction:)
- forControlEvents:UIControlEventTouchUpInside];
- _backTopBtn.hidden = YES;
- }
- return _backTopBtn;
- }
- @end
|