|
//
// columnListController.m
// ThePaperHD
//
// Created by scar1900 on 15/1/7.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "columnListController.h"
#import "loginPopUpController.h"
@implementation nodeHeadView
@synthesize nodeData = _nodeData;
@synthesize delegate;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
[self addSubview:self.sponsorImageView];
[self addSubview:self.nodeImageView];
[self addSubview:self.titleLabel];
[self addSubview:self.orderButton];
UITapGestureRecognizer *sponsorTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapSponsor:)];
sponsorTap.numberOfTapsRequired = 1;
[self.sponsorImageView addGestureRecognizer:sponsorTap];
}
return self;
}
- (AsyncImageView*)sponsorImageView {
if (!_sponsorImageView) {
_sponsorImageView = [[AsyncImageView alloc]initWithFrame:CGRectZero];
_sponsorImageView.isHaveWaterPrint = NO;
_sponsorImageView.hidden = YES;
_sponsorImageView.userInteractionEnabled = YES;
}
return _sponsorImageView;
}
- (AsyncImageView*)nodeImageView {
if (!_nodeImageView) {
_nodeImageView = [[AsyncImageView alloc]initWithFrame:CGRectZero];
_nodeImageView.isHaveWaterPrint = NO;
_nodeImageView.hidden = YES;
_nodeImageView.imageView.backgroundColor = [UIColor clearColor];
_nodeImageView.backgroundColor = [UIColor clearColor];
if (ISNotRETINA) {
_nodeImageView.isNeedCorner = YES;
}
}
return _nodeImageView;
}
- (UIButton*)orderButton {
if (!_orderButton) {
_orderButton = [UIButton buttonWithType:UIButtonTypeCustom];
_orderButton.layer.cornerRadius = 3;
[_orderButton addTarget:self action:@selector(orderHandler:) forControlEvents:UIControlEventTouchUpInside];
[_orderButton setImage:Image(@"detailPage/addPic.png") forState:UIControlStateNormal];
[_orderButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
[_orderButton setTitle:@"订阅" forState:UIControlStateNormal];
_orderButton.titleLabel.textAlignment = NSTextAlignmentLeft;
_orderButton.titleLabel.textColor = [UIColor whiteColor];
_orderButton.clipsToBounds = YES;
_orderButton.hidden = YES;
}
_orderButton.titleLabel.font = appFont(25/2, NO);
return _orderButton;
}
- (void)setNodeData:(nodeObjectBO *)data {
_nodeData = data;
self.titleLabel.text = data.name;
if (data.sponsor) {
sponsorBO *sponsor = setJsonDicToDataModel(data.sponsor, [sponsorBO class]);
self.sponsorImageView.imageUrl = sponsor.logo;
}
self.nodeImageView.imageUrl = data.pic;
if ([data.isOrder intValue] == 1 && [TPUserDefault instance].userBO) {
self.orderButton.selected = YES;
[_orderButton setImage:Image(@"detailPage/orderedIcon.png") forState:UIControlStateNormal];
[_orderButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateNormal];
[_orderButton setTitle:@"已订阅" forState:UIControlStateNormal];
}else {
self.orderButton.selected = NO;
[_orderButton setImage:Image(@"detailPage/addPic.png") forState:UIControlStateNormal];
[_orderButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
[_orderButton setTitle:@"订阅" forState:UIControlStateNormal];
}
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.font = appFont(20, NO);
_titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.hidden = YES;
_titleLabel.backgroundColor = [UIColor clearColor];
}
return _titleLabel;
}
- (void)tapSponsor:(id)sender {
if ([self.delegate respondsToSelector:@selector(clickSponsor:)]) {
sponsorBO *sponsor = setJsonDicToDataModel(self.nodeData.sponsor, [sponsorBO class]);
[self.delegate clickSponsor:sponsor];
}
}
- (void)orderHandler:(UIButton*)btn {
if (!self.nodeData) {
return;
}
if ([self.delegate respondsToSelector:@selector(clickToOrder:isOrder:orderBtn:)]) {
[self.delegate clickToOrder:self.nodeData.nodeId isOrder:!btn.selected orderBtn:btn];
}
}
- (void)layoutSubviews {
if (self.nodeData.sponsor) {
self.sponsorImageView.frame = CGRectMake(0, CGRectGetHeight(self.bounds)/2-25/2, 100, 25);
}else {
self.sponsorImageView.frame = CGRectZero;
}
self.nodeImageView.frame = CGRectMake(CGRectGetMaxX(self.sponsorImageView.frame)+10,
CGRectGetHeight(self.bounds)/2-25/2,
25,
25);
CGFloat nodeButtonWidth = widthForString(self.nodeData.name, self.titleLabel.font, 25, NSLineBreakByWordWrapping);
self.titleLabel.frame =CGRectMake(CGRectGetMaxX(self.nodeImageView.frame)+10,
CGRectGetHeight(self.bounds)/2-20,
nodeButtonWidth,
40);
self.orderButton.frame = CGRectMake(CGRectGetMaxX(self.titleLabel.frame)+10, CGRectGetHeight(self.bounds)/2-25/2, 70, 25);
if (self.orderButton.selected) {
self.orderButton.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 70-5-28/2);
}else {
self.orderButton.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 70-5-15/2);
}
[self.orderButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
self.sponsorImageView.hidden = NO;
self.nodeImageView.hidden = NO;
self.titleLabel.hidden = NO;
self.orderButton.hidden = NO;
}
@end
@interface columnListController ()<nodeHeadViewDelegate>
@property(nonatomic, strong)NSString *titleStr;
@end
@implementation columnListController
@synthesize nodeObj = _nodeObj;
@synthesize listBO = _listBO;
@synthesize titleStr;
@synthesize nodeId;
- (void)viewDidLoad {
[super viewDidLoad];
[MobClick event:@"2"];
// Do any additional setup after loading the view.
self.navigationItem.titleView = nil;
self.navigationController.navigationBar.translucent=YES;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {
self.collectionView.refreshControl.originalContentInsectY = 64;
}else {
self.collectionView.refreshControl.originalContentInsectY = 44;
}
[self leftIconButton:@"Button/backBarBtnBlack.png" highlited:nil selector:@selector(backButtonHandler:)];
[self.navigationController.navigationBar addSubview:self.titleHeadView];
[self enablePopBackGesture];
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
[self setRefreshControlInsectY:0];
}
- (void)backButtonHandler:(id)sender {
if (!self.isPresent) {
[self.navigationController popViewControllerAnimated:YES];
}else {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
- (void)statusBarOrientationChange:(NSNotification *)notification
{
[self pagesDidChange];
CGFloat width = 0;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight
|| orientation ==UIInterfaceOrientationLandscapeLeft) {
width = 1024;
}else {
width = 768;
}
if (self.nodeObj.sponsor) {
self.titleHeadView.frame = CGRectMake(width/2-680/4, 0, 680/2, 40);
}else {
self.titleHeadView.frame = CGRectMake(width/2-460/4, 0, 460/2, 40);
}
}
- (nodeHeadView*)titleHeadView {
if (!_titleHeadView) {
_titleHeadView = [[nodeHeadView alloc]initWithFrame: CGRectMake(CGRectGetWidth(self.view.bounds)/2-460/4, 0, 460/2, 40)];
_titleHeadView.delegate = self;
}
return _titleHeadView;
}
- (void)setListBO:(listContObjectVO *)data {
_listBO = data;
NSDictionary *nodeInfo = data.nodeInfo;
self.titleStr = nodeInfo[@"name"];
self.nodeId = nodeInfo[@"nodeId"];
}
- (void)setNodeObj:(nodeObjectBO *)data {
_nodeObj = data;
self.titleStr = data.name;
self.nodeId = data.nodeId;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.titleHeadView.hidden = NO;
self.navigationController.navigationBarHidden = NO;
if (isIOS7) {
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
}else {
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
}
if (self.nodeObj.sponsor) {
self.titleHeadView.frame = CGRectMake(CGRectGetWidth(self.view.bounds)/2-680/4, 0, 680/2, 40);
}else {
self.titleHeadView.frame = CGRectMake(CGRectGetWidth(self.view.bounds)/2-460/4, 0, 460/2, 40);
}
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if ([array containsObject:self.nodeId]) {
self.titleHeadView.orderButton.selected = YES;
[self.titleHeadView.orderButton setImage:Image(@"detailPage/orderedIcon.png") forState:UIControlStateNormal];
[self.titleHeadView.orderButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateNormal];
[self.titleHeadView.orderButton setTitle:@"已订阅" forState:UIControlStateNormal];
}else {
self.titleHeadView.orderButton.selected = NO;
[self.titleHeadView.orderButton setImage:Image(@"detailPage/addPic.png") forState:UIControlStateNormal];
[self.titleHeadView.orderButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
[self.titleHeadView.orderButton setTitle:@"订阅" forState:UIControlStateNormal];
}
[self.titleHeadView layoutSubviews];
}
- (void)refreshRemoteMethod {
NSDictionary *dic = @{@"n":self.nodeId};
[Remote doJsonAction:1
requestUrl:nodeContentListURL
parameter:dic
delegate:self];
}
#pragma mark - needRefreshEnterForground
- (void)refreshFrontPage {
}
#pragma mark - headView delegate
- (void)clickSponsor:(sponsorBO *)sponsor {
if (isBlankString(sponsor.link)) {
return;
}
TPWebViewContoller *webVC = [[TPWebViewContoller alloc]init];
[self.navigationController pushViewController:webVC animated:YES];
webVC.url = sponsor.link;
}
- (void)clickToOrder:(NSString *)nodeID isOrder:(BOOL)isOrder orderBtn:(UIButton *)btn {
if ([TPUserDefault instance].userBO) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"n":nodeID,@"oType":@"1"}];
if (!isOrder) {
[dic setValue:@"2" forKey:@"oType"];
}
[Remote doJsonActionWithBlock:1 requestUrl:orderNodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
if (isOrder) {
btn.selected = YES;
ShowMessage(@"订阅成功", YES);
btn.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 70-5-28/2);
[btn setImage:Image(@"detailPage/orderedIcon.png") forState:UIControlStateNormal];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateNormal];
[btn setTitle:@"已订阅" forState:UIControlStateNormal];
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if (![array containsObject:nodeID]) {
[array addObject:nodeID];
[TPUserDefault instance].orderEventTempList = array;
}
}else {
btn.selected = NO;
ShowMessage(@"取消订阅", YES);
btn.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 70-5-15/2);
[btn setImage:Image(@"detailPage/addPic.png") forState:UIControlStateNormal];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
[btn setTitle:@"订阅" forState:UIControlStateNormal];
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if ([array containsObject:nodeID]) {
[array removeObject:nodeID];
[TPUserDefault instance].orderEventTempList = array;
}
}
}
}];
}else {
loginPopUpController *loginVC = loginPopUpController.new;
[self presentController:loginVC animated:YES presentSize:loginPopUpSize completion:^{
} dismiss:^{
if ([TPUserDefault instance].userBO) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:@{@"n":nodeID,@"oType":@"1"}];
if (!isOrder) {
[dic setValue:@"2" forKey:@"oType"];
}
[Remote doJsonActionWithBlock:1 requestUrl:orderNodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
if (isOrder) {
btn.selected = YES;
ShowMessage(@"订阅成功", YES);
btn.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 70-5-28/2);
[btn setImage:Image(@"detailPage/orderedIcon.png") forState:UIControlStateNormal];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateNormal];
[btn setTitle:@"已订阅" forState:UIControlStateNormal];
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if (![array containsObject:nodeID]) {
[array addObject:nodeID];
[TPUserDefault instance].orderEventTempList = array;
}
}else {
btn.selected = NO;
ShowMessage(@"取消订阅", YES);
btn.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 70-5-15/2);
[btn setImage:Image(@"detailPage/addPic.png") forState:UIControlStateNormal];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
[btn setTitle:@"订阅" forState:UIControlStateNormal];
NSMutableArray *array = [TPUserDefault instance].orderEventTempList;
if ([array containsObject:nodeID]) {
[array removeObject:nodeID];
[TPUserDefault instance].orderEventTempList = array;
}
}
}
}];
}
}];
}
}
#pragma mark - remote
- (void)configNodeInfoWithResData:(id)resData {
if (resData[@"nodeInfo"]) {
nodeObjectBO *node = setJsonDicToDataModel(resData[@"nodeInfo"], [nodeObjectBO class]);
self.nodeObj = node;
}
self.titleHeadView.nodeData = self.nodeObj;
if (self.nodeObj.sponsor) {
self.titleHeadView.frame = CGRectMake(CGRectGetWidth(self.view.bounds)/2-680/4, 0, 680/2, 40);
}else {
self.titleHeadView.frame = CGRectMake(CGRectGetWidth(self.view.bounds)/2-460/4, 0, 460/2, 40);
}
self.titleHeadView.hidden = NO;
[self.titleHeadView layoutSubviews];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.titleHeadView.hidden = YES;
}
- (void)dealloc {
[self.titleHeadView removeFromSuperview];
self.titleHeadView = nil;
}
- (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
|