123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- //
- // UserInfoViewController.m
- // NIMDemo
- //
- // Created by Fenix Wang on 2017/7/14.
- // Copyright © 2017年 Netease. All rights reserved.
- //
- #import "UserInfoViewController.h"
- #import "UIView+NTES.h"
- #import "NIMAvatarImageView.h"
- #import "UIImageView+WebCache.h"
- #import "AppDelegate.h"
- #import "User.h"
- #import "NTESSessionViewController.h"
- #import "UserGiftViewController.h"
- #import "HttpRequest.h"
- #import "UIView+Toast.h"
- @interface UserInfoViewController ()
- @property (weak, nonatomic) IBOutlet UIImageView *bannerImage;
- @property (weak, nonatomic) IBOutlet UIView *avatarContainer;
- @property (weak, nonatomic) IBOutlet UIImageView *genderImage;
- @property (weak, nonatomic) IBOutlet UILabel *nickLabel;
- @property (weak, nonatomic) IBOutlet UILabel *idLabel;
- @property (weak, nonatomic) IBOutlet UIButton *followBtn;
- @property (weak, nonatomic) IBOutlet UIButton *msgBtn;
- @property (weak, nonatomic) IBOutlet UIButton *giftBtn;
- @property (weak, nonatomic) IBOutlet UILabel *picTitle;
- @property (weak, nonatomic) IBOutlet UIView *picContainer;
- @property (weak, nonatomic) IBOutlet UILabel *morePicLabel;
- @property (weak, nonatomic) IBOutlet UILabel *ageLabel;
- @property (weak, nonatomic) IBOutlet UILabel *hobbyLabel;
- @property (weak, nonatomic) IBOutlet UILabel *addressLabel;
- @property (nonatomic, strong) NIMAvatarImageView *avatar;
- @property (nonatomic, strong) NSString *userId;
- @property (nonatomic, strong) NIMUser *nimUser;
- @property (nonatomic, strong) UserInfo *userInfo;
- @property (nonatomic, assign) int followState;
- @end
- @implementation UserInfoViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.tableView.contentInset = UIEdgeInsetsMake(-69, 0, 0, 0);
-
- _followBtn.layer.borderColor = UIColor.lightGrayColor.CGColor;
- _followBtn.layer.borderWidth = 1;
- _followBtn.layer.cornerRadius = _followBtn.height/2;
-
- _msgBtn.layer.borderColor = UIColor.lightGrayColor.CGColor;
- _msgBtn.layer.borderWidth = 1;
- _msgBtn.layer.cornerRadius = _msgBtn.height/2;
-
- _giftBtn.layer.cornerRadius = _giftBtn.height/2;
-
- if(_userInfo)
- {
- [self followState:_userInfo.follow];
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
-
- [self.navigationItem setTitle:@""];
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate transparentNavBar:self];
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate orangeNavBar:self];
- }
- - (void)setUserId:(NSString *)userId{
- __weak typeof(self) wself = self;
- [[HttpRequest shared] userInfo:userId success:^(UserInfo *userInfo) {
- [wself setUser:userInfo];
- } failure:^{
-
- }];
- }
- - (void)setUser:(UserInfo *)userInfo{
- _userId = userInfo.userId;
- self.userInfo = userInfo;
- [self followState:userInfo.follow];
- [self fetchNIMUser];
- }
- - (void)fetchNIMUser{
- __weak typeof(self) wself = self;
- [[NIMSDK sharedSDK].userManager fetchUserInfos:@[_userId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
- _nimUser = [users objectAtIndex:0];
- [wself fillInfo];
- }];
- }
- - (void)fillInfo
- {
-
- if(!_avatar)
- {
- _avatar = [[NIMAvatarImageView alloc] initWithFrame:CGRectMake(0, 0, _avatarContainer.width, _avatarContainer.height)];
- [_avatarContainer addSubview:_avatar];
- }
- NSURL *url = _nimUser.userInfo.avatarUrl ? [NSURL URLWithString:_nimUser.userInfo.avatarUrl] : nil;
- [_avatar nim_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"avatar_user2"]];
- [_genderImage setImage:[[User sharedInfo] getGenderImg:_nimUser]];
- _nickLabel.text = [[User sharedInfo] getUserName:_nimUser];
- _idLabel.text = [NSString stringWithFormat:@"ID:%@", _nimUser.userId];
-
- if(_userInfo.showAge > 0)
- {
- if(_userInfo.age > 0)
- {
- _ageLabel.text = [@(_userInfo.age) stringValue];
- }
- else
- {
- _ageLabel.text = @"未知";
- }
- }
- else
- {
- _ageLabel.text = @"保密";
- }
-
- NSString *hobby = _userInfo.hobbyStr;
- if(hobby && hobby.length > 0)
- {
- _hobbyLabel.text = hobby;
- }
- else
- {
- _hobbyLabel.text = @"";
- }
-
- if(_userInfo.city && _userInfo.district && _userInfo.city.length > 0 && _userInfo.district.length > 0)
- {
- if([_userInfo.city isEqualToString:_userInfo.district])
- {
- _addressLabel.text = _userInfo.district;
- }
- else
- {
- _addressLabel.text = [NSString stringWithFormat:@"%@%@", _userInfo.city, _userInfo.district];
- }
- }
- else
- {
- _addressLabel.text = @"未知";
- }
-
-
- NSString *imgURL = _userInfo.socialBanner;
- url = imgURL && imgURL.length > 0 ? [NSURL URLWithString:imgURL] : nil;
- [_bannerImage sd_setImageWithURL:url placeholderImage:User.defaultSocialBanner];
- }
- - (void)followState:(int)state{
-
- _followState = state;
-
- if(state == 1)
- {
- [_followBtn setTitle:@"已关注" forState:UIControlStateNormal];
- }
- else if(state == 0)
- {
- [_followBtn setTitle:@"+关注" forState:UIControlStateNormal];
- }
- }
- - (IBAction)onTouchFollow:(id)sender {
-
- __weak typeof(self) wself = self;
- [[HttpRequest shared] follow:_userId success:^(int state) {
-
- [wself followState:state];
-
- if(state == 1)
- [wself.view makeToast:@"关注成功" duration:2.0 position:CSToastPositionCenter];
- else
- [wself.view makeToast:@"关注取消" duration:2.0 position:CSToastPositionCenter];
-
- } failure:^{
- [wself.view makeToast:@"操作失败" duration:2.0 position:CSToastPositionCenter];
- }];
-
- }
- - (IBAction)onTouchMsg:(id)sender {
- NIMSession *session = [NIMSession session:_userId type:NIMSessionTypeP2P];
- NTESSessionViewController *vc = [[NTESSessionViewController alloc] initWithSession:session];
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (IBAction)onTouchGift:(id)sender {
- UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
- UserGiftViewController *userGiftVC = [board instantiateViewControllerWithIdentifier:@"UserGift"];
- [userGiftVC setUser:_nimUser];
- [self.navigationController pushViewController:userGiftVC animated:YES];
- }
- - (IBAction)onTouchMorePic:(id)sender {
- NSLog(@"onTouchMorePic");
- }
- @end
|