// // YMMineSimpleUserInfoViewController.m // YUMI // // Created by XY on 2023/2/21. // #import "XPMineSimpleUserInfoViewController.h" #import "YUMIMacroUitls.h" #import #import #import "DJDKMIMOMColor.h" #import "UIImage+Utils.h" #import "AccountInfoStorage.h" #import "TTPopup.h" #import "YUMIHtmlUrl.h" #import "XPSkillCardPlayerManager.h" #import "UIImage+Utils.h" #import "YUMIConstant.h" #import "NIMMessageUtils.h" #import "NSArray+Safe.h" #import "ClientConfig.h" #import "XNDJTDDLoadingTool.h" #import "MonentsListInfoModel.h" #import "MineSkillCardListInfoModel.h" #import "UserInfoModel.h" ///P #import "XPMineUserInfoPresenter.h" #import "XPMineUserInfoProtocol.h" #import "RoomHostDelegate.h" ///View #import "XPMomentListCollectionViewCell.h" #import "XPMineUserInfoCustomNavView.h" #import "XPMineSimpleUserInfoHeaderView.h" ///VC #import "XPMineUserInfoEditViewController.h" #import "XPWebViewController.h" #import "SessionViewController.h" #import "XPRoomViewController.h" #import "XPMineUserDataViewController.h" #import "XPMonentsMineViewController.h" #import "XPMonentsDetailViewController.h" #import "XPMomentsSimpleDetailViewController.h" #import "XPMineUserInfoGiftWallViewController.h" #define kHeaderViewHeight 615 @interface XPMineSimpleUserInfoViewController () @property (nonatomic, strong) UICollectionView *collectionView; ///头部视图 @property (nonatomic, strong) XPMineSimpleUserInfoHeaderView *headerView; ///自定义的导航栏 @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 XPMineSimpleUserInfoViewController - (XPMineUserInfoPresenter *)createPresenter { return [[XPMineUserInfoPresenter alloc] init]; } - (BOOL)isHiddenNavBar { return YES; } - (void)viewDidLoad { [super viewDidLoad]; [self createUI]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (self.uid > 0) { [self initHttpRequest]; } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } - (void)createUI { [self.view addSubview:self.collectionView]; [self.collectionView addSubview:self.headerView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.leading.trailing.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; [self.view addSubview:self.navView]; [self.navView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.top.mas_equalTo(self.view); make.height.mas_equalTo(kNavigationHeight); }]; if (self.uid != [AccountInfoStorage instance].getUid.integerValue) { [self.view addSubview:self.chatButton]; [self.chatButton mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.view); make.height.mas_equalTo(36); make.width.mas_equalTo(100); make.bottom.mas_equalTo(self.view).offset(-kSafeAreaBottomHeight - 15); }]; } } - (void)initHttpRequest { NSString *uid = [NSString stringWithFormat:@"%ld", self.uid]; ///请求目标用户的个人信息 // [self.presenter getUserInfoWithUid:uid]; [self.presenter getUserAttentionState:uid]; //获取用户详细信息 跟随进房目前使用的这个接口 [self.presenter getUserDetailInfoWithUid:uid]; NSString * myUid = [AccountInfoStorage instance].getUid; ///上传访问记录 if (![uid isEqualToString:myUid]) { ///请求我自己的个人信息 // [self.presenter getUserInfoWithUid:myUid]; } } #pragma mark - 拉黑 移除黑名单 - (void)showRightNavHandle { NSMutableArray *array = [NSMutableArray array]; NSString *uid = [NSString stringWithFormat:@"%ld",self.uid]; TTActionSheetConfig *report = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMineSimpleUserInfoViewController0") clickAction:^{ if ([ClientConfig shareConfig].canOpen) { XPWebViewController *vc = [[XPWebViewController alloc]init]; NSString *urlstr = [NSString stringWithFormat:@"%@?reportUid=%@&source=PERSONAL",URLWithType(kReportRoomURL),uid]; vc.url = urlstr; [self.navigationController pushViewController:vc animated:YES]; } else { [XNDJTDDLoadingTool showErrorWithMessage:YMLocalizedString(@"XPMineSimpleUserInfoViewController1")]; } }]; TTActionSheetConfig *black = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMineSimpleUserInfoViewController2") clickAction:^{ [self addOrRemoveBlack:NO uid:uid]; }]; [array addObjectsFromArray:@[report, black]]; BOOL isInBlackList = [[NIMSDK sharedSDK].userManager isUserInBlackList:uid] || [NIMMessageUtils isOfficalAccount:[NSString stringWithFormat:@"%ld", self.uid]]; if (isInBlackList) { [array removeObject:black]; } [TTPopup actionSheetWithItems:array]; } //加入黑名单 - (void)addOrRemoveBlack:(BOOL)isRemove uid:(NSString *)uid { NSString *title; NSString *message; if (isRemove) { title = YMLocalizedString(@"XPMineSimpleUserInfoViewController3"); message = YMLocalizedString(@"XPMineSimpleUserInfoViewController4"); }else{ title = YMLocalizedString(@"XPMineSimpleUserInfoViewController5"); message = YMLocalizedString(@"XPMineSimpleUserInfoViewController6"); } 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:YMLocalizedString(@"XPMineSimpleUserInfoViewController7")]; } }]; } else { [[NIMSDK sharedSDK].userManager addToBlackList:uid completion:^(NSError * _Nullable error) { if (error == nil) { [self showSuccessToast:YMLocalizedString(@"XPMineSimpleUserInfoViewController8")]; } }]; } } cancelHandler:^{ }]; } #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 - XPMineSimpleUserInfoHeaderViewDelegate /// 更多了礼物 - (void)headerViewMoreGiftAction { if (self.uid > 0) { XPMineUserInfoGiftWallViewController * giftWallVC = [[XPMineUserInfoGiftWallViewController alloc] init]; giftWallVC.userUid = [NSString stringWithFormat:@"%ld", self.uid]; [self.navigationController pushViewController:giftWallVC animated:YES]; } } /// 点击了直播中 - (void)headerViewOnlineAction:(NSString *)roomUid { if (roomUid.length > 0 ) { //退出原来的房间 如果有的话 TODO 总感觉这种处理不太优雅 进房入口多了 怎么办 进房需要整合 [self.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[XPRoomViewController class]]) { [self.navigationController popToRootViewControllerAnimated:NO]; XPRoomViewController * rooomVC = obj; [rooomVC exitRoom]; *stop = YES; } }]; [XPRoomViewController openRoom:roomUid viewController:self]; } } #pragma mark - XPMineUserInfoProtocol - (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo { if (userInfo.uid == self.uid) { self.userInfo = userInfo; // self.headView.userInfo = userInfo; } else { if (!userInfo.userVipInfoVO.lookHomepageHide) { NSString * uid = [NSString stringWithFormat:@"%ld", self.uid]; [self.presenter visitUser:uid]; } } } - (void)ongetDetailInfoSuccess:(UserInfoModel *)userInfo { self.userInfo = userInfo; self.headerView.userInfo = userInfo; self.headerView.roomUid = userInfo.roomUid; [self.collectionView reloadData]; // self.userDataVC.userInfo = userInfo; // self.monentsVC.dynamicInfo = userInfo.dynamicInfo; } - (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 - UICollectionView - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.userInfo.dynamicInfo.count; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { XPMomentListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(XPMomentListCollectionViewCell.self) forIndexPath:indexPath]; MonentsInfoModel * monentsInfo = [self.userInfo.dynamicInfo safeObjectAtIndex1:indexPath.row]; cell.monentsInfo = monentsInfo; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (self.userInfo.dynamicInfo.count > 0) { if ([ClientConfig shareConfig].canOpen) { XPMonentsDetailViewController * detailVC = [[XPMonentsDetailViewController alloc] init]; MonentsInfoModel * monentsInfo = [self.userInfo.dynamicInfo safeObjectAtIndex1:indexPath.row]; detailVC.monentsInfo = monentsInfo; [self.navigationController pushViewController:detailVC animated:YES]; }else{ XPMomentsSimpleDetailViewController * detailVC = [[XPMomentsSimpleDetailViewController alloc] init]; MonentsInfoModel * monentsInfo = [self.userInfo.dynamicInfo safeObjectAtIndex1:indexPath.row]; detailVC.monentsInfo = monentsInfo; [self.navigationController pushViewController:detailVC animated:YES]; } } } #pragma mark - 懒加载 - (UICollectionView *)collectionView { if (!_collectionView) { MSBaseRTLFlowLayout *layout = [[MSBaseRTLFlowLayout alloc] init]; layout.scrollDirection = UICollectionViewScrollDirectionVertical; CGFloat width = (KScreenWidth - 16 -13 -16)/2.0; CGFloat height = 220.0/165.0*width; layout.itemSize = CGSizeMake(width, height); layout.minimumLineSpacing = 12.0; layout.minimumInteritemSpacing = 13.0; layout.sectionInset = UIEdgeInsetsMake(12, 16, 12, 16); _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _collectionView.backgroundColor = UIColor.whiteColor; _collectionView.alwaysBounceVertical = YES; [_collectionView registerClass:[XPMomentListCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass(XPMomentListCollectionViewCell.self)]; _collectionView.delegate = self; _collectionView.dataSource = self; _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; _collectionView.contentInset = UIEdgeInsetsMake(kHeaderViewHeight, 0, 0, 0); } return _collectionView; } - (XPMineSimpleUserInfoHeaderView *)headerView { if (!_headerView) { _headerView = [[XPMineSimpleUserInfoHeaderView alloc] init]; _headerView.frame = CGRectMake(0, -kHeaderViewHeight, KScreenWidth, kHeaderViewHeight); _headerView.delegate = self; } return _headerView; } - (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:YMLocalizedString(@"XPMineSimpleUserInfoViewController9") forState:UIControlStateNormal]; [_chatButton setTitleColor:[DJDKMIMOMColor confirmButtonTextColor] forState:UIControlStateNormal]; _chatButton.titleLabel.font = [UIFont systemFontOfSize:15]; [_chatButton setBackgroundColor:[DJDKMIMOMColor appMainColor]]; _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:YMLocalizedString(@"XPMineSimpleUserInfoViewController10") forState:UIControlStateNormal]; [_attentionButton setTitle:YMLocalizedString(@"XPMineSimpleUserInfoViewController11") forState:UIControlStateSelected]; [_attentionButton setTitleColor:[DJDKMIMOMColor confirmButtonTextColor] forState:UIControlStateNormal]; [_attentionButton setTitleColor:[DJDKMIMOMColor 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:@[[DJDKMIMOMColor confirmButtonGradientStartColor], [DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal]; [_attentionButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor cancelButtonGradientStartColor], [DJDKMIMOMColor cancelButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateSelected]; _attentionButton.layer.masksToBounds = YES; _attentionButton.layer.cornerRadius = 36/2; _attentionButton.hidden = YES; [_attentionButton addTarget:self action:@selector(attentionButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _attentionButton; } @end