|
//
// nodeInfoCell.m
// ThePaperDemo
//
// Created by scar1900 on 14-9-30.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "nodeInfoCell.h"
#import "AsyncImageView.h"
@interface nodeInfoCell()<RemoteDelegate>
@property(nonatomic, strong)AsyncImageView *nodeImageView;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UIButton *deleteButton;
@end
@implementation nodeInfoCell
@synthesize nodeInfoBO = _nodeInfoBO;
@synthesize isDelete = _isDelete;
@synthesize cellIndex = _cellIndex;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
[self addSubview:self.nodeImageView];
[self addSubview:self.titleLabel];
[self addSubview:self.deleteButton];
UIView *cellHLineView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds)-1, CGRectGetWidth(self.bounds), 1)];
cellHLineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
cellHLineView.tag = 1000;
[self addSubview:cellHLineView];
UIView *cellVLineView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.bounds)-1,0, 1, CGRectGetHeight(self.bounds))];
cellVLineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
cellVLineView.tag = 1001;
[self addSubview:cellVLineView];
UIView *cellHLineTopView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), 1)];
cellHLineTopView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
cellHLineTopView.tag = 1002;
[self addSubview:cellHLineTopView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAfterOpenNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)setCellIndex:(NSInteger)index {
_cellIndex = index;
UIView *cellHLineTopView = [self viewWithTag:1002];
if (index < 3) {
cellHLineTopView.hidden = NO;
}else {
cellHLineTopView.hidden = YES;
}
}
- (void)setNodeInfoBO:(nodeObjectBO *)data {
_nodeInfoBO = data;
self.nodeImageView.imageUrl = data.pic;
self.titleLabel.text = data.name;
}
- (AsyncImageView*)nodeImageView {
if (!_nodeImageView) {
_nodeImageView = [[AsyncImageView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.bounds)/2-36/2, CGRectGetHeight(self.bounds)/2-36/2, 36, 36)];
_nodeImageView.imageView.backgroundColor = [UIColor clearColor];
_nodeImageView.backgroundColor = [UIColor clearColor];
if (ISNotRETINA) {
_nodeImageView.isNeedCorner = YES;
}
}
return _nodeImageView;
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,
CGRectGetMaxY(self.nodeImageView.frame)+15,
CGRectGetWidth(self.bounds),
18)];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
_titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_titleLabel.font = appFont(18, NO);
return _titleLabel;
}
- (UIButton*)deleteButton {
if (!_deleteButton) {
_deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
_deleteButton.frame = CGRectMake(CGRectGetWidth(self.bounds)-41-5/2, 0, 41+5/2, 41+5/2);
[_deleteButton setImage:Image(@"Button/delete.png") forState:UIControlStateNormal];
[_deleteButton setImage:Image(@"Button/delete_s.png") forState:UIControlStateHighlighted];
_deleteButton.hidden = YES;
[_deleteButton setImageEdgeInsets:UIEdgeInsetsMake(5/2, 41/2, 41/2, 5/2)];
[_deleteButton addTarget:self action:@selector(cancelOrder:) forControlEvents:UIControlEventTouchUpInside];
}
return _deleteButton;
}
- (void)setIsDelete:(BOOL)delete {
self.backgroundColor = [UIColor clearColor];
if (_isDelete == delete) {
return;
}
_isDelete = delete;
if (delete) {
self.deleteButton.transform = CGAffineTransformMakeScale(0.0, 0.0);
[UIView animateWithDuration:0.3 animations:^{
self.deleteButton.transform = CGAffineTransformMakeScale(1.0, 1.0);
self.deleteButton.hidden = NO;
}];
}else {
[UIView animateWithDuration:0.3 animations:^{
self.deleteButton.transform = CGAffineTransformMakeScale(0.0, 0.0);
self.deleteButton.hidden = YES;
}];
}
}
- (void)setSelected:(BOOL)selected {
[super setSelected:YES];
if (selected) {
self.backgroundColor = [UIColor colorWithHexString:GRAYCOLOR];
}else {
self.backgroundColor = [UIColor clearColor];
}
}
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
if (highlighted) {
self.backgroundColor = [UIColor colorWithHexString:GRAYCOLOR];
}else {
self.backgroundColor = [UIColor clearColor];
}
}
- (void)cancelOrder:(UIButton*)btn {
NSDictionary *dic = @{@"n":self.nodeInfoBO.nodeId,@"oType":@"2"};
[Remote doJsonAction:1
requestUrl:orderNodeURL
parameter:dic
delegate:self];
}
- (void)startWaitCursor:(int)actionTag {
}
- (void)stopWaitCursor:(int)actionTag {
}
- (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData {
if (responsData && [responsData[@"resultCode"] intValue] == 1) {
if (cancelOrderBlock) {
cancelOrderBlock(self.nodeInfoBO);
}
}
}
- (void)cancelOrderBlock:(void (^)(nodeObjectBO *))block {
cancelOrderBlock = [block copy];
}
- (void)layoutSubviews {
UIView *cellHLineView = [self viewWithTag:1000];
cellHLineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
cellHLineView.frame = CGRectMake(0, CGRectGetHeight(self.bounds)-1, CGRectGetWidth(self.bounds), 1);
UIView *cellVLineView = [self viewWithTag:1001];
cellVLineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
cellVLineView.frame = CGRectMake(CGRectGetWidth(self.bounds)-1,0, 1, CGRectGetHeight(self.bounds));
UIView *cellHLineTopView = [self viewWithTag:1002];
cellHLineTopView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
cellHLineTopView.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), 1);
}
- (void)refreshAfterOpenNightMode:(NSNotification*)noti {
[self layoutSubviews];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
@end
|