Files
yinmeng-ios/xplan-ios/Main/Mine/View/MineInfo/XPMineUserInfoViewController.m

347 lines
12 KiB
Mathematica
Raw Normal View History

2021-09-23 18:38:33 +08:00
//
// MineInfoViewController.m
// xplan-ios
//
// Created by on 2021/9/22.
//
#import "XPMineUserInfoViewController.h"
///Third
#import <NIMSDK/NIMSDK.h>
2021-09-23 18:38:33 +08:00
#import <Masonry/Masonry.h>
#import <SDCycleScrollView/SDCycleScrollView.h>
2021-09-23 18:38:33 +08:00
///Tool
#import "ThemeColor.h"
#import "XPMacro.h"
#import "AccountInfoStorage.h"
#import "TTPopup.h"
#import "XPHtmlUrl.h"
#import "UIImage+Utils.h"
2021-09-23 18:38:33 +08:00
///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"
2021-09-23 18:38:33 +08:00
@interface XPMineUserInfoViewController ()<UITableViewDelegate, UITableViewDataSource, XPMineCustomNavViewDelegate, XPMineUserInfoProtocol, UIGestureRecognizerDelegate, XPMineUserInfoHeaderViewDelegate>
2021-09-23 18:38:33 +08:00
///
@property (nonatomic,strong) UITableView *tableView;
2021-09-23 18:38:33 +08:00
///
@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;
2021-09-23 18:38:33 +08:00
@end
@implementation XPMineUserInfoViewController
- (XPMineUserInfoPresenter *)createPresenter {
return [[XPMineUserInfoPresenter alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
[self initHttpRequest];
2021-09-23 18:38:33 +08:00
}
2021-09-24 17:46:52 +08:00
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (self.uid > 0) {
NSString * uidStr = [NSString stringWithFormat:@"%ld", self.uid];
2021-09-24 17:46:52 +08:00
[self.presenter getUserInfoWithUid:uidStr];
}
}
#pragma mark - Public Method
- (UIView *)getHeadHitView {
return self.headView.cycleScrollView;
}
2021-09-23 18:38:33 +08:00
#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);
}];
}
2021-09-23 18:38:33 +08:00
}
- (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];
2021-09-23 18:38:33 +08:00
}
#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:^{
}];
}
2021-09-23 18:38:33 +08:00
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 0;
2021-09-23 18:38:33 +08:00
}
- (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];
}
2021-09-23 18:38:33 +08:00
}
- (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];
}
2021-09-23 18:38:33 +08:00
#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];
}
2021-09-23 18:38:33 +08:00
#pragma mark - Getters And Setters
- (void)setUid:(NSInteger)uid {
2021-09-23 18:38:33 +08:00
_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];
2021-09-23 18:38:33 +08:00
[self.presenter getUserInfoWithUid:uidStr];
}
}
- (UITableView *)tableView {
2021-09-23 18:38:33 +08:00
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
2021-09-23 18:38:33 +08:00
_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;
2021-09-23 18:38:33 +08:00
}
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;
}
2021-09-23 18:38:33 +08:00
@end