| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- //
- // FriendRequestTableViewCell.m
- // NIMDemo
- //
- // Created by Fenix Wang on 2017/7/29.
- // Copyright © 2017年 Netease. All rights reserved.
- //
- #import "FriendRequestTableViewCell.h"
- #import "User.h"
- #import "UIView+NTES.h"
- #import "NIMAvatarImageView.h"
- @interface FriendRequestTableViewCell()
- @property (weak, nonatomic) IBOutlet UIView *avatarContainer;
- @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
- @property (weak, nonatomic) IBOutlet UILabel *descLabel;
- @property (weak, nonatomic) IBOutlet UIButton *btn;
- @property (nonatomic, strong) NIMAvatarImageView *avatar;
- @property (nonatomic, strong) id data;
- @end
- @implementation FriendRequestTableViewCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
-
- _btn.layer.cornerRadius = 3;
-
- [self setData:_data];
-
-
- UILongPressGestureRecognizer *longPressGesture= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longGesturePress:)];
- [self addGestureRecognizer:longPressGesture];
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (void)setData:(id)data{
- _data = data;
-
- if(!_avatarContainer || !data)
- {
- return;
- }
-
- if(!_avatar)
- {
- _avatar = [[NIMAvatarImageView alloc] initWithFrame:CGRectMake(0, 0, _avatarContainer.width, _avatarContainer.height)];
- [_avatarContainer addSubview:_avatar];
- }
-
- __weak typeof(self) wself = self;
- if([data isKindOfClass:[FriendRequestData class]])
- {
- FriendRequestData *friendRequestData = data;
- NIMUser *user = [[NIMSDK sharedSDK].userManager userInfo:friendRequestData.userId];
- NSURL *url = user.userInfo.avatarUrl ? [NSURL URLWithString:user.userInfo.avatarUrl] : nil;
- [wself.avatar nim_setImageWithURL:url placeholderImage:User.defaultUserAvatar];
-
- wself.nameLabel.text = [[User sharedInfo] getUserName:user];
- _descLabel.text = friendRequestData.msg;
-
- _btn.hidden = NO;
- }
- // else if([data isKindOfClass:[NIMSystemNotification class]])
- // {
- // NIMSystemNotification *systemData = data;
- // NIMKitInfo *sourceMember = [[NIMKit sharedKit] infoByUser:systemData.sourceID option:nil];
- // NIMSystemNotificationType type = systemData.type;
- // NSString *avatarUrlString = sourceMember.avatarUrlString;
- // NSURL *url;
- // if (avatarUrlString.length) {
- // url = [NSURL URLWithString:avatarUrlString];
- // }
- // [self.avatar nim_setImageWithURL:url placeholderImage:User.defaultUserAvatar];
- //
- // NIMUser *nimUser = [[NIMSDK sharedSDK].userManager userInfo:systemData.sourceID];
- // wself.nameLabel.text = [[User sharedInfo] getUserName:nimUser];
- //
- // switch (type) {
- // case NIMSystemNotificationTypeTeamApply:
- // {
- // NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:systemData.targetID];
- // self.descLabel.text = [NSString stringWithFormat:@"申请加入群 %@ %@", team.teamName, systemData.postscript ? systemData.postscript : @""];
- // _btn.hidden = NO;
- // }
- // break;
- // case NIMSystemNotificationTypeTeamApplyReject:
- // {
- // NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:systemData.targetID];
- // self.descLabel.text = [NSString stringWithFormat:@"群 %@ 拒绝你加入", team.teamName];
- // _btn.hidden = YES;
- // }
- // break;
- // case NIMSystemNotificationTypeTeamInvite:
- // {
- // NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:systemData.targetID];
- // self.descLabel.text = [NSString stringWithFormat:@"群 %@ 邀请你加入", team.teamName];
- // _btn.hidden = NO;
- // }
- // break;
- // case NIMSystemNotificationTypeTeamIviteReject:
- // {
- // NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:systemData.targetID];
- // self.descLabel.text = [NSString stringWithFormat:@"拒绝了群 %@ 邀请", team.teamName];
- // _btn.hidden = YES;
- // }
- // break;
- // case NIMSystemNotificationTypeFriendAdd:
- // {
- // NSString *text = @"未知请求";
- // id object = systemData.attachment;
- // if ([object isKindOfClass:[NIMUserAddAttachment class]]) {
- // NIMUserOperation operation = [(NIMUserAddAttachment *)object operationType];
- // switch (operation) {
- // case NIMUserOperationAdd:
- // text = @"已添加你为好友";
- // break;
- // case NIMUserOperationRequest:
- // text = @"请求添加你为好友";
- // break;
- // case NIMUserOperationVerify:
- // text = @"通过了你的好友请求";
- // break;
- // case NIMUserOperationReject:
- // text = @"拒绝了你的好友请求";
- // break;
- // default:
- // break;
- // }
- // }
- // self.descLabel.text = text;
- // }
- // break;
- // default:
- // break;
- // }
- //
- // }
- }
- - (void)longGesturePress:(UIGestureRecognizer*)gestureRecognizer
- {
- if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] &&
- gestureRecognizer.state == UIGestureRecognizerStateBegan) {
- if (self.delegate && [self.delegate respondsToSelector:@selector(friendRequestDelete:)]) {
- [self.delegate friendRequestDelete:_data];
- }
- }
- }
- - (IBAction)onTouchAccept:(id)sender {
- if (self.delegate && [self.delegate respondsToSelector:@selector(friendRequestAccept:)]) {
- [self.delegate friendRequestAccept:_data];
- }
- }
- @end
|