Files
yinmeng-ios/xplan-ios/Main/Message/View/Session/SessionInfoViewController.m
2022-05-13 16:12:18 +08:00

298 lines
9.3 KiB
Objective-C

//
// SessionInfoViewController.m
// xplan-ios
//
// Created by 冯硕 on 2022/4/25.
//
#import "SessionInfoViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <NIMSDK/NIMSDK.h>
///Tool
#import "ThemeColor.h"
#import "NetImageView.h"
#import "TTPopup.h"
#import "XPHtmlUrl.h"
///View
#import "XPWebViewController.h"
#import "XPMineUserInfoViewController.h"
@interface SessionInfoViewController ()
///最外面的容器
@property (nonatomic,strong) UIStackView *stackView;
///用户信息的view
@property (nonatomic,strong) UIView * infoView;
///头像
@property (nonatomic,strong) NetImageView *avatarImageView;
///昵称
@property (nonatomic,strong) UILabel *nickLabel;
///个人主页
@property (nonatomic,strong) UILabel *titleLabel;
///箭头
@property (nonatomic,strong) UIImageView *arrowImageView;
///显示举报 加入黑名单
@property (nonatomic,strong) UIStackView *contentStackView;
///举报
@property (nonatomic,strong) UIButton *reportButton;
///分割线
@property (nonatomic,strong) UIView * lineView;
///加入黑名单
@property (nonatomic,strong) UIButton *blackButton;
@end
@implementation SessionInfoViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initData];
[self initSubViews];
[self initSubViewConstraints];
}
#pragma mark - Private Method
- (void)initData {
[[NIMSDK sharedSDK].userManager fetchUserInfos:@[self.userId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
if (!error) {
NIMUser * user = users.firstObject;
self.avatarImageView.imageUrl = user.userInfo.avatarUrl;
self.nickLabel.text = user.userInfo.nickName;
} else {
[self showErrorToast:@"用户信息请求失败,请重试"];
[self.navigationController popViewControllerAnimated:YES];
}
}];
self.blackButton.selected = [[NIMSDK sharedSDK].userManager isUserInBlackList:self.userId];
}
- (void)initSubViews {
self.title = @"加入黑名单";
[self.view addSubview:self.stackView];
[self.stackView addArrangedSubview:self.infoView];
[self.stackView addArrangedSubview:self.contentStackView];
[self.infoView addSubview:self.avatarImageView];
[self.infoView addSubview:self.nickLabel];
[self.infoView addSubview:self.titleLabel];
[self.infoView addSubview:self.arrowImageView];
[self.contentStackView addArrangedSubview:self.reportButton];
[self.contentStackView addArrangedSubview:self.lineView];
[self.contentStackView addArrangedSubview:self.blackButton];
}
- (void)initSubViewConstraints {
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.view);
make.top.mas_equalTo(self.view).offset(10);
}];
[self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(60);
}];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(40, 40));
make.left.mas_equalTo(self.infoView).offset(15);
make.centerY.mas_equalTo(self.infoView);
}];
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.infoView);
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(5);
make.right.mas_lessThanOrEqualTo(self.titleLabel.mas_left).offset(-5);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.arrowImageView.mas_left).offset(-5);
make.centerY.mas_equalTo(self.infoView);
}];
[self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(6.5, 11));
make.centerY.mas_equalTo(self.infoView);
make.right.mas_equalTo(self.infoView).offset(-10);
}];
[self.reportButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(44);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(0.5);
}];
[self.blackButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(44);
}];
}
#pragma mark - Event Response
- (void)blackButtonAction:(UIButton *)sender {
NSString *title = nil;
NSString *message = nil;
BOOL isInBlack = [[NIMSDK sharedSDK].userManager isUserInBlackList:self.userId];
if (!isInBlack) {
title = @"加入黑名单";
message = @"加入黑名单,你将不再收到对方的消息";
} else {
title = @"移除黑名单";
message = @"移除黑名单,你将正常收到对方的消息";
}
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = title;
config.message = message;
[TTPopup alertWithConfig:config confirmHandler:^{
if (isInBlack) {
[[NIMSDK sharedSDK].userManager removeFromBlackBlackList:self.userId completion:^(NSError * _Nullable error) {
if (error == nil) {
[self showErrorToast:@"已经成功将对方移除黑名单"];
self.blackButton.selected = NO;
} else {
[self showErrorToast:error.description];
}
}];
} else {
[[NIMSDK sharedSDK].userManager addToBlackList:self.userId completion:^(NSError * _Nullable error) {
if (error == nil) {
[self showErrorToast:@"已经成功将对方加入黑名单"];
self.blackButton.selected = YES;
} else {
[self showErrorToast:error.description];
}
}];
}
} cancelHandler:^{
}];
}
- (void)reportButtonAction:(UIButton *)sender {
XPWebViewController *webVC = [[XPWebViewController alloc] init];
NSString *urlstr = [NSString stringWithFormat:@"%@?reportUid=%@&source=CHAT",URLWithType(kReportRoomURL),self.userId];
webVC.url = urlstr;
[self.navigationController pushViewController:webVC animated:YES];
}
- (void)didTapUserRecognizer {
XPMineUserInfoViewController * mineVC = [[XPMineUserInfoViewController alloc] init];
mineVC.uid = self.userId.integerValue;
[self.navigationController pushViewController:mineVC animated:YES];
}
#pragma mark - Getters And Setters
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisVertical;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 20;
}
return _stackView;
}
- (UIView *)infoView {
if (!_infoView) {
_infoView = [[UIView alloc] init];
_infoView.backgroundColor = [ThemeColor appCellBackgroundColor];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapUserRecognizer)];
[_infoView addGestureRecognizer:tap];
}
return _infoView;
}
- (NetImageView *)avatarImageView {
if (!_avatarImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
_avatarImageView.layer.masksToBounds = YES;
_avatarImageView.layer.cornerRadius = 20;
}
return _avatarImageView;
}
- (UILabel *)nickLabel {
if (!_nickLabel) {
_nickLabel = [[UILabel alloc] init];
_nickLabel.font = [UIFont systemFontOfSize:15];
_nickLabel.textColor = [ThemeColor mainTextColor];
}
return _nickLabel;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:14];
_titleLabel.text = @"个人主页";
_titleLabel.textColor = [ThemeColor secondTextColor];
}
return _titleLabel;
}
- (UIImageView *)arrowImageView {
if (!_arrowImageView) {
_arrowImageView = [[UIImageView alloc] init];
_arrowImageView.userInteractionEnabled = YES;
_arrowImageView.image = [UIImage imageNamed:@"room_setting_arrow"];
}
return _arrowImageView;
}
- (UIStackView *)contentStackView {
if (!_contentStackView) {
_contentStackView = [[UIStackView alloc] init];
_contentStackView.axis = UILayoutConstraintAxisVertical;
_contentStackView.distribution = UIStackViewDistributionFill;
_contentStackView.alignment = UIStackViewAlignmentFill;
_contentStackView.spacing = 0;
}
return _contentStackView;
}
- (UIButton *)reportButton {
if (!_reportButton) {
_reportButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_reportButton setTitle:@"举报" forState:UIControlStateNormal];
[_reportButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateNormal];
_reportButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
[_reportButton setBackgroundColor:[ThemeColor appCellBackgroundColor]];
[_reportButton addTarget:self action:@selector(reportButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _reportButton;
}
- (UIView *)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [ThemeColor dividerColor];
}
return _lineView;
}
- (UIButton *)blackButton {
if (!_blackButton) {
_blackButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_blackButton setTitle:@"加入黑名单" forState:UIControlStateNormal];
[_blackButton setTitle:@"移除黑名单" forState:UIControlStateSelected];
[_blackButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateNormal];
[_blackButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateSelected];
_blackButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
[_blackButton setBackgroundColor:[ThemeColor appCellBackgroundColor]];
[_blackButton addTarget:self action:@selector(blackButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _blackButton;
}
@end