347 lines
12 KiB
Objective-C
347 lines
12 KiB
Objective-C
//
|
|
// MineInfoViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/9/22.
|
|
//
|
|
|
|
#import "XPMineUserInfoViewController.h"
|
|
///Third
|
|
#import <NIMSDK/NIMSDK.h>
|
|
#import <Masonry/Masonry.h>
|
|
#import <SDCycleScrollView/SDCycleScrollView.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "XPMacro.h"
|
|
#import "AccountInfoStorage.h"
|
|
#import "TTPopup.h"
|
|
#import "XPHtmlUrl.h"
|
|
#import "UIImage+Utils.h"
|
|
///View
|
|
#import "XPMineUserInfoTableViewCell.h"
|
|
#import "XPMineUserInfoHeaderView.h"
|
|
#import "XPMineUserInfoCustomNavView.h"
|
|
///P
|
|
#import "XPMineUserInfoPresenter.h"
|
|
#import "XPMineUserInfoProtocol.h"
|
|
///VC
|
|
#import "XPMineUserInfoEditViewController.h"
|
|
#import "XPWebViewController.h"
|
|
#import "SessionViewController.h"
|
|
#import "XPRoomViewController.h"
|
|
|
|
@interface XPMineUserInfoViewController ()<UITableViewDelegate, UITableViewDataSource, XPMineCustomNavViewDelegate, XPMineUserInfoProtocol, UIGestureRecognizerDelegate, XPMineUserInfoHeaderViewDelegate>
|
|
///列别
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
///头部视图
|
|
@property (nonatomic,strong) XPMineUserInfoHeaderView *headView;
|
|
///自定义的导航栏
|
|
@property (nonatomic,strong) XPMineUserInfoCustomNavView *navView;
|
|
///用户信息
|
|
@property (nonatomic,strong) UserInfoModel *userInfo;
|
|
///底部的容器
|
|
@property (nonatomic,strong) UIStackView *bottomStackView;
|
|
///私聊
|
|
@property (nonatomic,strong) UIButton *chatButton;
|
|
///关注
|
|
@property (nonatomic,strong) UIButton *attentionButton;
|
|
@end
|
|
|
|
@implementation XPMineUserInfoViewController
|
|
|
|
- (XPMineUserInfoPresenter *)createPresenter {
|
|
return [[XPMineUserInfoPresenter alloc] init];
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
[self initHttpRequest];
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
if (self.uid > 0) {
|
|
NSString * uidStr = [NSString stringWithFormat:@"%ld", self.uid];
|
|
[self.presenter getUserInfoWithUid:uidStr];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Public Method
|
|
- (UIView *)getHeadHitView {
|
|
return self.headView.cycleScrollView;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.view addSubview:self.tableView];
|
|
[self.view addSubview:self.navView];
|
|
|
|
self.tableView.tableHeaderView = self.headView;
|
|
if (self.uid != [AccountInfoStorage instance].getUid.integerValue) {
|
|
[self.view addSubview:self.bottomStackView];
|
|
[self.bottomStackView addArrangedSubview:self.chatButton];
|
|
[self.bottomStackView addArrangedSubview:self.attentionButton];
|
|
|
|
[self.bottomStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.view).inset(25);
|
|
make.height.mas_equalTo(36);
|
|
make.bottom.mas_equalTo(self.view).offset(-kSafeAreaBottomHeight - 15);
|
|
}];
|
|
}
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.view);
|
|
}];
|
|
|
|
[self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(kNavigationHeight);
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
- (void)initHttpRequest {
|
|
NSString *uid = [NSString stringWithFormat:@"%ld", self.uid];
|
|
[self.presenter getUserAttentionState:uid];
|
|
|
|
//获取用户详细信息 跟随进房目前使用的这个接口
|
|
[self.presenter getUserDetailInfoWithUid:uid];
|
|
}
|
|
|
|
#pragma mark - 拉黑 移除黑名单
|
|
- (void)showRightNavHandle {
|
|
NSMutableArray<TTActionSheetConfig *> *array = [NSMutableArray array];
|
|
NSString *uid = [NSString stringWithFormat:@"%ld",self.uid];
|
|
TTActionSheetConfig *report = [TTActionSheetConfig normalTitle:@"举报" clickAction:^{
|
|
XPWebViewController *vc = [[XPWebViewController alloc]init];
|
|
NSString *urlstr = [NSString stringWithFormat:@"%@?reportUid=%@&source=PERSONAL",URLWithType(kReportRoomURL),uid];
|
|
vc.url = urlstr;
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}];
|
|
TTActionSheetConfig *removeBlack = [TTActionSheetConfig normalTitle:@"移除黑名单" clickAction:^{
|
|
[self addOrRemoveBlack:YES uid:uid];
|
|
}];
|
|
TTActionSheetConfig *black = [TTActionSheetConfig normalTitle:@"拉黑" clickAction:^{
|
|
[self addOrRemoveBlack:NO uid:uid];
|
|
}];
|
|
|
|
[array addObjectsFromArray:@[report, black]];
|
|
|
|
BOOL isInBlackList = [[NIMSDK sharedSDK].userManager isUserInBlackList:uid];
|
|
if (isInBlackList) {
|
|
[array addObject:removeBlack];
|
|
}
|
|
[TTPopup actionSheetWithItems:array];
|
|
}
|
|
|
|
|
|
//加入黑名单
|
|
- (void)addOrRemoveBlack:(BOOL)isRemove uid:(NSString *)uid {
|
|
NSString *title;
|
|
NSString *message;
|
|
if (isRemove) {
|
|
title = @"移除黑名单";
|
|
message = @"移除黑名单,你将正常收到对方的消息";
|
|
}else{
|
|
title = @"加入黑名单";
|
|
message = @"加入黑名单,你将不再收到对方的消息";
|
|
}
|
|
|
|
TTAlertConfig *config = [[TTAlertConfig alloc] init];
|
|
config.title = title;
|
|
config.message = message;
|
|
|
|
[TTPopup alertWithConfig:config confirmHandler:^{
|
|
if (isRemove) {
|
|
[[NIMSDK sharedSDK].userManager removeFromBlackBlackList:uid completion:^(NSError * _Nullable error) {
|
|
if (error == nil) {
|
|
[self showSuccessToast:@"移出黑名单成功"];
|
|
}
|
|
}];
|
|
} else {
|
|
[[NIMSDK sharedSDK].userManager addToBlackList:uid completion:^(NSError * _Nullable error) {
|
|
if (error == nil) {
|
|
[self showSuccessToast:@"加入黑名单成功"];
|
|
}
|
|
}];
|
|
}
|
|
} cancelHandler:^{
|
|
}];
|
|
}
|
|
|
|
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return 0;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
return 100;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
XPMineUserInfoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineUserInfoTableViewCell class])];
|
|
if (cell == nil) {
|
|
cell = [[XPMineUserInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineUserInfoTableViewCell class])];
|
|
}
|
|
cell.userInfo = self.userInfo;
|
|
return cell;
|
|
}
|
|
|
|
#pragma mark - XPMineCustomNavViewDelegate
|
|
- (void)xPMineCustomNavView:(XPMineUserInfoCustomNavView *)view didClickEditButton:(UIButton *)sender {
|
|
if (sender.isSelected) {///自己看自己的 去修改资料
|
|
XPMineUserInfoEditViewController * editVC = [[XPMineUserInfoEditViewController alloc] init];
|
|
[self.navigationController pushViewController:editVC animated:YES];
|
|
} else {
|
|
[self showRightNavHandle];
|
|
}
|
|
}
|
|
|
|
- (void)xPMineCustomNavView:(XPMineUserInfoCustomNavView *)view didClickBackButton:(UIButton *)sender {
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
|
|
#pragma mark - XPMineUserInfoHeaderViewDelegate
|
|
- (void)xPMineUserInfoHeaderView:(XPMineUserInfoHeaderView *)view didClickGoToRoom:(NSString *)roomUid {
|
|
[XPRoomViewController openRoom:roomUid viewController:self];
|
|
}
|
|
|
|
#pragma mark - XPMineUserInfoProtocol
|
|
- (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo {
|
|
self.userInfo = userInfo;
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
- (void)ongetDetailInfoSuccess:(UserInfoModel *)userInfo {
|
|
self.headView.userInfo = userInfo;
|
|
}
|
|
|
|
- (void)getAttentionStateSuccess:(BOOL)status {
|
|
self.attentionButton.selected = status;
|
|
}
|
|
|
|
- (void)attentionUserSuccess:(BOOL)status {
|
|
self.attentionButton.selected = status;
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)chatButtonAction:(UIButton *)sender {
|
|
NSString * sessionId = [NSString stringWithFormat:@"%ld",self.uid];
|
|
NIMSession * session = [NIMSession session:sessionId type:NIMSessionTypeP2P];
|
|
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
|
|
[self.navigationController pushViewController:sessionVC animated:YES];
|
|
}
|
|
|
|
- (void)attentionButtonAction:(UIButton *)sender {
|
|
NSString *uid = [NSString stringWithFormat:@"%ld", self.uid];
|
|
[self.presenter attentionUser:uid state:!sender.selected];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setUid:(NSInteger)uid {
|
|
_uid = uid;
|
|
if (_uid > 0) {
|
|
if (_uid == [AccountInfoStorage instance].getUid.integerValue) {
|
|
[self.navView.editButton setTitle:@"编辑" forState:UIControlStateNormal];
|
|
[self.navView.editButton setImage:[UIImage new] forState:UIControlStateNormal];
|
|
} else {
|
|
[self.navView.editButton setTitle:@"" forState:UIControlStateNormal];
|
|
[self.navView.editButton setImage:[UIImage imageNamed:@"mine_user_info_edit"] forState:UIControlStateNormal];
|
|
}
|
|
self.navView.editButton.selected = _uid == [AccountInfoStorage instance].getUid.integerValue;
|
|
NSString * uidStr = [NSString stringWithFormat:@"%ld", uid];
|
|
[self.presenter getUserInfoWithUid:uidStr];
|
|
}
|
|
}
|
|
|
|
- (UITableView *)tableView {
|
|
if (!_tableView) {
|
|
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
|
|
_tableView.delegate = self;
|
|
_tableView.dataSource = self;
|
|
_tableView.tableFooterView = [UIView new];
|
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
|
if (@available(iOS 11.0, *)) {
|
|
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
}
|
|
[_tableView registerClass:[XPMineUserInfoTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineUserInfoTableViewCell class])];
|
|
}
|
|
return _tableView;
|
|
}
|
|
|
|
- (XPMineUserInfoHeaderView *)headView {
|
|
if (!_headView) {
|
|
_headView = [[XPMineUserInfoHeaderView alloc] init];
|
|
_headView.frame = CGRectMake(0, 0, KScreenWidth, 270 + kSafeAreaTopHeight);
|
|
_headView.delegate = self;
|
|
}
|
|
return _headView;
|
|
}
|
|
|
|
- (XPMineUserInfoCustomNavView *)navView {
|
|
if (!_navView) {
|
|
_navView = [[XPMineUserInfoCustomNavView alloc] init];
|
|
_navView.delegate = self;
|
|
}
|
|
return _navView;
|
|
}
|
|
|
|
- (UIStackView *)bottomStackView {
|
|
if (!_bottomStackView) {
|
|
_bottomStackView = [[UIStackView alloc] init];
|
|
_bottomStackView.axis = UILayoutConstraintAxisHorizontal;
|
|
_bottomStackView.distribution = UIStackViewDistributionFillEqually;
|
|
_bottomStackView.alignment = UIStackViewAlignmentFill;
|
|
_bottomStackView.spacing = 25;
|
|
}
|
|
return _bottomStackView;
|
|
}
|
|
|
|
- (UIButton *)chatButton {
|
|
if (!_chatButton) {
|
|
_chatButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_chatButton setTitle:@"私信" forState:UIControlStateNormal];
|
|
[_chatButton setTitleColor:[ThemeColor cancelButtonTextColor] forState:UIControlStateNormal];
|
|
[_chatButton setImage:[UIImage imageNamed:@"mine_user_info_bottom_chat"] forState:UIControlStateNormal];
|
|
_chatButton.titleLabel.font = [UIFont systemFontOfSize:15];
|
|
[_chatButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor cancelButtonGradientStartColor], [ThemeColor cancelButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
|
|
_chatButton.layer.masksToBounds = YES;
|
|
_chatButton.layer.cornerRadius = 36/2;
|
|
[_chatButton addTarget:self action:@selector(chatButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _chatButton;
|
|
}
|
|
|
|
- (UIButton *)attentionButton {
|
|
if (!_attentionButton) {
|
|
_attentionButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_attentionButton setTitle:@"关注" forState:UIControlStateNormal];
|
|
[_attentionButton setTitle:@"已关注" forState:UIControlStateSelected];
|
|
[_attentionButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateNormal];
|
|
[_attentionButton setTitleColor:[ThemeColor cancelButtonTextColor] forState:UIControlStateSelected];
|
|
[_attentionButton setImage:[UIImage imageNamed:@"mine_user_info_bottom_attention_normal"] forState:UIControlStateNormal];
|
|
[_attentionButton setImage:[UIImage imageNamed:@"mine_user_info_bottom_attention_select"] forState:UIControlStateSelected];
|
|
_attentionButton.titleLabel.font = [UIFont systemFontOfSize:15];
|
|
[_attentionButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor], [ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
|
|
[_attentionButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor cancelButtonGradientStartColor], [ThemeColor cancelButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateSelected];
|
|
_attentionButton.layer.masksToBounds = YES;
|
|
_attentionButton.layer.cornerRadius = 36/2;
|
|
[_attentionButton addTarget:self action:@selector(attentionButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _attentionButton;
|
|
}
|
|
|
|
|
|
@end
|