123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- //
- // ContactTableViewCell.m
- // NIMDemo
- //
- // Created by Fenix Wang on 2017/7/29.
- // Copyright © 2017年 Netease. All rights reserved.
- //
- #import "ContactTableViewCell.h"
- #import "User.h"
- #import "UIView+NTES.h"
- #import "NIMAvatarImageView.h"
- #import "AddFriendViewController.h"
- #import "HttpRequest.h"
- #import "UIView+Toast.h"
- @interface ContactTableViewCell()
- @property (weak, nonatomic) IBOutlet UIView *avatarContainer;
- @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
- @property (weak, nonatomic) IBOutlet UILabel *descLabel;
- @property (weak, nonatomic) IBOutlet UIButton *actionBtn;
- @property (nonatomic, strong) NIMAvatarImageView *avatar;
- @property (nonatomic, strong) ContactData *data;
- @end
- @implementation ContactTableViewCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
-
- _actionBtn.layer.cornerRadius = 3;
- [self setData:_data];
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (void)setData:(ContactData *)data{
- _data = data;
-
- if(!data)
- return;
-
- if(!_avatar)
- {
- _avatar = [[NIMAvatarImageView alloc] initWithFrame:CGRectMake(0, 0, _avatarContainer.width, _avatarContainer.height)];
- [_avatarContainer addSubview:_avatar];
- }
-
- NSURL *url = nil;
- if(data.userId)
- {
- NIMUser *user = [[NIMSDK sharedSDK].userManager userInfo:data.userId];
-
- url = user.userInfo && user.userInfo.avatarUrl ? [NSURL URLWithString:user.userInfo.avatarUrl] : nil;
-
- _nameLabel.text = data.name;
- BOOL isFollow = [[User sharedInfo] isFollowd:data.userId];
- if(isFollow)
- {
- [_actionBtn setBackgroundColor:UIColor.clearColor];
- [_actionBtn setTitle:@"已添加" forState:UIControlStateNormal];
- [_actionBtn setTitleColor:UIColor.lightGrayColor forState:UIControlStateNormal];
- [_actionBtn setUserInteractionEnabled:NO];
- }
- else
- {
- [_actionBtn setBackgroundColor:User.greenColor];
- [_actionBtn setTitle:@"添加" forState:UIControlStateNormal];
- [_actionBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
- [_actionBtn setUserInteractionEnabled:YES];
- }
-
- if(data.follow > 0)
- {
- _descLabel.text = [NSString stringWithFormat:@"%@已经关注了你", data.name];
- }
- else
- {
- _descLabel.text = [data.phones objectAtIndex:0];
-
- }
- }
- else
- {
- _nameLabel.text = data.name;
- _descLabel.text = [data.phones objectAtIndex:0];
-
- if(_data.msgSend)
- {
- [_actionBtn setBackgroundColor:UIColor.clearColor];
- [_actionBtn setTitle:@"已发送" forState:UIControlStateNormal];
- [_actionBtn setTitleColor:UIColor.lightGrayColor forState:UIControlStateNormal];
- [_actionBtn setUserInteractionEnabled:NO];
- }
- else
- {
- [_actionBtn setBackgroundColor:User.orangeColor];
- [_actionBtn setTitle:@"邀请" forState:UIControlStateNormal];
- [_actionBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
- [_actionBtn setUserInteractionEnabled:YES];
- }
- }
-
- [_avatar nim_setImageWithURL:url placeholderImage:User.defaultUserAvatar];
- }
- - (IBAction)onTouchActionBtn:(id)sender {
-
- if(_data.userId)
- {
- UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
- AddFriendViewController *vc = [board instantiateViewControllerWithIdentifier:@"AddFriend"];
- [vc setUserId:_data.userId];
- [self.viewController.navigationController pushViewController:vc animated:YES];
- }
- else
- {
- [[HttpRequest shared] sendMsg:_data.phones[0] success:^{
- [self makeToast:@"发送成功" duration:2.0 position:CSToastPositionCenter];
- _data.msgSend = YES;
- [self setData:_data];
- } failure:^{
- [self makeToast:@"发送失败,请重试" duration:2.0 position:CSToastPositionCenter];
- }];
- }
- }
- @end
|