// // nodeInfoController.m // ThePaperDemo // // Created by scar1900 on 14-9-30. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "nodeInfoController.h" #import "CoreAnimationEffect.h" #import "nodeInfoCell.h" #import "orderCenterController.h" #import "columnManagerController.h" #import "loginFrontPageController.h" #import "nodeTopicCell.h" #import "InterViewPageViewController.h" #import "AppDelegate.h" #import "TPMainPageViewController.h" @interface nodeInfoController() { BOOL isNodeSame; } @property(nonatomic,strong)UIView *orderBackView; @property(nonatomic,strong)UIButton *orderButton; @property(nonatomic,strong)UILabel *orderBackLabel; @end @implementation nodeInfoController @synthesize nodeList = _nodeList; @synthesize orderNodeBO = _orderNodeBO; @synthesize orderButton; @synthesize orderBackLabel; @synthesize isOpenDeleteMode; - (void)viewDidLoad { [super viewDidLoad]; isNodeSame = NO; self.view.backgroundColor = [UIColor clearColor]; isOpenDeleteMode = NO; // AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate]; // YRSideViewController *sideController=[delegate sideViewController]; // // __weak typeof(self) Self = self; // [sideController setRootViewMoveBlock:^(UIView *rootView, CGRect orginFrame, CGFloat xoffset) { // //使用简单的平移动画 // Self.collectionView.scrollEnabled = NO; // if (xoffset == 270) { // Self.collectionView.scrollEnabled = YES; // } // }]; } - (void)setNodeList:(NSMutableArray *)list { _nodeList = list; if (!_collectionView) { [self.view addSubview:self.collectionView]; } if (list.count == 0) { self.collectionView.hidden = YES; }else { self.collectionView.hidden = NO; } [self.collectionView reloadData]; if (!isNodeSame) { [self.collectionView setContentOffset:CGPointMake(0, 0) animated:NO]; [CoreAnimationEffect animationEaseOut:self.collectionView]; } /** * bug:5639(栏目导航页:订阅导航页,在滑动到下方进入一个栏目,返回,不要回到顶部) */ } - (UICollectionView*)collectionView { if (!_collectionView) { CGSize itemSize = CGSizeMake(CGRectGetWidth(self.view.bounds)/2, CGRectGetWidth(self.view.bounds)/2); UICollectionViewFlowLayout *layout= [[UICollectionViewFlowLayout alloc]init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 0; layout.itemSize = itemSize; _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout]; _collectionView.delegate = self; _collectionView.dataSource = self; _collectionView.clipsToBounds = YES; [_collectionView registerClass:[nodeInfoCell class] forCellWithReuseIdentifier:@"nodeCollectCellID"]; [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"addCollectCell"]; [_collectionView registerClass:[nodeTopicCell class] forCellWithReuseIdentifier:@"topicNodeCellID"]; _collectionView.allowsSelection = YES; _collectionView.scrollEnabled = YES; _collectionView.alwaysBounceVertical = YES; _collectionView.showsVerticalScrollIndicator= NO; _collectionView.showsHorizontalScrollIndicator= NO; // _collectionView.bounces = NO; _collectionView.delaysContentTouches = NO; [self.view addSubview:_collectionView]; [_collectionView makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); }]; } _collectionView.backgroundColor = [UIColor clearColor]; /** * bug:5071(夜间模式,在订阅导航页里拉动后,有白底) */ return _collectionView; } - (UIView*)orderBackView { if (!_orderBackView) { _orderBackView = [[UIView alloc]initWithFrame:self.view.bounds]; _orderBackView.hidden = NO; self.orderButton = [UIButton buttonWithType:UIButtonTypeCustom]; [self.orderButton setImage:Image(@"Button/orderButton.png") forState:UIControlStateNormal]; self.orderButton.frame = CGRectMake(CGRectGetWidth(_orderBackView.bounds)/2-50/2, CGRectGetHeight(_orderBackView.bounds)/2-75, 50, 50); [_orderBackView addSubview:self.orderButton]; self.orderBackLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(_orderBackView.bounds)/2-270/4, CGRectGetMaxY(self.orderButton.frame)+15, 270/2, 40)]; self.orderBackLabel.textAlignment = NSTextAlignmentLeft; self.orderBackLabel.textColor = [UIColor colorWithHexString:LINECOLOR]; self.orderBackLabel.lineBreakMode = NSLineBreakByWordWrapping; self.orderBackLabel.numberOfLines = 0; [_orderBackView addSubview:self.orderBackLabel]; } _orderBackView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; return _orderBackView; } - (void)setOrderNodeBO:(nodeObjectBO *)nodeBO { if (_orderNodeBO && [_orderNodeBO.nodeId intValue] == [nodeBO.nodeId intValue]) { isNodeSame = YES; }else { isNodeSame = NO; } _orderNodeBO = nodeBO; if (!_orderBackView) { [self.view addSubview:self.orderBackView]; } if ([nodeBO.nodeId isEqualToString:@"-1"]) { self.orderBackView.hidden = NO; self.orderBackLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); if ([nodeBO.myOrderStatus intValue] == 2 && ![TPUserDefault instance].userBO) { [self.orderButton removeTarget:self action:@selector(jumpToOrder:) forControlEvents:UIControlEventTouchUpInside]; [self.orderButton addTarget:self action:@selector(loginHandler:) forControlEvents:UIControlEventTouchUpInside]; self.orderBackLabel.text = @"登录后,马上添加感兴趣的栏目到这里"; }else if ([nodeBO.myOrderStatus intValue] == 3) { [self.orderButton removeTarget:self action:@selector(loginHandler:) forControlEvents:UIControlEventTouchUpInside]; [self.orderButton addTarget:self action:@selector(jumpToOrder:) forControlEvents:UIControlEventTouchUpInside]; self.orderBackLabel.text = @"马上添加感兴趣的栏目到这里"; [[NSNotificationCenter defaultCenter] postNotificationName:CLEARALLORDER object:nil]; }else if ([nodeBO.myOrderStatus intValue] == 4) { self.orderBackView.hidden = YES; }else { self.orderBackView.hidden = YES; [self.orderButton removeTarget:self action:@selector(loginHandler:) forControlEvents:UIControlEventTouchUpInside]; [self.orderButton addTarget:self action:@selector(jumpToOrder:) forControlEvents:UIControlEventTouchUpInside]; self.orderBackLabel.text = @"马上添加感兴趣的栏目到这里"; [[NSNotificationCenter defaultCenter] postNotificationName:CLEARALLORDER object:nil]; } }else { self.orderBackView.hidden = YES; } [self.orderBackView remakeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); }]; [self.orderButton remakeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.orderBackView.centerX); make.centerY.equalTo(self.orderBackView.centerY).offset(-75); make.size.mas_equalTo(CGSizeMake(50, 50)); }]; [self.orderBackLabel remakeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.orderBackView.centerX); make.top.equalTo(self.orderButton.bottom).offset(15); make.size.mas_equalTo(CGSizeMake(270/2, 40)); }]; /** * bug:5163(栏目页的频道未与正文的频道同步) */ } #pragma mark - btn handler - (void)loginHandler:(UIButton*)btn { [[NSNotificationCenter defaultCenter] postNotificationName:PUSHTOLOGIN object:nil]; } - (void)jumpToOrder:(UIButton*)btn { [self jumpToOrderCenter]; } - (void)jumpToOrderCenter { orderCenterController *vc = orderCenterController.new; [self.navigationController pushViewController:vc animated:YES]; } - (void)jumpToColumnManager:(nodeObjectBO*)nodeObj { columnManagerController *vc = columnManagerController.new; [self.navigationController pushViewController:vc animated:YES]; vc.nodeBO = nodeObj; } - (void)openDeleteMode { isOpenDeleteMode = YES; [self.collectionView reloadData]; [CoreAnimationEffect animationEaseIn:self.collectionView]; } - (void)hideDeleteMode { isOpenDeleteMode = NO; [self.collectionView reloadData]; [CoreAnimationEffect animationEaseIn:self.collectionView]; } #pragma mark - collction View delegate and datasource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { if (self.nodeList && self.nodeList.count > 0) { return self.nodeList.count; }else return 0; } - (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString* cellId = @"nodeCollectCellID"; static NSString* addCellId = @"addCollectCell"; static NSString *topicNodeCellID = @"topicNodeCellID"; if ([self.orderNodeBO.nodeId intValue] == -3) { nodeTopicCell *cell = (nodeTopicCell*)[collectionView dequeueReusableCellWithReuseIdentifier:topicNodeCellID forIndexPath:indexPath]; cell.nodeInfoBO = self.nodeList[indexPath.row]; return cell; }else { if ([self.orderNodeBO.nodeId isEqualToString:@"-1"] && indexPath.row == 0) { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:addCellId forIndexPath:indexPath]; cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; cell.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor; cell.layer.borderWidth = 0.5; UIView *selectView = [[UIView alloc]initWithFrame:cell.bounds]; selectView.backgroundColor = [UIColor colorWithHexString:GRAYCOLOR]; cell.selectedBackgroundView = selectView; UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetWidth(cell.bounds)/2-25, CGRectGetHeight(cell.bounds)/2-25, 50, 50)]; imageView.userInteractionEnabled = YES; imageView.image = Image(@"Button/orderButton.png"); [cell addSubview:imageView]; return cell; }else { nodeInfoCell *cell = (nodeInfoCell*)[collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath]; // [cell sizeToFit]; cell.nodeInfoBO = self.nodeList[indexPath.row]; if (isOpenDeleteMode) { cell.isDelete = YES; }else { cell.isDelete = NO; } __weak typeof(self) Self = self; __block NSInteger deleteRow = 0; [cell cancelOrderBlock:^(nodeObjectBO *nodeBO) { [Self.nodeList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[nodeObjectBO class]]) { nodeObjectBO *nodeOBJ = obj; if ([nodeOBJ.nodeId doubleValue] == [nodeBO.nodeId doubleValue]) { deleteRow = idx; } } }]; if (deleteRow > 0) { NSIndexPath *IndexPath = [NSIndexPath indexPathForItem:deleteRow inSection:0]; [Self.nodeList removeObjectAtIndex:IndexPath.row]; NSArray *array = [NSArray arrayWithObject:IndexPath]; [Self.collectionView deleteItemsAtIndexPaths:array]; if (Self.nodeList.count == 1) { [Self.collectionView reloadData]; Self.orderBackView.hidden = NO; Self.orderBackLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); [self.orderButton removeTarget:self action:@selector(jumpToOrder:) forControlEvents:UIControlEventTouchUpInside]; [self.orderButton addTarget:self action:@selector(jumpToOrderCenter) forControlEvents:UIControlEventTouchUpInside]; self.orderBackLabel.text = @"马上添加感兴趣的栏目到这里"; [[NSNotificationCenter defaultCenter] postNotificationName:CLEARALLORDER object:nil]; } ShowMessage(@"退订成功", YES); } }]; return cell; } } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [collectionView deselectItemAtIndexPath:indexPath animated:YES]; /** * bug:5315(订阅导航页点击栏目,点击效果不应和页面跳转一起显示) */ if ([self.orderNodeBO.nodeId isEqualToString:@"-1"]) { if (isOpenDeleteMode) { [self hideDeleteMode]; }else { if (indexPath.row == 0) { [self jumpToOrderCenter]; }else { nodeObjectBO* node = self.nodeList[indexPath.row]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self jumpToColumnManager:node]; }); } } }else if (![self.orderNodeBO.nodeId isEqualToString:@"-3"]){ nodeObjectBO* node = self.nodeList[indexPath.row]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self jumpToColumnManager:node]; }); }else if ([self.orderNodeBO.nodeId isEqualToString:@"-3"]) { if (indexPath.row == 0) { AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate]; YRSideViewController *sideController=[delegate sideViewController]; [sideController hideSideViewController:YES]; TPMainPageViewController *mainVC = delegate.mainVC; NSArray *array = [TPUserDefault instance].channldataList; __block NSInteger index = -1; [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj[@"nodeId"] intValue] == -3) { index = idx; } }]; if (index >=0 ) { dispatch_async(dispatch_get_main_queue(), ^{ mainVC.pageView.currentPageIndex = index; mainVC.pageView.currentPageIndex = index; /** * bug:5641(【倒退】栏目导航页:在非问吧频道页,点击+号进入栏目导航页后,点击问吧精选无法正常跳转) */ }); } }else { [MobClick event:@"81"]; nodeObjectBO* data = self.nodeList[indexPath.row]; categoryBO *cateBO = [categoryBO new]; cateBO.category = data.nodeId; cateBO.name = data.name; InterViewPageViewController *vc = [InterViewPageViewController new]; vc.cateBo = cateBO; // vc.cateList = cateList; // vc.index = index; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.navigationController pushViewController:vc animated:YES]; }); } } } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(CGRectGetWidth(self.view.bounds)/2, CGRectGetWidth(self.view.bounds)/2); } -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { UIEdgeInsets top = {0,0,0,0}; return top; } - (void)refreshRemoteOrderData:(void (^)())block { refreshRemoteOrderData = [block copy]; } - (void)dealloc { [[NSNotificationCenter defaultCenter]removeObserver:self]; } @end