|
//
// orderController.m
// ThePaperDemo
//
// Created by scar1900 on 14-9-29.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "orderController.h"
#import "AppDelegate.h"
#import "nodeInfoCell.h"
#import "CoreAnimationEffect.h"
#import "LBorderView.h"
#import "orderCenterController.h"
#import "columnListController.h"
#import "customFlowLayout.h"
#define ORDERBUTTONTAG 6000
#define ORDERLABELTAG 6300
#define ORDEREDVIEWTAG 6500
@interface orderController()<nodeInfoDelegate> {
BOOL isNodeInfoChange;
NSMutableArray *colorArray;
}
@property(nonatomic, strong)UIView *lineView;
@property(nonatomic, strong)UIView *nodeBtnView; //订阅侧边栏
@property(nonatomic, strong)NSMutableArray *orderButtonArray;
@property(nonatomic, strong)NSMutableArray *nodeListArray;
@property(nonatomic, assign)NSInteger currentIndex;
@property(nonatomic, strong)UILongPressGestureRecognizer *longGesture;
@property(nonatomic, strong)UIView *orderedView; //订阅拖动后的View
@property(nonatomic, strong)LBorderView *orderLineView; //拖动后的虚线
@property(nonatomic, strong)NSMutableArray *orderChildList;
@end
@implementation orderController
@synthesize orderButtonArray;
@synthesize nodeListArray = _nodeListArray;
@synthesize currentIndex = _currentIndex;
@synthesize longGesture;
@synthesize orderChildList=_orderChildList;
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAfterOpenNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[MobClick event:@"9"];
isNodeInfoChange = NO;
if ([TPUserDefault instance].userBO && self.currentIndex == 4) {
[self remoteAskOrderData];
return;
}
self.lineView.frame = CGRectMake(70, 0, 2, CGRectGetHeight(self.view.bounds));
// self.nodeBtnView.frame = CGRectMake(0, 0, 69, CGRectGetHeight(self.view.bounds));
//
// self.orderedView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 70, CGRectGetHeight(self.view.bounds))];
// self.orderLineView.frame = CGRectMake(1, 780/2, CGRectGetWidth(_orderedView.frame)-4, 580/2);
self.nodeInfoController.view.frame = CGRectMake(70,
0,
CGRectGetWidth(self.view.bounds)-70,
CGRectGetHeight(self.view.bounds));
self.nodeInfoController.collectionView.frame = CGRectMake(0,
0,
CGRectGetWidth(self.nodeInfoController.view.bounds),
CGRectGetHeight(self.nodeInfoController.view.bounds));
if (!self.nodeListArray || self.nodeListArray.count == 0) {
NSError *error;
NSFetchRequest *request = [[NSFetchRequest alloc]init];
//为已创建好的实体利用检索到的上下文创建一个实体描述
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"NodeListDB"
inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext];
[request setEntity:entityDescription];
NodeListDB *nodeListDB = nil;
NSArray *objs = [[CoreDataManager shareInstance].managedObjectContext executeFetchRequest:request error:&error];
if (objs == nil) {
TPLOG(@"there was an error!!");
}
if (objs.count > 0) {
nodeListDB = [objs objectAtIndex:0];
NSDictionary *coreDataDic = makeCoreDataModelToDic(nodeListDB, [NodeListDB class]);
self.nodeListArray = [NSMutableArray array];
if (coreDataDic && coreDataDic[@"nodeList"]) {
NSArray *nodeArray = coreDataDic[@"nodeList"];
NSMutableArray *tempArray = [NSMutableArray array];
[nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
nodeObjectBO *nodeInfo = setJsonDicToDataModel(obj, [nodeObjectBO class]);
if (![nodeInfo.nodeId isEqualToString:@"-3"]) {
[tempArray addObject:nodeInfo];
}
}];
self.nodeListArray = tempArray;
}
}
[self askForRemoteNodeList];
}else {
self.orderedView.hidden = NO;
if (self.currentIndex == 4) {
nodeObjectBO *nodeInfo = self.nodeListArray[self.currentIndex];
nodeInfo.myOrderStatus = @"2";
self.orderChildList = [NSMutableArray array];
self.nodeInfoController.orderNodeBO = nodeInfo;
self.nodeInfoController.nodeList = self.orderChildList;
}
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (isNodeInfoChange) {
[[NSNotificationCenter defaultCenter] postNotificationName:NEEDREFRESHENTERFORGROUND object:nil];
}
}
//获取网络栏目信息
- (void)askForRemoteNodeList {
NSDictionary *dic = @{@"type":@"2"};
[Remote doJsonAction:1
requestUrl:allNodeListURL
parameter:dic
delegate:self];
}
- (UIView*)lineView {
if (!_lineView) {
_lineView = [[UIView alloc]initWithFrame:CGRectMake(70, 0, 2, CGRectGetHeight(self.view.bounds))];
_lineView.autoresizingMask = AutoresizingFull;
}
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
return _lineView;
}
- (UIView*)nodeBtnView {
if (!_nodeBtnView) {
_nodeBtnView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 69, CGRectGetHeight(self.view.bounds))];
_nodeBtnView.autoresizingMask = AutoresizingFull;
}
_nodeBtnView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
return _nodeBtnView;
}
- (LBorderView*)orderLineView {
if (!_orderLineView) {
_orderLineView = [[LBorderView alloc]initWithFrame:CGRectZero];
_orderLineView.cornerRadius = 0;
_orderLineView.borderType = BorderTypeDashed;
_orderLineView.borderColor = [UIColor colorWithHexString:GRAYCOLOR];
_orderLineView.borderWidth = 2.0f;
_orderLineView.dashPattern = 3.0f;
_orderLineView.spacePattern = 3.0f;
}
return _orderLineView;
}
- (UIView*)orderedView {
UILabel *titleLabel = (UILabel*)[_orderedView viewWithTag:ORDEREDVIEWTAG];
if (!_orderedView) {
_orderedView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 70, CGRectGetHeight(self.view.bounds))];
_orderedView.autoresizingMask = AutoresizingFull;
self.orderLineView.hidden = YES;
self.orderLineView.frame = CGRectMake(1, 780/2, CGRectGetWidth(_orderedView.frame)-4, 580/2);
[_orderedView addSubview:self.orderLineView];
if (!titleLabel) {
titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(35/2, 780/2+20, 16, 150/2)];
titleLabel.tag = ORDEREDVIEWTAG;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = @"拖入订阅";
titleLabel.textAlignment = NSTextAlignmentLeft;
titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
titleLabel.numberOfLines = 0;
titleLabel.font = appFont(15, NO);
[_orderedView addSubview:titleLabel];
}
}
_orderedView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
return _orderedView;
}
- (nodeInfoController*)nodeInfoController {
if (!_nodeInfoController) {
_nodeInfoController = [[nodeInfoController alloc]init];
_nodeInfoController.view.frame = CGRectMake(70,
0,
CGRectGetWidth(self.view.bounds)-70,
CGRectGetHeight(self.view.bounds));
// _nodeInfoController.view.autoresizingMask = AutoresizingAuto;
_nodeInfoController.delegate = self;
__weak typeof(self) Self = self;
[_nodeInfoController refreshRemoteOrderData:^{
[Self remoteAskOrderData];
}];
[self addChildViewController:_nodeInfoController];
[self.view addSubview:_nodeInfoController.view];
}
if (!self.longGesture) {
self.longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognized:)];
[self.view addGestureRecognizer:self.longGesture];
}
return _nodeInfoController;
}
#pragma mark - data source
- (void)setNodeListArray:(NSMutableArray *)list {
_nodeListArray = list;
if (list.count == 0) {
return;
}
[self.view addSubview:self.lineView];
[self.view addSubview:self.nodeBtnView];
[self.view addSubview:self.orderedView];
[self.view insertSubview:self.orderedView belowSubview:self.nodeBtnView];
[self addChildViewController:self.nodeInfoController];
orderButtonArray = [NSMutableArray array];
if (![TPUserDefault instance].channldataList || [TPUserDefault instance].channldataList.count == 0) {
NSDictionary *dic = @{@"type":@"1"};
[Remote doJsonActionWithBlock:0 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) {
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 addBtnAfterSetNodeList];
}
}else {
ShowTextMessage(message);
}
}];
}else {
[self addBtnAfterSetNodeList];
}
}
- (void)addBtnAfterSetNodeList {
NSMutableArray *orderTitleArray = [NSMutableArray array];
NSMutableArray *orderTitleEnglishArray = [NSMutableArray array];
colorArray = [NSMutableArray array];
[[TPUserDefault instance].channldataList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {//【需求】频道名字要读后台的,不要写死(bug:4044)
//【倒退】栏目导航页的频道名显示有误,与设计图不一致(bug:4705)
NSDictionary *dic = [TPUserDefault instance].channldataList[idx];
if (![dic[@"nodeId"] isEqualToString:@"25949"] && ![dic[@"nodeId"] isEqualToString:@"-3"]) {
if ([dic[@"nodeId"] intValue] == -1) {
[orderTitleArray addObject:@"订阅"];
}else{
[orderTitleArray addObject:dic[@"name"]];
}
[orderTitleEnglishArray addObject:dic[@"enname"]];
[colorArray addObject:dic[@"color"]];
}
// if (idx != 0 && idx !=5) {
// if (idx == 6) {
// [orderTitleArray addObject:@"订阅"];
// }else{
// [orderTitleArray addObject:[TPUserDefault instance].channldataList[idx][@"name"]];
// }
// [orderTitleEnglishArray addObject:[TPUserDefault instance].channldataList[idx][@"enname"]];
// }
}];
// NSArray *orderTitleArray = @[@"时事",@"经济",@"思想",@"生活",@"订阅"];
for (int i=0;i<5;i++) {
UIButton *orderBtn = (UIButton*)[self.nodeBtnView viewWithTag:6000+i];
if (!orderBtn) {
nodeObjectBO *nodeInfo = self.nodeListArray[i];
NSString *colorStr = nodeInfo.color;
colorStr = [colorStr stringByReplacingOccurrencesOfString:@"#" withString:@"0x"];
orderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[orderBtn setTitle:orderTitleArray[i] forState:UIControlStateNormal];
[orderBtn setTitleColor:[UIColor colorWithHexString:TextBlack] forState:UIControlStateNormal];
[orderBtn setTitleColor:[UIColor colorWithHexString:colorStr] forState:UIControlStateSelected];
// 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;
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];
}];
self.nodeInfoController.nodeList = childNodeArray;
}
if (i != 4) {
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];
btnLine.tag = 1000;
[orderBtn addSubview:btnLine];
}else {
orderBtn.frame = CGRectMake(0, 4*195/2, CGRectGetWidth(self.nodeBtnView.bounds), 195/2);
[orderBtn setTitleEdgeInsets:UIEdgeInsetsMake(25, 35/2, 16, 16)];
}
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 = orderTitleEnglishArray[i];//【需求】频道名字要读后台的,不要写死(bug:4044)
if (i==0) {
orderLabel.textColor = [UIColor colorWithHexString:colorStr];
}
[orderBtn addSubview:orderLabel];
[self.nodeBtnView addSubview:orderBtn];
}
[self.orderButtonArray addObject:orderBtn];
orderBtn.titleLabel.font = appFont(18, NO);
}
}
- (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;
// NSString *colorStr = colorArray[btn.tag - ORDERBUTTONTAG];
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 {
if (_currentIndex != index) {
if (self.nodeInfoController.isOpenDeleteMode) {
[self.nodeInfoController hideDeleteMode];
}
if (![TPUserDefault instance].userBO) {
_currentIndex = index;
nodeObjectBO *nodeInfo = self.nodeListArray[index];
if (index != 4) {
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];
}];
self.nodeInfoController.orderNodeBO = nodeInfo;
self.nodeInfoController.nodeList = childNodeArray;
}else {
nodeInfo.myOrderStatus = @"2";
self.orderChildList = [NSMutableArray array];
if (!nodeInfo) {
nodeInfo = nodeObjectBO.new;
nodeInfo.myOrderStatus = @"2";
}
self.nodeInfoController.orderNodeBO = nodeInfo;
self.nodeInfoController.nodeList = self.orderChildList;
}
}else {
if (index != 4) {
_currentIndex = index;
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];
}];
self.nodeInfoController.orderNodeBO = nodeInfo;
self.nodeInfoController.nodeList = childNodeArray;
}else {
_currentIndex = index;
[self remoteAskOrderData];
}
}
}
}
- (void)remoteAskOrderData {
NSDictionary* childDic = @{@"n":@"-1"};
[Remote doJsonAction:2
requestUrl:childNodeListURL
parameter:childDic
delegate:self];
}
#pragma mark - node info delgate
- (void)haveDeleteNode {
isNodeInfoChange = YES;
}
- (void)popUpOrderCenter {
[[NSNotificationCenter defaultCenter] postNotificationName:POPUPORDERCENTER object:nil];
}
#pragma mark - remote delegate
- (void)startWaitCursor:(int)actionTag {
}
- (void)stopWaitCursor:(int)actionTag {
}
- (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData {
if (actionTag == 1) {
self.nodeListArray = [NSMutableArray array];
if (responsData && responsData[@"nodeList"]) {
NSError *error;
NSFetchRequest *request = [[NSFetchRequest alloc]init];
//为已创建好的实体利用检索到的上下文创建一个实体描述
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"NodeListDB"
inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext];
[request setEntity:entityDescription];
NodeListDB *nodeListDB = nil;
NSArray *objs = [[CoreDataManager shareInstance].managedObjectContext executeFetchRequest:request error:&error];
if (objs == nil) {
TPLOG(@"there was an error!!");
}
if (objs.count > 0) {
nodeListDB = [objs objectAtIndex:0];
[[CoreDataManager shareInstance].managedObjectContext deleteObject:nodeListDB];
}
NodeListDB *newNodeListDB = nil;
newNodeListDB = [NSEntityDescription insertNewObjectForEntityForName:@"NodeListDB"
inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext];
newNodeListDB = makeDicToCoreDataModel(responsData, newNodeListDB);
newNodeListDB.date = getLocalDate();
[[CoreDataManager shareInstance] saveContext];
NSArray *nodeArray = responsData[@"nodeList"];
NSMutableArray *tempArray = [NSMutableArray array];
[nodeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
nodeObjectBO *nodeInfo = setJsonDicToDataModel(obj, [nodeObjectBO class]);
if ([nodeInfo.nodeId intValue] != -3) {
[tempArray addObject:nodeInfo];
}
}];
self.nodeListArray = tempArray;
}
}else if (actionTag == 2){
TPLOG(@"接到订阅数据");
self.orderChildList = [NSMutableArray array];
if (responsData && responsData[@"nodeList"]) {
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];
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if (![array containsObject:nodeInfo.nodeId]) {
[array addObject:nodeInfo.nodeId];
[TPUserDefault instance].orderEventTempList = array;
}
}];
[self.orderChildList addObject:@""];
[self.orderChildList addObjectsFromArray:tempArray];
nodeObjectBO *nodeInfo = self.nodeListArray[4];
if (self.orderChildList.count == 0) {
nodeInfo.myOrderStatus = @"3";
}else nodeInfo.myOrderStatus = @"1";
self.nodeInfoController.orderNodeBO = nodeInfo;
self.nodeInfoController.nodeList = self.orderChildList;
}
}else {
ShowMessage(@"订阅成功", YES);
isNodeInfoChange = YES;
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if (![array containsObject:[NSString stringWithFormat:@"%d",actionTag]]) {
[array addObject:[NSString stringWithFormat:@"%d",actionTag]];
[TPUserDefault instance].orderEventTempList = array;
}
}
}
- (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{
if ([code intValue] == 3) {
self.orderChildList = [NSMutableArray array];
nodeObjectBO *nodeInfo = self.nodeListArray[4];
if (self.orderChildList.count == 0) {
nodeInfo.myOrderStatus = @"3";
}else nodeInfo.myOrderStatus = @"1";
self.nodeInfoController.orderNodeBO = nodeInfo;
self.nodeInfoController.nodeList = self.orderChildList;
return;
}
ShowTextMessage(message);
if (actionTag == 2) {
self.orderChildList = [NSMutableArray array];
if ([message isEqualToString:@"您的网络未连接,请设置网络"]) {
nodeObjectBO *nodeInfo = self.nodeListArray[4];
nodeInfo.myOrderStatus = @"4";
self.nodeInfoController.orderNodeBO = nodeInfo;
self.nodeInfoController.nodeList = self.orderChildList;
}else {
}
}else {
ShowTextMessage(message);
}
}
#pragma mark - statusBarOrientationChange
- (void)statusBarOrientationChange:(NSNotification *)notification
{
self.lineView.frame = CGRectMake(70, 0, 2, CGRectGetHeight(self.view.bounds));
// self.nodeBtnView.frame = CGRectMake(0, 0, 69, CGRectGetHeight(self.view.bounds));
//
// self.orderedView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 70, CGRectGetHeight(self.view.bounds))];
// self.orderLineView.frame = CGRectMake(1, 780/2, CGRectGetWidth(_orderedView.frame)-4, 580/2);
self.nodeInfoController.view.frame = CGRectMake(70,
0,
CGRectGetWidth(self.view.bounds)-70,
CGRectGetHeight(self.view.bounds));
}
/**********************************************************************************/
/**********************************************************************************/
/***************************gesture handler****************************************/
/**********************************************************************************/
/**********************************************************************************/
#pragma mark - long press gesture event
- (void)longPressGestureRecognized:(id)sender {
if (![TPUserDefault instance].userBO) { //未登录用户无法订阅
return;
}
UILongPressGestureRecognizer *longPress = (UILongPressGestureRecognizer *)sender;
UIGestureRecognizerState state = longPress.state;
CGPoint snapLineLocation = [longPress locationInView:self.orderLineView];
// if (snapLineLocation.y+CGRectGetWidth(self.nodeInfoController.view.frame)/4> 0 && snapLineLocation.x-CGRectGetWidth(self.nodeInfoController.view.frame)/4< CGRectGetWidth(self.orderLineView.frame)-4) {
if (snapLineLocation.y+CGRectGetWidth(self.nodeInfoController.view.frame)/4> 0 && snapLineLocation.x< CGRectGetWidth(self.orderLineView.frame)-4) {//订阅:部分栏目方块仅按住就能被订阅(bug:5668)
self.orderLineView.hidden = NO;
}else {
self.orderLineView.hidden = YES;
}
CGPoint location = [longPress locationInView:self.view];
// if (location.x <= self.nodeInfoController.view.frame.origin.x) {
// return;
// }
/**
* bug:5214(【倒退】在栏目导航页,长按一个栏目拖到左边订阅栏,订阅栏卡主)
*/
CGPoint collectLoaction = location;
collectLoaction.x = collectLoaction.x + self.nodeInfoController.collectionView.contentOffset.x-CGRectGetWidth(self.nodeBtnView.frame);
collectLoaction.y = collectLoaction.y + self.nodeInfoController.collectionView.contentOffset.y;
NSIndexPath *indexPath = [self.nodeInfoController.collectionView indexPathForItemAtPoint:collectLoaction];
if (self.currentIndex == 4) {
[self myOrderLongPress:longPress indexPath:indexPath];
return;
}
// //订阅导航页:在登录情况下长按各频道,拖动到订阅处闪退(bug:5497)
// if (!indexPath) {
// return;
// }
static UIView *snapshot = nil;
static NSIndexPath *sourceIndexPath = nil;
switch (state) {
case UIGestureRecognizerStateBegan: {
if (indexPath) {
needGestureOfSideController(NO);
[self.view insertSubview:self.orderedView aboveSubview:self.nodeBtnView];
[CoreAnimationEffect animationEaseOut:self.view];
if(!indexPath) {
return;
}
sourceIndexPath = indexPath;
nodeInfoCell *cell = (nodeInfoCell*)[self.nodeInfoController.collectionView cellForItemAtIndexPath:indexPath];
[cell setHighlighted:NO];
cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
__block nodeInfoCell *Cell = cell;
// Take a snapshot of the selected row using helper method.
snapshot = [self customSnapshoFromView:cell];
__block CGPoint center = cell.center;
center.y = location.y;
center.x = location.x;
snapshot.center = center;
snapshot.alpha = 0.0;
[self.view addSubview:snapshot];
[UIView animateWithDuration:0.2 animations:^{
center.y = location.y;
center.x = location.x;
snapshot.center = center;
snapshot.transform = CGAffineTransformMakeScale(1.1, 1.1);
snapshot.alpha = 0.98;
} completion:^(BOOL finished) {
Cell.backgroundColor = [UIColor colorWithHexString:GRAYCOLOR];
}];
}
break;
}
case UIGestureRecognizerStateChanged: {
CGPoint center = snapshot.center;
center.y = location.y;
center.x = location.x;
snapshot.center = center;
break;
}
default: {
//订阅导航页:在登录情况下长按各频道,拖动到订阅处闪退(bug:5497)
if (!sourceIndexPath) {
return;
}
//clean up.
nodeInfoCell *cell = (nodeInfoCell*)[self.nodeInfoController.collectionView cellForItemAtIndexPath:sourceIndexPath];
__block nodeInfoCell *Cell = cell;
__block CGPoint snapShotCenter = cell.center;
if (self.orderLineView.hidden) {
[UIView animateWithDuration:0.35 animations:^{
snapShotCenter.x = Cell.center.x - self.nodeInfoController.collectionView.contentOffset.x+CGRectGetWidth(self.nodeBtnView.frame);
snapShotCenter.y = Cell.center.y - self.nodeInfoController.collectionView.contentOffset.y;
snapshot.center = snapShotCenter;
snapshot.transform = CGAffineTransformIdentity;
snapshot.alpha = 0.0f;
Cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[Cell setHighlighted:NO];
} completion:^(BOOL finished) {
needGestureOfSideController(YES);
[snapshot removeFromSuperview];
snapshot = nil;
[self.view insertSubview:self.nodeBtnView aboveSubview:self.orderedView];
[CoreAnimationEffect animationEaseOut:self.view];
}];
}else {
[UIView animateWithDuration:0.35 animations:^{
snapShotCenter = self.orderLineView.center;
snapShotCenter.y = snapShotCenter.y + 70;
snapshot.center = snapShotCenter;
snapshot.transform = CGAffineTransformMakeScale(0.1,0.1);
snapshot.alpha = 0.0f;
// [self.scrollTimer invalidate];
} completion:^(BOOL finished) {
Cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[Cell setHighlighted:NO];
needGestureOfSideController(YES);
[snapshot removeFromSuperview];
snapshot = nil;
nodeObjectBO *nodeBO = Cell.nodeInfoBO;
__block BOOL isHaveOrdered = NO;
[self.orderChildList enumerateObjectsUsingBlock:^(nodeObjectBO* obj, NSUInteger idx, BOOL *stop) {
if (idx > 0) {
if ([nodeBO.nodeId doubleValue] == [obj.nodeId doubleValue]) {
isHaveOrdered = YES;
}
}
}];
if (isHaveOrdered) {
ShowMessage(@"订阅成功", YES);
}else {
NSDictionary *dic = @{@"n":nodeBO.nodeId,@"oType":@"1"};
[Remote doJsonAction:[nodeBO.nodeId intValue]
requestUrl:orderNodeURL
parameter:dic
delegate:self];
}
isHaveOrdered = NO;
[self.view insertSubview:self.nodeBtnView aboveSubview:self.orderedView];
[CoreAnimationEffect animationEaseOut:self.view];
}];
}
sourceIndexPath = nil;
break;
}
}
}
- (void)myOrderLongPress:(UILongPressGestureRecognizer*)longPress indexPath:(NSIndexPath*)indexPath { //the long press for order page
UIGestureRecognizerState state = longPress.state;
if (indexPath.row == 0) {
return;
}
nodeInfoCell *cell = (nodeInfoCell*)[self.nodeInfoController.collectionView cellForItemAtIndexPath:indexPath];
switch (state) {
case UIGestureRecognizerStateBegan: {
if(!indexPath) {
return;
}
// [cell setHighlighted:NO];
[self.nodeInfoController openDeleteMode];
break;
}
default: {
cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[cell setHighlighted:NO];
break;
}
}
}
#pragma mark - make snapshot method
- (UIView *)customSnapshoFromView:(UIView *)inputView { //The method that 'snapshotViewAfterScreenUpdates' has bugs in iphone 6 and 6+
UIView *snapshot = UIView.new;
// if ([inputView respondsToSelector:@selector(snapshotViewAfterScreenUpdates:)]) { //ios 7 snapshot method
// snapshot = [inputView snapshotViewAfterScreenUpdates:YES];
// snapshot.layer.masksToBounds = NO;
// snapshot.layer.cornerRadius = 0.0;
// }else { //...make snapshot avilibile under ios7
// snapshot = [[UIView alloc]initWithFrame:inputView.frame];
// UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, inputView.opaque, 10.0);
// [inputView.layer renderInContext:UIGraphicsGetCurrentContext()];
// UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
// UIImageView *imageView = [[UIImageView alloc]initWithImage:viewImage];
// [snapshot addSubview:imageView];
// }
snapshot = [[UIView alloc]initWithFrame:inputView.frame];
UIGraphicsBeginImageContextWithOptions(inputView.bounds.size, inputView.opaque, 7.0);
[inputView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *imageView = [[UIImageView alloc]initWithImage:viewImage];
[snapshot addSubview:imageView];
snapshot.layer.shadowOffset = CGSizeMake(2.0, 2.0);
snapshot.layer.shadowRadius = 1.0;
snapshot.layer.shadowOpacity = 0.4;
snapshot.tag = 7000;
return snapshot;
}
- (void)refreshAfterOpenNightMode:(NSNotification*)noti {
// [self.lineView removeFromSuperview];
// [self.nodeBtnView removeFromSuperview];
// self.nodeBtnView = nil;
// [self.orderedView removeFromSuperview];
//
// NSMutableArray *array = self.nodeListArray;
// self.nodeListArray = array;
//
// [self.nodeInfoController.collectionView reloadData];
self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.lineView.backgroundColor = [UIColor colorWithHexString:BackGrayGroundColor];
self.nodeBtnView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.orderedView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
UILabel *titleLabel = (UILabel*)[_orderedView viewWithTag:ORDEREDVIEWTAG];
titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
titleLabel.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[orderButtonArray enumerateObjectsUsingBlock:^(UIButton* button, NSUInteger idx, BOOL *stop) {
button.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[button setTitleColor:[UIColor colorWithHexString:TextBlack] forState:UIControlStateNormal];
//夜间模式:进入订阅页,文字下方的英文反色错误(bug:6076)
if(!button.selected){
UILabel *label = (UILabel*)[button viewWithTag:button.tag - ORDERBUTTONTAG+ORDERLABELTAG];
label.textColor = [UIColor colorWithHexString:TextBlack];
}
UIView *line = [button viewWithTag:1000];
line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}];// 栏目导航页:切换夜间模式后有异常(bug:5667)
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
|