澎湃iPad上线版本

orderCenterController.m 13KB

    // // orderCenterController.m // ThePaperHD // // Created by scar1900 on 15/4/14. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "orderCenterController.h" #import "ATPagingView.h" #import "orderTableController.h" #define ORDERBUTTONTAG 6000 #define ORDERLABELTAG 6300 #define ORDEREDVIEWTAG 6500 @interface orderCenterController () <ATPagingViewDelegate,orderTableDelegate> @property(nonatomic, strong)UIButton *closeBtn; @property(nonatomic, strong)UILabel *titleLabel; @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)NSArray *nodeListArray; @property(nonatomic, strong)UIView *nodeBtnView; //订阅侧边栏 @property(nonatomic, strong)NSMutableArray *orderButtonArray; @property(nonatomic, strong)UIView *lineView; @property(nonatomic, strong)ATPagingView *pagingView; @property(nonatomic, strong)NSMutableArray *pageViewControllers; @property(nonatomic, assign)NSInteger currentIndex; @property(nonatomic, strong)nodeObjectBO *orderedBO; @end @implementation orderCenterController @synthesize isNeedHold; @synthesize nodeListArray = _nodeListArray; @synthesize orderButtonArray; @synthesize currentIndex = _currentIndex; @synthesize orderedBO; @synthesize delegate; - (id)init { self = [super init]; if (self) { self.isNeedHold = NO; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor clearColor]; self.view.frame = CGRectMake(0, 0, orderCenterPopSize.width, orderCenterPopSize.height); [self.view addSubview:self.closeBtn]; [self.view addSubview:self.titleLabel]; [self.view addSubview:self.backView]; self.closeBtn.frame = CGRectMake(0, 0, 50, 80); self.titleLabel.frame = CGRectMake(50, 0, CGRectGetWidth(self.view.bounds)-100, 80); self.backView.frame = CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), CGRectGetWidth(self.view.bounds), settingPopSize.height-80); [self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self askForRemoteNodeList]; self.isNeedHold = NO; } - (void)setNodeListArray:(NSArray *)list { if (!_nodeListArray) { _nodeListArray = list; if (list.count == 0) { return; } self.orderedBO = [list lastObject]; [self.backView addSubview:self.lineView]; [self.backView addSubview:self.nodeBtnView]; [self.backView addSubview:self.pagingView]; 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]; 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]initWithFrame:CGRectMake(CGRectGetWidth(orderBtn.frame)/2-8, CGRectGetHeight(orderBtn.frame)-1, 16, 1)]; btnLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [orderBtn addSubview:btnLine]; UILabel *orderLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(orderBtn.bounds)/2+10, CGRectGetWidth(orderBtn.bounds), 20)]; orderLabel.tag = ORDERLABELTAG+i; orderLabel.backgroundColor = [UIColor clearColor]; orderLabel.font = appFont(9, NO); orderLabel.textColor = [UIColor colorWithHexString:TextBlack]; orderLabel.textAlignment = NSTextAlignmentCenter; orderLabel.text = nodeInfo.enname; if (i==0) { orderLabel.textColor = [UIColor colorWithHexString:colorStr]; } [orderBtn addSubview:orderLabel]; [self.nodeBtnView addSubview:orderBtn]; [self.pageViewControllers addObject:[NSNull null]]; } [self.orderButtonArray addObject:orderBtn]; orderBtn.titleLabel.font = appFont(18, NO); [self.pagingView reloadData]; self.pagingView.currentPageIndex = 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) { UILabel *label = (UILabel*)[button viewWithTag:button.tag - ORDERBUTTONTAG+ORDERLABELTAG]; button.selected = NO; label.textColor = [UIColor colorWithHexString:TextBlack]; }]; btn.selected = !btn.selected; nodeObjectBO *nodeInfo = self.nodeListArray[btn.tag - ORDERBUTTONTAG]; NSString *colorStr = nodeInfo.color; colorStr = [colorStr stringByReplacingOccurrencesOfString:@"#" withString:@"0x"]; UILabel *orderLabel = (UILabel*)[btn viewWithTag:btn.tag - ORDERBUTTONTAG+ORDERLABELTAG]; orderLabel.textColor = [UIColor colorWithHexString:colorStr]; NSInteger selectIndex = btn.tag - ORDERBUTTONTAG; self.currentIndex = selectIndex; } - (void)setCurrentIndex:(NSInteger)index { _currentIndex = index; self.pagingView.currentPageIndex = index; } #pragma mark - paging view - (ATPagingView*)pagingView { if (!_pagingView) { _pagingView = [[ATPagingView alloc]initWithFrame:CGRectMake(71, 0, orderCenterPopSize.width-71, orderCenterPopSize.height-80)]; _pagingView.gapBetweenPages = 0; _pagingView.recyclingEnabled = NO; _pagingView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _pagingView.delegate = self; _pagingView.clipsToBounds = YES; _pagingView.scrollView.scrollEnabled = NO; // _pagingView.direction = ATPagingViewVertical; } return _pagingView; } - (UIView*)lineView { if (!_lineView) { _lineView = [[UIView alloc]initWithFrame:CGRectMake(70, 0, 1, CGRectGetHeight(self.backView.bounds))]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; }return _lineView; } - (UIView*)nodeBtnView { if (!_nodeBtnView) { _nodeBtnView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 69, CGRectGetHeight(self.backView.bounds))]; _nodeBtnView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _nodeBtnView; } //获取网络栏目信息 - (void)askForRemoteNodeList { NSDictionary *dic = @{@"type":@"2"}; [Remote doJsonAction:1 requestUrl:allNodeListURL parameter:dic delegate:self]; } - (UIButton*)closeBtn { if (!_closeBtn) { _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_closeBtn setImage:Image(@"login/popUpCloseBtn.png") forState:UIControlStateNormal]; [_closeBtn setImage:Image(@"login/popUpCloseBtn_s.png") forState:UIControlStateHighlighted]; [_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _closeBtn; } - (UILabel*)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.textAlignment = NSTextAlignmentCenter; _titleLabel.text = @"订阅管理"; _titleLabel.textColor = [UIColor whiteColor]; _titleLabel.font = appFont(30, NO); } return _titleLabel; } - (UIView*)backView { if (!_backView) { _backView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), orderCenterPopSize.width, orderCenterPopSize.height-80)]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _backView; } #pragma mark - btn handler - (void)closeEvent:(UIButton*)btn { [self dismissControllerAnimated:YES completion:nil]; } - (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 { } - (void)pagesDidChangeInPagingView:(ATPagingView *)pageView { } - (void)pagingViewWillBeginMoving:(ATPagingView *)pageView { } - (void)pagingViewdDidScroll:(UIScrollView *)scrollerView { } - (void)selectedNode:(nodeObjectBO *)nodeInfo { self.isNeedHold = YES; if ([self.delegate respondsToSelector:@selector(pushToNodeController:)]) { [self.delegate pushToNodeController:nodeInfo]; } } - (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