remove callButton from contactItemCell

 

@interface IPhoneMVContactItemCell()

 

@property(nonatomic, retain) CVUserIconView* iconView;

@property(nonatomic, retain) UILabel* nameLabel;

@property(nonatomic, retain) UILabel* titleLabel;

@property(nonatomic, retain) UILabel* companyLabel;

@property(nonatomic, retain) UILabel* messageLabel;

@property(nonatomic, retain) UILabel* tsLabel;

@property(nonatomic, retain) UIButton* callButton;

 

@end

 

@implementation IPhoneMVContactItemCell

 

– (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)identifier {

 

if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) {

        

        _iconView = [[CVUserIconView alloc] init];

        

        _nameLabel = [[UILabel alloc] init];

        _nameLabel.font = [UIFont boldSystemFontOfSize:13];

        _nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;

        _nameLabel.textAlignment = NSTextAlignmentLeft;

        _nameLabel.backgroundColor = [UIColor clearColor];

        _nameLabel.textColor = [UIColor blackColor];

        _nameLabel.highlightedTextColor = [UIColor whiteColor];

        

        _titleLabel = [[UILabel alloc] init];

        _titleLabel.numberOfLines = 2;

        _titleLabel.font = [UIFont systemFontOfSize:11];

        _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;

        _titleLabel.textAlignment = NSTextAlignmentLeft;

        _titleLabel.backgroundColor = [UIColor clearColor];

        _titleLabel.textColor = [UIColor darkGrayColor];

        _titleLabel.highlightedTextColor = [UIColor whiteColor];

        

        

        _companyLabel = [[UILabel alloc] init];

        _companyLabel.font = [UIFont systemFontOfSize:11];

        _companyLabel.lineBreakMode = NSLineBreakByTruncatingTail;

        _companyLabel.textAlignment = NSTextAlignmentLeft;

        _companyLabel.backgroundColor = [UIColor clearColor];

        _companyLabel.textColor = [UIColor darkGrayColor];

        _companyLabel.highlightedTextColor = [UIColor whiteColor];

        

        _messageLabel = [[UILabel alloc] init];

        _messageLabel.font = [UIFont systemFontOfSize:12];

        _messageLabel.textColor = [UIColor darkGrayColor];

        _messageLabel.textAlignment = NSTextAlignmentRight;

        _messageLabel.backgroundColor = [UIColor clearColor];

        

        _tsLabel = [[UILabel alloc] init];

        _tsLabel.font = [UIFont systemFontOfSize:12];

        _tsLabel.textAlignment = NSTextAlignmentRight;

        _tsLabel.backgroundColor = [UIColor clearColor];

        

//        _callButton = [UIButton buttonWithType:UIButtonTypeCustom];

//        _callButton.frame = CGRectMake(0, 0, 55, 35);

//        [_callButton setImage:[CVColorNamedIcon iconNamed:@”Chat”]  forState:UIControlStateNormal];

//        //[_callButton setImage:[UIImage imageNamed:@”phone-icon.png”] forState:UIControlStateNormal];

//        _callButton.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 15, 0);

        

        [self.contentView addSubview:_iconView];

        [self.contentView addSubview:_nameLabel];

        [self.contentView addSubview:_titleLabel];

        [self.contentView addSubview:_companyLabel];

        [self.contentView addSubview:_messageLabel];

        [self.contentView addSubview:_tsLabel];

//        self.accessoryView = _callButton;

}

return self;

}

 

+ (CGFloat)tableView:(UITableView*)tableView rowHeightForObject:(id)object {

    return TB_PADDING*2 + ICON_HEIGHT;

}

 

– (void)prepareForReuse {

    [_iconView unsetImage];

    

//    _callButton.hidden = YES;

    _callingDelegate = nil;

}

 

-(void)setObject:(id)object {

    

    [super setObject:object];

    

    _item = (CVContactItem*)object;

    [_iconView setIconWithUser:_item];

    [CVAPIUtil formatUserNameLabel:_nameLabel withUser:_item firstFont:FONT_FIRSTNAME lastFont:FONT_LASTNAME];

    //search result might not have first/last name field but displayName

    if([_nameLabel.text length] == 0 && [_item.displayName length] >0 ) {

        _nameLabel.text = _item.displayName;

    }

    

    self.accessoryType = _item.checked ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;

 

    _titleLabel.text = LS(_item.jobTitle, @””);

    _companyLabel.text = LS(_item.company, @””);

    _messageLabel.text = @”some message”;

    _tsLabel.text = @”11/24/2012″;

    

//    if (![_item.key isEqualToString:[CVAPIUtil getUserKey]]) {

//

//        _callButton.hidden = NO;

//

//        NSString* phoneNum = _item.phone;

//        BOOL hasPhoneNum = (nil != phoneNum && ![phoneNum isEqualToString:@””]);

//        BOOL deviceSupportPhoneCalls = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@”tel://”]];

//        if( hasPhoneNum && deviceSupportPhoneCalls) {

//            [_callButton removeTarget:nil action:nil forControlEvents:UIControlEventAllEvents];

//            [_callButton setImage:[CVColorNamedIcon iconNamed:@”Menu”]  forState:UIControlStateNormal];

//            [_callButton addTarget:self action:@selector(callButtonTouched:) forControlEvents:UIControlEventTouchUpInside];

//        } else {

//            [_callButton removeTarget:nil action:nil forControlEvents:UIControlEventAllEvents];

//            [_callButton setImage:[CVColorNamedIcon iconNamed:@”Chat”]  forState:UIControlStateNormal];

//            [_callButton addTarget:self action:@selector(chatButtonTouched:) forControlEvents:UIControlEventTouchUpInside];

//        }

//    }

}

 

 

