// // TPFrontPageController.m // ThePaperHD // // Created by scar1900 on 15/1/4. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "TPFrontPageController.h" #import "coverFlowView.h" #import "frontPageDataMethod.h" #import "frontPageCell.h" #import "channelListHomeController.h" #import "columnListController.h" #import "detailContentHomeController.h" #import "loginPopUpController.h" #import "topicHomeController.h" #import "settingNaviController.h" #import "hotAskListHomeController.h" #import "customFlowLayout.h" #import "ImageContentController.h" #import "TPLiveHomeController.h" #import "TPcontentWebController.h" #import "hotAnswerDetailController.h" #import "updateContent.h" #import "KGModal.h" #import "orderCenterController.h" #import "orderController.h" #import "topicListController.h" #import "otherPersonHomepageController.h" #import "topicContentController.h" #import "topicListHomeController.h" #define topicViewTag 3000 @interface TPFrontPageController () { CAGradientLayer *gradientLayer; NSMutableArray *coverFlowDataList; NSMutableArray *collectList; NSMutableArray *PoliticsList; NSMutableArray *EconomyList; NSMutableArray *InsightsList; NSMutableArray *LifeList; NSMutableArray *topicList; NSMutableArray *hotAnswerList; NSMutableArray *myPaperList; NSMutableArray *finishedList; CGFloat tablePadding; BOOL isFirstInFrontPage; NSInteger remoteFlag; NSMutableArray *reloadFlagList; } @property(nonatomic, strong)coverFlowView *coverFlow; @property(nonatomic, strong)NSMutableArray *dataList; @property(nonatomic, strong)settingNaviController *settingController; @property(nonatomic, strong)orderCenterController *orderCenterVC; @property(nonatomic, strong)hotAskListHomeController *hotAskVC; @property(nonatomic, strong)UIView *topicView; @end @implementation TPFrontPageController @synthesize dataList = _dataList; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. remoteFlag = 0; self.view.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor]; self.navigationController.navigationBarHidden = NO; tablePadding = 64; self.tableView.frame = CGRectMake(0,tablePadding, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)-tablePadding); self.tableView.tableHeaderView = self.coverFlow; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 20)]; self.tableView.tableFooterView = footView; [self configCanRefresh:YES canLoad:NO]; isFirstInFrontPage = YES; //【需求】后台修改的频道名字等信息,下次启动需要刷新(BUG:4586) // NSMutableArray *channalList = [TPUserDefault instance].channldataList; coverFlowDataList = [NSMutableArray array]; // if (channalList.count == 0) { collectList = [NSMutableArray array]; PoliticsList = [NSMutableArray array]; EconomyList = [NSMutableArray array]; InsightsList = [NSMutableArray array]; LifeList = [NSMutableArray array]; topicList = [NSMutableArray array]; hotAnswerList = [NSMutableArray array]; myPaperList = [NSMutableArray array]; finishedList = [NSMutableArray array]; [self getChannelList]; // }else { // [self getOfflineList]; // [self manualRefresh]; // } [self.tableView becomeFirstResponder]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToDetailContent:) name:PUSHTODETAILCONTENT object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToTopicInfoContent:) name:PUSHTOTOPICDETAILCONTENT object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentHotAsk:) name:PRESENTHOTASK object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(login) name:HAVELOGIN object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOut) name:HAVELOGINOUT object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshFrontPage) name:NEEDREFRESHENTERFORGROUND object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToSetting:) name:PUSHTOSETTINGS object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popAnswerDetail:) name:POPANSWERDETAIL object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popUpOrderCenter:) name:POPUPORDERCENTER object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAfterOpenNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.navigationBarHidden = NO; self.navigationController.navigationBar.translucent=YES; if (isNotIOS7) { self.tableView.refreshControl.originalContentInsectY = 44; } if (isIOS7) { if ([[TPUserDefault instance].isNightMode intValue] == 1) { self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0x4c4c4c"]; }else { self.navigationController.navigationBar.barTintColor = [UIColor whiteColor]; } }else { if ([[TPUserDefault instance].isNightMode intValue] == 1) { self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:@"0x4c4c4c"]; }else { self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; } } if (_topicView) { [self.topicView removeFromSuperview]; } [self.navigationController.navigationBar addSubview:self.topicView]; CGFloat paddingX = 118; if (isNotIOS7) { paddingX = 110; } self.topicView.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-paddingX, 0, 65, CGRectGetHeight(self.navigationController.navigationBar.bounds)); if (self.orderCenterVC && self.orderCenterVC.isNeedHold) { __weak typeof(self) Self = self; [self presentController:self.orderCenterVC animated:YES presentSize:orderCenterPopSize completion:^{ } dismiss:^{ if (!Self.orderCenterVC.isNeedHold) { Self.orderCenterVC = nil; [Self refreshFrontPage]; AppDelegate *appDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate]; YRSideViewController *sideController=[appDelegate sideViewController]; orderController *orderVC = (orderController*)sideController.leftViewController; //【适配性】ios8和9订阅页:如此操作后进入订阅页必定错乱(bug:6077) if (orderVC.nodeInfoController.nodeList && orderVC.nodeInfoController.nodeList.count > 0) { [orderVC viewWillAppear:YES]; } } }]; return; } if ([TPUserDefault instance].updateInfo && ![TPUserDefault instance].pushBO) { NSDictionary *updateInfo = [TPUserDefault instance].updateInfo; NSString *latestVersion = updateInfo[@"versionName"]; NSString *currentVersion = [TPUserDefault instance].appVersion; NSString *ignoreVersion = [TPUserDefault instance].ignoreVersion; if (isNeedUpdate(latestVersion, currentVersion, ignoreVersion)) { NSArray *contentList = updateInfo[@"updateDesc"]; __block CGFloat totalHeight=0; [contentList enumerateObjectsUsingBlock:^(NSString* desc, NSUInteger idx, BOOL *stop) { CGFloat height = heightForString(desc, appFont(13, NO), 540/2, NSLineBreakByWordWrapping)+15/2; totalHeight = totalHeight+height; }]; CGFloat height = 158/2 + totalHeight + 175/2; updateContent *updateView = [[updateContent alloc]initWithFrame:CGRectMake(0, 0, 640/2-20 , height)]; updateView.updateInfo = updateInfo; [[KGModal sharedInstance]showWithContentView:updateView completion:^{ }]; } } __weak typeof(self) Self = self; if (self.hotAskVC && self.hotAskVC.isNeedHold) { [self presentController:self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{ } dismiss:^{ if (!Self.hotAskVC.isNeedHold) { Self.hotAskVC = nil; } }]; } } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:YES]; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { if (self.view.bounds.size.width > self.view.bounds.size.height) { self.view.frame =CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); } }else { if (self.view.bounds.size.width < self.view.bounds.size.height) { self.view.frame =CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); } } self.tableView.frame = CGRectMake(0,tablePadding, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)-tablePadding); //首页,精选等频道名称感觉点击热区较小,难以点击(bug:4745) // self.coverFlow.frame = CGRectMake(0,0, CGRectGetWidth(self.tableView.bounds), 780/2); self.coverFlow.frame = CGRectMake(0,0, CGRectGetWidth(self.tableView.bounds), 750/2); [self addGradientLayer]; self.coverFlow.orientation = orientation; if (!isFirstInFrontPage) { [self endRefresh]; } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.topicView removeFromSuperview]; } - (void)actionOfNightMode { [self addGradientLayer]; self.view.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor]; if (isIOS7) { if ([[TPUserDefault instance].isNightMode intValue] == 1) { self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0x4c4c4c"]; }else { self.navigationController.navigationBar.barTintColor = [UIColor whiteColor]; } TPWindow *window = (TPWindow*)[[UIApplication sharedApplication]keyWindow]; [window setMaskAfterOpenNightMode]; }else { if ([[TPUserDefault instance].isNightMode intValue] == 1) { self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:@"0x4c4c4c"]; }else { self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; } TPWindow *window = (TPWindow*)[[UIApplication sharedApplication]keyWindow]; [window setNoNightModeMask]; } [self.tableView reloadData]; UIButton *topicBtn = (UIButton*)[self.topicView viewWithTag:topicViewTag+1]; [topicBtn setTitleColor:[UIColor colorWithHexString:TextBlack] forState:UIControlStateNormal]; [topicBtn setTitleColor:[UIColor colorWithHexString:TextLightGray] forState:UIControlStateHighlighted]; UIView *topicLine = [self.topicView viewWithTag:topicViewTag+2]; topicLine.backgroundColor = [UIColor colorWithHexString:TextBlack]; } - (UIView*)topicView { if (!_topicView) { _topicView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)-118, 0, 65, CGRectGetHeight(self.navigationController.navigationBar.bounds))]; _topicView.backgroundColor = [UIColor clearColor]; UIButton *topicBtn = [UIButton buttonWithType:UIButtonTypeCustom]; topicBtn.backgroundColor = [UIColor clearColor]; [topicBtn setTitle:@"问吧" forState:UIControlStateNormal]; [topicBtn setTitleColor:[UIColor colorWithHexString:TextBlack] forState:UIControlStateNormal]; [topicBtn setTitleColor:[UIColor colorWithHexString:TextLightGray] forState:UIControlStateHighlighted]; topicBtn.frame = _topicView.bounds; topicBtn.titleLabel.font = appFont(18, NO); [topicBtn addTarget:self action:@selector(goToTopicCenter:) forControlEvents:UIControlEventTouchUpInside]; [_topicView addSubview:topicBtn]; topicBtn.tag = topicViewTag + 1; CGFloat width = 1; if (ISNotRETINA) { width = 2; } UIView *topicLine = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetWidth(_topicView.bounds)-width, CGRectGetHeight(_topicView.bounds)/2-10, width, 20)]; topicLine.backgroundColor = [UIColor colorWithHexString:TextBlack]; [_topicView addSubview:topicLine]; topicLine.tag = topicViewTag + 2; } return _topicView; } //获取首页全量数据 - (void)askChannelContentInfo { collectList = [NSMutableArray array]; PoliticsList = [NSMutableArray array]; EconomyList = [NSMutableArray array]; InsightsList = [NSMutableArray array]; LifeList = [NSMutableArray array]; topicList = [NSMutableArray array]; hotAnswerList = [NSMutableArray array]; myPaperList = [NSMutableArray array]; finishedList = [NSMutableArray array]; coverFlowDataList = [NSMutableArray array]; NSMutableArray *channalList = [TPUserDefault instance].channldataList; if (!channalList || channalList.count == 0) { collectList = [NSMutableArray array]; PoliticsList = [NSMutableArray array]; EconomyList = [NSMutableArray array]; InsightsList = [NSMutableArray array]; LifeList = [NSMutableArray array]; topicList = [NSMutableArray array]; hotAnswerList = [NSMutableArray array]; myPaperList = [NSMutableArray array]; finishedList = [NSMutableArray array]; [self getChannelList]; }else { [channalList enumerateObjectsUsingBlock:^(NSDictionary* dic, NSUInteger idx, BOOL *stop) { NSString* nodeID = dic[@"nodeId"]; [self getChannelContentListData:nodeID]; }]; } } - (void)addGradientLayer { [gradientLayer removeFromSuperlayer]; gradientLayer = nil; gradientLayer = [CAGradientLayer layer]; gradientLayer.borderWidth = 0; gradientLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.tableView.bounds), 780/2-50); gradientLayer.colors = @[(id)[UIColor colorWithHexString:@"0xbfbfbf"].CGColor,(id)[UIColor colorWithHexString:BackGrayGroundColor].CGColor]; [self.view.layer insertSublayer:gradientLayer atIndex:0]; } - (coverFlowView*)coverFlow { if (!_coverFlow) { _coverFlow = [[coverFlowView alloc]initWithFrame:CGRectMake(0,0, CGRectGetWidth(self.tableView.bounds), 780/2-25)]; _coverFlow.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; _coverFlow.delegate = self; } return _coverFlow; } - (settingNaviController*)settingController { if (!_settingController) { _settingController = [[settingNaviController alloc]init]; [self addChildViewController:_settingController]; _settingController.delegate = self; _settingController.view.frame = CGRectMake(0,64, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)); if (isNotIOS7) { _settingController.view.frame = CGRectMake(0,44, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)); } _settingController.view.hidden = YES; [self.view addSubview:_settingController.view]; } return _settingController; } - (void)setDataList:(NSMutableArray *)list { if (!_dataList && list.count == 0) { _dataList = list; return; } _dataList = list; isFirstInFrontPage = NO; reloadFlagList = [NSMutableArray array]; [list enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [reloadFlagList addObject:@"1"]; }]; [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ [self.tableView reloadData]; } completion:^(BOOL finished) { }]; } #pragma mark - remote method - (void)getChannelList { NSDictionary *dic = @{@"type":@"1"}; __weak typeof(self) Self = self; [Remote doJsonActionWithBlock:0 requestUrl:allNodeListURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { [Self endRefresh]; NSArray *nodeArray = responseData[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSString *nodeId = obj[@"nodeId"]; NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:obj]; [dic setValue:nodeId forKey:@"nodeId"]; NSString *color = dic[@"color"]; color = [color substringWithRange:NSMakeRange(1, 6)]; color = [NSString stringWithFormat:@"0x%@",color]; [dic setValue:color forKey:@"color"]; [tempArray addObject:dic]; }]; if (tempArray.count == 7) { [TPUserDefault instance].channldataList = tempArray; [Self manualRefresh]; } }else { ShowTextMessage(message); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [Self endRefresh]; }); } }]; } - (void)getOfflineList { NSDictionary *dic = @{@"type":@"4"}; [Remote doJsonActionWithBlock:1 requestUrl:allNodeListURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { NSArray *nodeArray = responseData[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { nodeObjectBO *nodeBO = setJsonDicToDataModel(obj, [nodeObjectBO class]); [tempArray addObject:nodeBO]; }]; [TPUserDefault instance].offlineList = [NSArray arrayWithArray:tempArray]; }else { ShowTextMessage(message); } }]; } - (void)getChannelContentListData:(NSString*)nodeId { if (![TPUserDefault instance].userBO && [nodeId isEqualToString:@"-1"]) { return; } remoteFlag++; // TPLOG(@"=========%ld========",remoteFlag); if (!isBlankString(nodeId)){ NSDictionary *dic = @{@"n":nodeId}; [Remote doJsonAction:[nodeId intValue] requestUrl:channelNodeListURL parameter:dic delegate:self]; } } -(void)gotoPersonInfo:(commentObjectVO *)comment{ __weak typeof(self) Self = self; [self.hotAskVC dismissControllerAnimated:YES completion:^{ otherPersonHomepageController *otherVC = [otherPersonHomepageController new]; otherVC.commentBo = comment; [Self.navigationController pushViewController:otherVC animated:YES]; }]; } #pragma mark - navigation bar tap - (void)naviBarTapHandler:(UITapGestureRecognizer*)tap { [self.tableView setContentOffset:CGPointZero animated:YES]; } #pragma mark - status bar orientChanged - (void)statusBarOrientationChange:(NSNotification *)notification { UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { if (self.view.bounds.size.width > self.view.bounds.size.height) { self.view.frame =CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); } }else { if (self.view.bounds.size.width < self.view.bounds.size.height) { self.view.frame =CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); } } self.coverFlow.frame = CGRectMake(0,0, CGRectGetWidth(self.tableView.bounds), 780/2); [self addGradientLayer]; self.coverFlow.orientation = orientation; CGFloat paddingX = 118; if (isNotIOS7) { paddingX = 110; } self.topicView.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-paddingX, 0, 65, CGRectGetHeight(self.navigationController.navigationBar.bounds)); } #pragma mark - tableView delegate and datasource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataList.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 550.f/2; } - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSMutableArray *dataArray = self.dataList[indexPath.row]; NSDictionary *infoDic = [dataArray lastObject]; NSString *nodeId = infoDic[@"nodeId"]; NSString* frontPageCellIdentifer = [NSString stringWithFormat:@"frontPageCellIdentifer cell:%@",nodeId]; frontPageCell* cell = (frontPageCell*)[table dequeueReusableCellWithIdentifier:frontPageCellIdentifer]; if (nil == cell) { cell = [[frontPageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:frontPageCellIdentifer]; cell.delegate = self; cell.indexPath = indexPath; } NSString *flag = reloadFlagList[indexPath.row]; if ([flag intValue] == 1) { cell.channelInfoDataList = dataArray; flag = @"0"; [reloadFlagList replaceObjectAtIndex:indexPath.row withObject:flag]; } return cell; } #pragma mark - cell delegate - (void)clickMoreInfo:(NSDictionary *)infoDic { NSString *nodeId = infoDic[@"nodeId"]; if (isBlankString(nodeId)) { customFlowLayout *layout = nil; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; CGSize itemSize = CGSizeZero; layout= [[customFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 35; layout.minimumInteritemSpacing = 35; CGFloat width = 0; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { width = (self.view.bounds.size.width-35*3)/2; }else { width = (self.view.bounds.size.width-35*4)/3; } CGFloat viewScale = width/600; itemSize = CGSizeMake(width, 450*viewScale); layout.itemSize = itemSize; // topicListController *topicController = [[topicListController alloc]initWithCollectionViewLayout:layout]; topicListHomeController *topicController = [[topicListHomeController alloc]initWithCollectionViewLayout:layout]; [self.navigationController pushViewController:topicController animated:YES]; }else { __block NSInteger index; [[TPUserDefault instance].channldataList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj[@"nodeId"] intValue] == [infoDic[@"nodeId"] intValue]) { index = idx; } }]; channelListHomeController *vc = channelListHomeController.new; vc.channelIndex = index; if ([TPUserDefault instance].userBO && myPaperList.count>0 && [myPaperList[0] isKindOfClass:[listContObjectVO class]]) { vc.isOrder = YES; }else vc.isOrder = NO; [self.navigationController pushViewController:vc animated:YES]; } } - (void)pushGotoNodeListPage:(listContObjectVO *)listBO infoDic:(NSDictionary *)infoDic{ customFlowLayout *layout = nil; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; CGSize itemSize = CGSizeZero; layout= [[customFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 35; layout.minimumInteritemSpacing = 35; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { CGFloat width = (self.view.bounds.size.width-35*3)/2; itemSize = CGSizeMake(width, 470/2); }else { CGFloat width = (self.view.bounds.size.width-35*4)/3; itemSize = CGSizeMake(width, 446/2); } layout.itemSize = itemSize; columnListController *vc = [[columnListController alloc]initWithCollectionViewLayout:layout]; vc.listBO = listBO; [self.navigationController pushViewController:vc animated:YES]; layout = nil; } - (void)leftRefreshSuccess:(NSIndexPath *)indexPath newDataList:(NSMutableArray *)list { NSDictionary *dic = [self.dataList[indexPath.row] lastObject]; [list addObject:dic]; [self saveDifferentChannelInfo:list withNodeId:dic[@"nodeId"]]; [self.dataList replaceObjectAtIndex:indexPath.row withObject:list]; NSArray *indexList = [NSArray arrayWithObject:indexPath]; [reloadFlagList replaceObjectAtIndex:indexPath.row withObject:@"1"]; [self.tableView reloadRowsAtIndexPaths:indexList withRowAnimation:UITableViewRowAnimationNone]; } - (void)popUpLoginWindow { loginPopUpController *loginVC = loginPopUpController.new; [self presentController:loginVC animated:YES presentSize:loginPopUpSize completion:^{ }]; } - (void)popUpOrderCenter:(NSNotification*)noti { if (!self.orderCenterVC) { self.orderCenterVC = orderCenterController.new; self.orderCenterVC.delegate = self; // self.orderCenterVC.delegate = self; } __weak typeof(self) Self = self; [self presentController:self.orderCenterVC animated:YES presentSize:orderCenterPopSize completion:^{ } dismiss:^{ if (!Self.orderCenterVC.isNeedHold) { Self.orderCenterVC = nil; [Self refreshFrontPage]; AppDelegate *appDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate]; YRSideViewController *sideController=[appDelegate sideViewController]; orderController *orderVC = (orderController*)sideController.leftViewController; //【适配性】ios8和9订阅页:如此操作后进入订阅页必定错乱(bug:6077) if (orderVC.nodeInfoController.nodeList && orderVC.nodeInfoController.nodeList.count > 0) { [orderVC viewWillAppear:YES]; } } }]; } - (void)refreshAfterOpenNightMode:(NSNotification*)noti { [self actionOfNightMode]; } #pragma mark - remote delegate and dataSource - (void)startWaitCursor:(int)actionTag { } - (void)stopWaitCursor:(int)actionTag { } #pragma mark - remote delegate - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { NSString *nodeId = responsData[@"nodeId"]; if (![nodeId isEqualToString:@"-3"]) { [self getRefreshDataFromDic:responsData sourceKey:@"contList" contentClass:[listContObjectVO class] nodeId:nodeId actionTag:actionTag]; }else { [self getRefreshDataFromDic:responsData sourceKey:@"topicList" contentClass:[TopicInfoBO class] nodeId:nodeId actionTag:actionTag]; } // [frontPageDataMethod saveRemoteDataToCoreData:responsData nodeId:nodeId]; } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{ if (actionTag == -1 && [code intValue] == 6) { [self saveDifferentChannelInfo:[NSMutableArray array] withNodeId:@"-1"]; [finishedList addObject:@"-1"]; if (finishedList.count == remoteFlag) { self.coverFlow.dataList = coverFlowDataList; self.dataList = [NSMutableArray array]; NSMutableArray *tempArray = [NSMutableArray array]; NSMutableArray *channalList = [TPUserDefault instance].channldataList; [channalList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [self saveDataListAfterRemoteActionWithNodeInfo:obj inArray:tempArray]; }]; self.dataList = tempArray; [[UIApplication sharedApplication]beginIgnoringInteractionEvents]; [self endRefresh:nil completion:^{ //iPad中订阅一个栏目后返回到首页进行刷新,再取消订阅返回首页刷新,反复几次就会出现首页一直处于刷新状态(bug:4906) remoteFlag = 0; // TPLOG(@"*******failed endrefresh: %ld********",remoteFlag); [[UIApplication sharedApplication]endIgnoringInteractionEvents]; }]; } }else { ShowTextMessage(message); __weak typeof(self) weakSelf = self; [[UIApplication sharedApplication]beginIgnoringInteractionEvents]; [self endRefresh:nil completion:^{ //iPad中订阅一个栏目后返回到首页进行刷新,再取消订阅返回首页刷新,反复几次就会出现首页一直处于刷新状态(bug:4906) remoteFlag = 0; // TPLOG(@"*******failed endrefresh: %ld********",remoteFlag); [weakSelf.tableView setContentOffset:CGPointZero animated:YES]; [[UIApplication sharedApplication]endIgnoringInteractionEvents]; }]; } tablePadding = 0; self.tableView.frame = CGRectMake(0,tablePadding, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)-tablePadding); } - (void)getRefreshDataFromDic:(NSDictionary*)sourceDic sourceKey:(NSString*)sourceKey contentClass:(Class)contentClass nodeId:(NSString*)nodeId actionTag:(int)actionTag{ NSArray *contList = sourceDic[sourceKey]; if (contList) { NSMutableArray *tempArray = [NSMutableArray array]; [contList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { id contentBO = setJsonDicToDataModel(obj, contentClass); if ([contentBO isKindOfClass:[listContObjectVO class]]) { listContObjectVO *listContentBO = contentBO; if (!listContentBO.title && [listContentBO.cardMode intValue] != 1 && ([listContentBO.cardMode intValue] == 2 || [listContentBO.cardMode intValue] == 3)) { [tempArray addObject:contentBO]; } //coverflow 数据源构建 if(![nodeId isEqualToString:@"-2"] && ![nodeId isEqualToString:@"-1"]) { if ([listContentBO.cardMode intValue] == 1) { listContentBO.parentNodeId = nodeId; [coverFlowDataList addObject:listContentBO]; } } }else if ([contentBO isKindOfClass:[TopicInfoBO class]]) { TopicInfoBO *topicBO = contentBO; if(isPad){ if (![topicBO.forwordType isEqualToString:@"4"]) { NSString *desc = obj[@"description"]; topicBO.desc = desc; [tempArray addObject:topicBO]; } }else{ NSString *desc = obj[@"description"]; topicBO.desc = desc; [tempArray addObject:topicBO]; } }else { [tempArray addObject:contentBO]; } }]; [self saveDifferentChannelInfo:tempArray withNodeId:nodeId]; [finishedList addObject:nodeId]; [self actionAfterRemoteFinish]; } } - (void)actionAfterRemoteFinish{ // TPLOG(@"%ld",remoteFlag); if (finishedList.count == remoteFlag) { self.coverFlow.dataList = coverFlowDataList; self.dataList = [NSMutableArray array]; NSMutableArray *tempArray = [NSMutableArray array]; NSMutableArray *channalList = [TPUserDefault instance].channldataList; [channalList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [self saveDataListAfterRemoteActionWithNodeInfo:obj inArray:tempArray]; if (idx == 4) { [self saveDataListAfterRemoteActionWithNodeInfo:nil inArray:tempArray]; } }]; self.dataList = tempArray; __weak typeof(self) weakSelf = self; [[UIApplication sharedApplication]beginIgnoringInteractionEvents]; [self endRefresh:nil completion:^{ remoteFlag = 0;//4601: ipad升级后,首页慢慢刷新会一直处在刷新的状态 // TPLOG(@"********%ld********",remoteFlag); tablePadding = 0; weakSelf.tableView.frame = CGRectMake(0,tablePadding, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)-tablePadding); [TPUserDefault instance].isFirstIntoApp = @"2"; [[UIApplication sharedApplication]endIgnoringInteractionEvents]; }]; } } - (void)saveDifferentChannelInfo:(NSMutableArray *)dataArray withNodeId:(NSString*)nodeId { // if (isBlankString(nodeId)) { // topicList = [NSMutableArray arrayWithArray:dataArray]; // }else { if ([nodeId isEqualToString:@"25949"]) { collectList = [NSMutableArray arrayWithArray:dataArray]; }else if ([nodeId isEqualToString:@"25950"]) { PoliticsList = [NSMutableArray arrayWithArray:dataArray]; }else if ([nodeId isEqualToString:@"25951"]) { EconomyList = [NSMutableArray arrayWithArray:dataArray]; }else if ([nodeId isEqualToString:@"25952"]) { InsightsList = [NSMutableArray arrayWithArray:dataArray]; }else if ([nodeId isEqualToString:@"25953"]) { LifeList = [NSMutableArray arrayWithArray:dataArray]; }else if ([nodeId isEqualToString:@"-3"]) { [dataArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { TopicInfoBO *infoBo = obj; if (idx <10) { [topicList addObject:infoBo]; } }]; // topicList = [NSMutableArray arrayWithArray:dataArray]; }else { myPaperList = [NSMutableArray arrayWithArray:dataArray]; } // } } - (void)saveDataListAfterRemoteActionWithNodeInfo:(NSDictionary*)dic inArray:(NSMutableArray*)tmpList{ // if (dic) { if ([dic[@"nodeId"] isEqualToString:@"25949"]) { [collectList addObject:dic]; [tmpList addObject:collectList]; }else if ([dic[@"nodeId"] isEqualToString:@"25950"]) { [PoliticsList addObject:dic]; [tmpList addObject:PoliticsList]; }else if ([dic[@"nodeId"] isEqualToString:@"25951"]) { [EconomyList addObject:dic]; [tmpList addObject:EconomyList]; }else if ([dic[@"nodeId"] isEqualToString:@"25952"]) { [InsightsList addObject:dic]; [tmpList addObject:InsightsList]; }else if ([dic[@"nodeId"] isEqualToString:@"25953"]) { [LifeList addObject:dic]; [tmpList addObject:LifeList]; }else if ([dic[@"nodeId"] isEqualToString:@"-2"]) { [hotAnswerList addObject:dic]; [tmpList addObject:hotAnswerList]; }else if ([dic[@"nodeId"] isEqualToString:@"-1"]){ [myPaperList addObject:dic]; [tmpList addObject:myPaperList]; }else if ([dic[@"nodeId"] isEqualToString:@"-3"]){ [topicList addObject:dic]; [tmpList addObject:topicList]; } // }else { // NSDictionary *topicDic = @{@"name":@"问吧",@"enname":@"Interview",@"nodeId":@""}; // [topicList addObject:topicDic]; // [tmpList addObject:topicList]; // } } #pragma mark - pull refresher - (void)pullRefreshHandler { [self askChannelContentInfo]; } - (void)pushToDetailContent:(NSNotification*)noti { NSDictionary *dic = noti.userInfo; id data = dic[@"listContentData"]; if ([data isKindOfClass:[listContObjectVO class]]) { listContObjectVO *listItem = data; pushContentWithListContentObject(self.navigationController, listItem); }else if ([data isKindOfClass:[commentObjectVO class]]) { commentObjectVO *commentBO = data; pushContentWithCommentBO(self.navigationController, commentBO); }else if ([data isKindOfClass:[TopicInfoBO class]]) { TopicInfoBO *topicBO = data; pushTopicPageWithTopicInfo(self.navigationController, topicBO); } } -(void)pushToTopicInfoContent:(NSNotification*)noti{ NSDictionary *dic = noti.userInfo; id data = dic[@"listContentData"]; commentObjectVO *commentBO = (commentObjectVO *)data; TopicInfoBO *topic = [[TopicInfoBO alloc] init]; topic.topicId = commentBO.contId; NSMutableDictionary *topicHost = commentBO.answerList[0]; userBO *user = setJsonDicToDataModel(topicHost[@"userInfo"], [userBO class]); topicContentController *topicControllerVC = [[topicContentController alloc]init]; if (topic) { topicControllerVC.preTopicInfo = topic; topicControllerVC.creatUser = user; } [self.navigationController pushViewController:topicControllerVC animated:YES]; } - (void)presentHotAsk:(NSNotification*)noti { if (!self.hotAskVC) { self.hotAskVC = [[hotAskListHomeController alloc]init]; self.hotAskVC.commentBO = noti.userInfo[@"data"]; self.hotAskVC.commentOT = self.hotAskVC.commentBO.objectType; self.hotAskVC.delegate = self; } __weak typeof(self) Self = self; [self presentController:self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{ }dismiss:^{ if (!Self.hotAskVC.isNeedHold) { Self.hotAskVC = nil; } }tapHandler:^{ if (Self.hotAskVC.writeVC) { [Self.hotAskVC.writeVC closeKeyBoard]; } }]; } //选择coverflow - (void)didSelectOneFlow:(listContObjectVO *)listBO { pushContentWithListContentObject(self.navigationController, listBO); } - (void)login { [self manualRefresh]; } - (void)loginOut { [self manualRefresh]; } - (void)popAnswerDetail:(NSNotification*)noti { NSDictionary *dic = noti.userInfo; commentObjectVO *comment = dic[@"commentData"]; UIColor *color = dic[@"color"]; CGFloat contentNameHeight = heightForString(comment.contName, appFont(11, NO), 850/2, NSLineBreakByWordWrapping); CGFloat askHeight = heightForString(comment.content, appFont(20, YES), 850/2, NSLineBreakByWordWrapping); NSDictionary *answerDic = comment.answerList[0]; commentObjectVO *answerBO = setJsonDicToDataModel(answerDic, [commentObjectVO class]); CGFloat answerHeight = heightForString(answerBO.content, appFont(14, NO), 350, NSLineBreakByWordWrapping)+35; if (answerHeight<50) { answerHeight = 50; } if (answerHeight>320) { answerHeight = 320; } hotAnswerDetailController *hotAnswerVC = hotAnswerDetailController.new; hotAnswerVC.contentNameHeight = contentNameHeight; hotAnswerVC.askHeight = askHeight; hotAnswerVC.answerHeight = answerHeight; hotAnswerVC.commentBO = comment; hotAnswerVC.delegate = self; hotAnswerVC.backColor = color; CGSize size = CGSizeMake(966/2,110+16+contentNameHeight+15+askHeight+25+answerHeight+15); [self presentController:hotAnswerVC animated:YES presentSize:size completion:^{ }]; } #pragma mark - hot ask list delegate - (void)goToOriginContent:(objInfoBO *)commentBO presentedController:(TPHttpController *)presentedController{ __weak typeof(self) Self = self; [presentedController dismissControllerAnimated:YES completion:^{ pushContentWithObjInfo(Self.navigationController, commentBO); }]; } -(void)hotAskHomeToTopic:(TopicInfoBO *)topic user:(userBO *)user{ __weak typeof(self) Self = self; [self.hotAskVC dismissControllerAnimated:YES completion:^{ if (!Self.hotAskVC.isNeedHold) { Self.hotAskVC = nil; } topicContentController *topicControllerVC = [[topicContentController alloc]init]; if (topic) { topicControllerVC.preTopicInfo = topic; topicControllerVC.creatUser = user; } [Self.navigationController pushViewController:topicControllerVC animated:YES]; }]; } #pragma mark - answer detail delegate - (void)answerDetailGoToOriginContent:(commentObjectVO *)commentBO presentedController:(TPHttpController *)presentedController { __weak typeof(self) Self = self; [presentedController dismissControllerAnimated:YES completion:^{ pushContentWithCommentBO(Self.navigationController, commentBO); }]; } - (void)goToAskDetail:(commentObjectVO *)comment presentedController:(TPHttpController *)presentedController { __weak typeof(self) Self = self; [presentedController dismissControllerAnimated:YES completion:^{ if (Self.hotAskVC) { Self.hotAskVC = nil; } Self.hotAskVC = [[hotAskListHomeController alloc]init]; Self.hotAskVC.commentBO = comment; Self.hotAskVC.delegate = Self; [Self presentController:Self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{ }dismiss:^{ }tapHandler:^{ if (Self.hotAskVC.writeVC) { [Self.hotAskVC.writeVC closeKeyBoard]; } }]; }]; } #pragma mark - handler with refreshFrontPage //进入后台后回到前台的间隔时间大于一小时 - (void)refreshFrontPage { TPLOG(@"time to refresh frontPage"); [self manualRefresh]; } #pragma mark - call setting - (void)pushToSetting:(NSNotification*)noti{ if (!noti.object) { if (self.settingController.view.hidden) { self.settingController.view.hidden = NO; [CoreAnimationEffect animationPushDown:self.settingController.view]; [self.settingController settingNaviBarAppear]; }else { self.settingController.view.hidden = YES; [CoreAnimationEffect animationPushUp:self.settingController.view]; } }else { NSString *type = noti.object; if ([type intValue] == 1) { if (!self.settingController.view.hidden) { self.settingController.view.hidden = YES; [CoreAnimationEffect animationPushUp:self.settingController.view]; } } } } #pragma mark - go to topic page //进入话题列表 - (void)goToTopicCenter:(UIButton*)btn { // customFlowLayout *layout = nil; // UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; // CGSize itemSize = CGSizeZero; // layout= [[customFlowLayout alloc]init]; // layout.scrollDirection = UICollectionViewScrollDirectionVertical; // layout.minimumLineSpacing = 35; // layout.minimumInteritemSpacing = 35; // // CGFloat width = 0; // if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { // width = (self.view.bounds.size.width-35*3)/2; // }else { // width = (self.view.bounds.size.width-35*4)/3; // } // CGFloat viewScale = width/600; // itemSize = CGSizeMake(width, 450*viewScale); // layout.itemSize = itemSize; //// topicListController *topicController = [[topicListController alloc]initWithCollectionViewLayout:layout]; // topicListHomeController *topicController = [[topicListHomeController alloc]initWithCollectionViewLayout:layout]; // [self.navigationController pushViewController:topicController animated:YES]; NSString *nodeId = @"-3"; if (isBlankString(nodeId)) { customFlowLayout *layout = nil; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; CGSize itemSize = CGSizeZero; layout= [[customFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 35; layout.minimumInteritemSpacing = 35; CGFloat width = 0; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { width = (self.view.bounds.size.width-35*3)/2; }else { width = (self.view.bounds.size.width-35*4)/3; } CGFloat viewScale = width/600; itemSize = CGSizeMake(width, 450*viewScale); layout.itemSize = itemSize; // topicListController *topicController = [[topicListController alloc]initWithCollectionViewLayout:layout]; topicListHomeController *topicController = [[topicListHomeController alloc]initWithCollectionViewLayout:layout]; [self.navigationController pushViewController:topicController animated:YES]; }else { __block NSInteger index; [[TPUserDefault instance].channldataList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj[@"nodeId"] intValue] == -3) { index = idx; } }]; channelListHomeController *vc = channelListHomeController.new; vc.channelIndex = index; if ([TPUserDefault instance].userBO && myPaperList.count>0 && [myPaperList[0] isKindOfClass:[listContObjectVO class]]) { vc.isOrder = YES; }else vc.isOrder = NO; [self.navigationController pushViewController:vc animated:YES]; } } #pragma mark - settingNaviDelegate - (void)clickToDismissSetting { self.settingController.view.hidden = YES; [CoreAnimationEffect animationPushUp:self.settingController.view]; } - (void)pushToNodeController:(nodeObjectBO *)nodeInfo { __weak typeof(self) Self = self; [self.orderCenterVC dismissControllerAnimated:YES completion:^{ customFlowLayout *layout = nil; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; CGSize itemSize = CGSizeZero; layout= [[customFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumLineSpacing = 35; layout.minimumInteritemSpacing = 35; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { CGFloat width = (self.view.bounds.size.width-35*3)/2; itemSize = CGSizeMake(width, 470/2); }else { CGFloat width = (self.view.bounds.size.width-35*4)/3; itemSize = CGSizeMake(width, 446/2); } layout.itemSize = itemSize; columnListController *vc = [[columnListController alloc]initWithCollectionViewLayout:layout]; vc.nodeObj = nodeInfo; [Self.navigationController pushViewController:vc animated:YES]; layout = nil; }]; } #pragma mark - dealloc - (void)dealloc { [[NSNotificationCenter defaultCenter]removeObserver:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end