// // orderManagerController.m // ThePaperDemo // // Created by scar1900 on 14-10-15. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "orderCenterController.h" #import "ATPagingView.h" #import "orderTableController.h" #import "columnManagerController.h" #import "MLNavigationController.h" #define ORDERBUTTONTAG 6000 #define ORDERCOLORVIEWTAG 6300 #define ORDEREDVIEWTAG 6500 @interface orderCenterController () { BOOL enablePan; } @property(nonatomic, strong)NSArray *nodeListArray; @property(nonatomic, strong)UIView *nodeBtnView; //订阅侧边栏 @property(nonatomic, strong)NSMutableArray *orderButtonArray; @property(nonatomic, strong)ATPagingView *pagingView; @property(nonatomic, strong)NSMutableArray *pageViewControllers; @property(nonatomic, assign)NSInteger currentIndex; @property(nonatomic, strong)nodeObjectBO *orderedBO; @end @implementation orderCenterController @synthesize nodeListArray = _nodeListArray; @synthesize orderButtonArray; @synthesize currentIndex = _currentIndex; @synthesize orderedBO; - (void)viewDidLoad { [super viewDidLoad]; enablePan = NO; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; ((MLNavigationController*)self.navigationController).canDragBack = NO; self.titleStr = @"订阅管理"; [self askForRemoteNodeList]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(paningGestureReceive:)]; recognizer.delegate = self; recognizer.direction = UISwipeGestureRecognizerDirectionRight; // [recognizer delaysTouchesBegan]; [self.view addGestureRecognizer:recognizer]; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } - (void)paningGestureReceive:(UISwipeGestureRecognizer*)pan {// 问吧列表,切换第一第二个类型,极易闪退(bug:5064) if (self.pagingView.currentPageIndex != 0) { return; } if (!enablePan) { return; } orderTableController *listController = self.pageViewControllers[0]; if (!listController) { return; } if (listController.tableView.isDragging) { return; } CGPoint touchPoint = [pan locationInView:self.naviBar]; if (touchPoint.y <= self.naviBar.frame.size.height+37) { return; } [self.navigationController popViewControllerAnimated:YES]; /** * bug:5039(订阅管理滑动处理优化) */ // [(MLNavigationController*)self.navigationController paningGestureReceive:pan]; } //获取网络栏目信息 - (void)askForRemoteNodeList { NSDictionary *dic = @{@"type":@"2"}; [Remote doJsonAction:1 requestUrl:allNodeListURL parameter:dic delegate:self]; } #pragma mark - paging view - (ATPagingView*)pagingView { if (!_pagingView) { _pagingView = [[ATPagingView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.nodeBtnView.frame), rect_screen.size.width, rect_screen.size.height-self.barHeight-CGRectGetHeight(self.nodeBtnView.frame))]; _pagingView.gapBetweenPages = 0; _pagingView.recyclingEnabled = NO; _pagingView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _pagingView.delegate = self; _pagingView.clipsToBounds = YES; _pagingView.scrollView.scrollEnabled = YES; _pagingView.scrollView.bounces = NO; // _pagingView.direction = ATPagingViewVertical; } return _pagingView; } - (UIView*)nodeBtnView { if (!_nodeBtnView) { _nodeBtnView = [[UIView alloc]init]; _nodeBtnView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _nodeBtnView; } - (void)setAutoLayoutSubviews { [self.nodeBtnView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left); make.right.equalTo(self.view.right); make.top.equalTo(self.naviBar.bottom).offset(-1); make.height.equalTo(@37); }]; [self.pagingView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left); make.right.equalTo(self.view.right); make.top.equalTo(self.nodeBtnView.bottom); make.bottom.equalTo(self.view.bottom); }]; } #pragma mark - set node list - (void)setNodeListArray:(NSArray *)list { if (!_nodeListArray) { _nodeListArray = list; if (list.count == 0) { return; } self.orderedBO = [list lastObject]; [self.view addSubview:self.nodeBtnView]; [self.view addSubview:self.pagingView]; [self setAutoLayoutSubviews]; self.pageViewControllers = [NSMutableArray array]; self.orderButtonArray = [NSMutableArray array]; // NSArray *orderTitleArray = @[@"时事",@"经济",@"思想",@"生活"]; // NSArray *orderTitleArray = [TPUserDefault instance].channldataList; for (int i=0;i<4;i++) { UIButton *orderBtn = (UIButton*)[self.nodeBtnView viewWithTag:6000+i]; UIButton *lastBtn = (UIButton*)[self.nodeBtnView viewWithTag:6000+i-1]; if (!orderBtn) { nodeObjectBO *nodeInfo = list[i]; NSString *colorStr = nodeInfo.color; colorStr = [colorStr stringByReplacingOccurrencesOfString:@"#" withString:@"0x"]; orderBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // [orderBtn setTitle:orderTitleArray[i] forState:UIControlStateNormal]; [orderBtn setTitle:nodeInfo.name forState:UIControlStateNormal];//【需求】频道名字要读后台的,不要写死(bug:4044) [orderBtn setTitleColor:[UIColor colorWithHexString:TextBlack] forState:UIControlStateNormal]; [orderBtn setTitleColor:[UIColor colorWithHexString:colorStr] forState:UIControlStateSelected]; orderBtn.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; // orderBtn.titleLabel.lineBreakMode = NSLineBreakByCharWrapping; // orderBtn.titleLabel.numberOfLines = 0; orderBtn.tag = ORDERBUTTONTAG + i; [orderBtn addTarget:self action:@selector(orderClickHandler:) forControlEvents:UIControlEventTouchUpInside]; if (i == 0) { orderBtn.selected = YES; } // orderBtn.frame = CGRectMake(0, i*195/2, CGRectGetWidth(self.nodeBtnView.bounds), 195/2); // [orderBtn setTitleEdgeInsets:UIEdgeInsetsMake(25, 35/2, 16, 16)]; UIView *btnLine = [[UIView alloc]init]; btnLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [orderBtn addSubview:btnLine]; if (i==3) { btnLine.hidden = YES; } UIView *lineView = [[UIView alloc]init]; lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [orderBtn addSubview:lineView]; /** * bug:5301(订阅管理tab下方颜色线和灰色线的距离不对,彩色条要压在灰线上) */ UIView *orderColorView = [[UIView alloc]init]; orderColorView.tag = ORDERCOLORVIEWTAG; orderColorView.backgroundColor = [UIColor colorWithHexString:colorStr]; orderColorView.hidden = YES; if (i == 0) { orderColorView.hidden = NO; } [orderBtn addSubview:orderColorView]; [self.nodeBtnView addSubview:orderBtn]; CGFloat orderWidth = rect_screen.size.width/4; if (i==0) { [orderBtn makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.nodeBtnView.left); make.top.equalTo(self.nodeBtnView.top); make.bottom.equalTo(self.nodeBtnView.bottom); make.width.mas_equalTo(orderWidth); }]; }else { [orderBtn makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(lastBtn.right); make.top.equalTo(self.nodeBtnView.top); make.bottom.equalTo(self.nodeBtnView.bottom); make.width.mas_equalTo(orderWidth); }]; } [btnLine makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(orderBtn.centerY); make.right.equalTo(orderBtn.right); make.width.equalTo(@1); make.height.equalTo(@16); }]; [lineView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(orderBtn.left); make.right.equalTo(orderBtn.right); make.height.equalTo(@0.5); make.bottom.equalTo(orderBtn.bottom); }]; [orderColorView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(orderBtn.left); make.right.equalTo(orderBtn.right); make.bottom.equalTo(orderBtn.bottom); make.height.equalTo(@3); }]; [self.pageViewControllers addObject:[NSNull null]]; [self.orderButtonArray addObject:orderBtn]; orderBtn.titleLabel.font = appFont(TEXT_ONE_PLUS_LEVELSIZE, NO); } } [self.pagingView reloadData]; enablePan = YES; self.currentIndex = 0; }else { self.orderedBO = [list lastObject]; _nodeListArray = list; orderTableController *tableVC = self.pageViewControllers[self.pagingView.currentPageIndex]; nodeObjectBO *nodeInfo = self.nodeListArray[self.pagingView.currentPageIndex]; NSArray *childList = nodeInfo.childNodeList; NSMutableArray *childNodeArray = [NSMutableArray array]; [childList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { nodeObjectBO *nodeBO = setJsonDicToDataModel(obj, [nodeObjectBO class]); [childNodeArray addObject:nodeBO]; }]; tableVC.orderChildList = childNodeArray; tableVC.orderedBO = self.orderedBO; } } - (void)orderClickHandler:(UIButton*)btn { // [orderButtonArray enumerateObjectsUsingBlock:^(UIButton* button, NSUInteger idx, BOOL *stop) { // UIView *colorView = [button viewWithTag:ORDERCOLORVIEWTAG]; // button.selected = NO; // colorView.hidden = YES; // }]; // btn.selected = !btn.selected; // // UIView *colorView = [btn viewWithTag:ORDERCOLORVIEWTAG]; // colorView.hidden = NO; // NSInteger selectIndex = btn.tag - ORDERBUTTONTAG; self.currentIndex = selectIndex; } - (void)setCurrentIndex:(NSInteger)index { _currentIndex = index; self.pagingView.currentPageIndex = index; } #pragma mark - remote delegate - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { NSArray *nodeArray = responsData[@"nodeList"]; NSMutableArray *tempArray = [NSMutableArray array]; [nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { nodeObjectBO *nodeInfo = setJsonDicToDataModel(obj, [nodeObjectBO class]); [tempArray addObject:nodeInfo]; }]; self.nodeListArray = tempArray; } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code { ShowTextMessage(message); } #pragma mark - pagingview delegate #pragma mark ATPagingViewDelegate methods - (NSInteger)numberOfPagesInPagingView:(ATPagingView *)pagingView { return self.pageViewControllers.count; } - (UIView *)viewForPageInPagingView:(ATPagingView *)pagingView atIndex:(NSInteger)index { if (self.pageViewControllers[index] == [NSNull null]) { orderTableController *tableVC = [[orderTableController alloc]init]; [self addChildViewController:tableVC]; nodeObjectBO *nodeInfo = self.nodeListArray[index]; NSArray *childList = nodeInfo.childNodeList; NSMutableArray *childNodeArray = [NSMutableArray array]; [childList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { nodeObjectBO *nodeBO = setJsonDicToDataModel(obj, [nodeObjectBO class]); [childNodeArray addObject:nodeBO]; }]; tableVC.orderChildList = childNodeArray; tableVC.orderedBO = self.orderedBO; tableVC.orderTableDelgate = self; self.pageViewControllers[index] = tableVC; } return ((UIViewController*)self.pageViewControllers[index]).view; } - (void)currentPageDidChangeInPagingView:(ATPagingView *)pageView { UIButton *btn = (UIButton*)[self.nodeBtnView viewWithTag:self.pagingView.currentPageIndex+ORDERBUTTONTAG]; [orderButtonArray enumerateObjectsUsingBlock:^(UIButton* button, NSUInteger idx, BOOL *stop) { UIView *colorView = [button viewWithTag:ORDERCOLORVIEWTAG]; button.selected = NO; colorView.hidden = YES; }]; btn.selected = !btn.selected; UIView *colorView = [btn viewWithTag:ORDERCOLORVIEWTAG]; colorView.hidden = NO; if (pageView.currentPageIndex == 0) { enablePan = YES; }else { enablePan = NO; } } - (void)pagesDidChangeInPagingView:(ATPagingView *)pageView { } - (void)pagingViewWillBeginMoving:(ATPagingView *)pageView { } - (void)pagingViewDidEndMoving:(ATPagingView *)pagingView { if (pagingView.currentPageIndex == 0) { enablePan = YES; }else { enablePan = NO; } } - (void)pagingViewdDidScroll:(UIScrollView *)scrollerView { enablePan = NO; } //- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { // return YES; //} - (void)selectedNode:(nodeObjectBO *)nodeInfo { ((MLNavigationController*)self.navigationController).canDragBack = YES; columnManagerController *vc = columnManagerController.new; [self.navigationController pushViewController:vc animated:YES]; vc.nodeBO = nodeInfo; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)needrefreshNightMode:(id)sender{ self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [orderButtonArray enumerateObjectsUsingBlock:^(UIButton* button, NSUInteger idx, BOOL *stop) { [button setTitleColor:[UIColor colorWithHexString:TextBlack] forState:UIControlStateNormal]; button.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; }]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } /* #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