– (void)layoutSubviews {

    

    [super layoutSubviews];

    

    // enlarge the button area, but not the button image

//    _callButton.height = self.contentView.height;

//    _callButton.top = 0;

//    self.accessoryView.left = self.contentView.width + 15;

//    _callButton.imageEdgeInsets = UIEdgeInsetsMake((self.contentView.height – BUTTON_IMG_HEIGHT)/2,

//                                                   (_callButton.width – BUTTON_IMG_WIDTH)/2,

//                                                   (self.contentView.height – BUTTON_IMG_HEIGHT)/2,

//                                                   (_callButton.width – BUTTON_IMG_WIDTH)/2);

    

    _iconView.frame = CGRectMake(LR_PADDING, TB_PADDING, ICON_WIDTH, ICON_HEIGHT);

    CGFloat left = LR_PADDING + ICON_WIDTH + 10;

    CGFloat width = self.contentView.width – left + 15;

    

    CGFloat widthAccording2FirstNameFont = [_nameLabel.text sizeWithFont:FONT_FIRSTNAME constrainedToSize:CGSizeMake(width, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping].width;

    CGFloat widthAccording2LastNameFont = [_nameLabel.text sizeWithFont:FONT_LASTNAME constrainedToSize:CGSizeMake(width, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping].width;

    CGFloat widthForName = MIN(MAX(widthAccording2FirstNameFont, widthAccording2LastNameFont), width);

    

    //it seems that server return ” ” from task..maybe bug

    _item.jobTitle = [_item.jobTitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

    _item.company = [_item.company stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

    if ([_item.jobTitle isEqualToString:@””] && [_item.company isEqualToString:@””]){

        _nameLabel.frame = CGRectMake(left, _iconView.frame.origin.y + 11, widthForName, NAME_HEIGHT);

        //_nameLabel.frame = CGRectMake(left, _iconView.frame.origin.y + 5, widthForName, NAME_HEIGHT);

        CGFloat nameLabelBottom = _nameLabel.frame.origin.y + _nameLabel.frame.size.height;

        _titleLabel.frame = CGRectMake(left, nameLabelBottom, width, TITLE_HEIGHT);

        _companyLabel.frame = CGRectMake(left, _titleLabel.bottom, width, TITLE_HEIGHT);

    } else if ([_item.jobTitle isEqualToString:@””] && ![_item.company isEqualToString:@””]){

        _nameLabel.frame = CGRectMake(left, _iconView.frame.origin.y + 3, widthForName, NAME_HEIGHT);

        _companyLabel.frame = CGRectMake(left, _nameLabel.bottom , width, TITLE_HEIGHT);

    } else if (![_item.jobTitle isEqualToString:@””] && [_item.company isEqualToString:@””]) {

        _nameLabel.frame = CGRectMake(left, _iconView.frame.origin.y + 3, widthForName, NAME_HEIGHT);

        _titleLabel.frame = CGRectMake(left, _nameLabel.bottom, width, TITLE_HEIGHT);

    } else {

        _nameLabel.frame = CGRectMake(left, _iconView.frame.origin.y -2, widthForName, NAME_HEIGHT);

        CGFloat nameLabelBottom = _nameLabel.frame.origin.y + _nameLabel.frame.size.height;

        _titleLabel.frame = CGRectMake(left, nameLabelBottom, width, TITLE_HEIGHT);

        _companyLabel.frame = CGRectMake(left, _titleLabel.bottom – 2, width, TITLE_HEIGHT);

    }

    

    _tsLabel.frame = CGRectMake(self.contentView.width – LR_PADDING*3 – 100, _iconView.top, 100, TITLE_HEIGHT);

    _tsLabel.hidden = YES;

}

 

– (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    /*

     _tsLabel.textColor = selected ? [UIColor whiteColor] : [UIColor blackColor];

     _messageLabel.textColor = selected ? [UIColor whiteColor] : [UIColor blackColor];

     */

    return;

}

 

– (void)callButtonTouched:(UIButton *)button {

    

    if ([_callingDelegate respondsToSelector:@selector(makeACall2User:fromView:)]) {

        [_callingDelegate makeACall2User:((CVContactItem*)self.object) fromView:button];

    }

}

 

– (void)chatButtonTouched:(UIButton *)button {

 

    NSArray *recipient = @[[CVAPIUtil getDictionaryFromObject:_item]];

    IPhoneMVChatEditWithExistViewController* chatVC = [[IPhoneMVChatEditWithExistViewController alloc] initWithContacts:recipient chats:nil];

    chatVC.destKey = @”Contact”;

    [chatVC pushToStack];

}

 

@end

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s