// // MineInfoViewController.m // xplan-ios // // Created by 冯硕 on 2021/9/22. // #import "XPMineUserInfoViewController.h" ///Third #import #import #import #import #import #import #import #import ///Tool #import "AccountInfoStorage.h" #import "TTPopup.h" #import "XPSkillCardPlayerManager.h" #import "UIImage+Utils.h" ///Model #import "MineSkillCardListInfoModel.h" #import "UserInfoModel.h" #import "XPSoundCardModel.h" #import "XPMineUserInfoTagModel.h" #import "UploadFile.h" ///View #import "XPMineUserInfoHeaderView.h" #import "XPMineUserInfoCustomNavView.h" #import "XPMineUserInfoIndividualTagView.h" #import "XPMineGameMateOrderView.h" ///P #import "XPMineUserInfoPresenter.h" #import "XPMineUserInfoProtocol.h" #import "RoomHostDelegate.h" ///VC #import "XPMineUserInfoEditViewController.h" #import "XPWebViewController.h" #import "SessionViewController.h" #import "XPRoomViewController.h" #import "XPMineUserDataViewController.h" #import "XPMomentsMineViewController.h" #import "XPGiftUserDataViewController.h" #import "XPRoomMiniManager.h" #import "XPMineUserInfoTagVC.h" #import "XPMomentUserDataViewController.h" UIKIT_EXTERN NSString * kUpdateSoundInfo; @interface XPMineUserInfoViewController ()< XPMineCustomNavViewDelegate, XPMineUserInfoProtocol, XPMineUserInfoHeaderViewDelegate, JXCategoryViewDelegate,JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,XPMineUserInfoEditViewControllerDelegate,XPMineUserInfoTagVCDelegate,XPMineUserInfoIndividualTagViewDelegate, XPMineUserDataViewControllerDelegate> @property (nonatomic, strong) JXCategoryTitleView *titleView; @property (nonatomic, strong) JXCategoryIndicatorImageView *lineView; @property (nonatomic, strong) JXPagerView *pagingView; @property (nonatomic, strong) NSArray *titles; ///头部视图 @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; ///资料 @property (nonatomic,strong) XPMineUserDataViewController *userDataVC; ///禮物牆 @property (nonatomic,strong) XPGiftUserDataViewController *giftVC; ///编辑资料 @property (nonatomic,strong) XPMineUserInfoEditViewController * editVC; ///标签 @property (nonatomic,strong) XPMineUserInfoTagModel *tagModel; @property (nonatomic, strong) XPMomentUserDataViewController *userMomentVC; @property (nonatomic, strong) XPMineGameMateOrderView *gameOrderView; @property (nonatomic, assign) CGFloat headerHeight; @end @implementation XPMineUserInfoViewController - (void)dealloc { [[NSNotificationCenter defaultCenter]removeObserver:self]; } - (XPMineUserInfoPresenter *)createPresenter { return [[XPMineUserInfoPresenter alloc] init]; } - (BOOL)isHiddenNavBar { return YES; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; [self initHttpRequest]; } -(void)viewDidDisappear:(BOOL)animated{ [super viewDidAppear:animated]; [[XPSkillCardPlayerManager shareInstance] stopMusic]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.presenter getUserInfoWithUid:@(self.uid).stringValue]; if([XPSkillCardPlayerManager shareInstance].isInRoom == YES && [XPSkillCardPlayerManager shareInstance].isInRoomFirstRecharge == NO){ [XPSkillCardPlayerManager shareInstance].isInRoomFirstRecharge = YES; } } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; [self initSubViews]; [self initSubViewConstraints]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; if (self.uid == [AccountInfoStorage instance].getUid.integerValue) { self.pagingView.frame = self.view.bounds; } else { self.pagingView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 45 - kSafeAreaBottomHeight - 15); } } #pragma mark - Private Method - (void)initSubViews { [self.view addSubview:self.pagingView]; [self.view addSubview:self.navView]; if (self.uid != [AccountInfoStorage instance].getUid.integerValue) { [self.view addSubview:self.bottomStackView]; [self.bottomStackView addArrangedSubview:self.attentionButton]; [self.bottomStackView addArrangedSubview:self.chatButton]; [self.bottomStackView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.mas_equalTo(self.view).inset(15); make.height.mas_equalTo(45); make.bottom.mas_equalTo(self.view).offset(-kSafeAreaBottomHeight - 15); }]; } } - (void)initSubViewConstraints { [self.navView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.top.mas_equalTo(self.view); make.height.mas_equalTo(kNavigationHeight); }]; } - (void)initHttpRequest { NSString *uid = [NSString stringWithFormat:@"%ld", self.uid]; // [self.presenter getUserInfoWithUid:uid]; [self.presenter getUserAttentionState:uid]; ///上传访问记录 if (![uid isEqualToString:[[AccountInfoStorage instance] getUid]]) { [self.presenter visitUser:uid]; } } #pragma mark - 拉黑 移除黑名单 - (BOOL)isSystemAccount { return [KeyWithType(KeyType_SecretaryUidKey) isEqualToString:[NSString stringWithFormat:@"%ld", self.uid]] || [KeyWithType(KeyType_SystemNotifiUidKey) isEqualToString:[NSString stringWithFormat:@"%ld", self.uid]] || [KeyWithType(KeyType_GuildUidKey) isEqualToString:[NSString stringWithFormat:@"%ld", self.uid]]; } - (void)showRightNavHandle { NSMutableArray *array = [NSMutableArray array]; NSString *uid = [NSString stringWithFormat:@"%ld",self.uid]; TTActionSheetConfig *report = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMineUserInfoViewController0") 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 *black = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMineUserInfoViewController1") clickAction:^{ [self addOrRemoveBlack:NO uid:uid]; }]; [array addObjectsFromArray:@[report, black]]; BOOL isInBlackList = [[NIMSDK sharedSDK].userManager isUserInBlackList:uid] || [self isSystemAccount]; if (isInBlackList) { [array removeObject:black]; } [TTPopup actionSheetWithItems:array]; } //加入黑名单 - (void)addOrRemoveBlack:(BOOL)isRemove uid:(NSString *)uid { NSString *title; NSString *message; if (isRemove) { title = YMLocalizedString(@"XPMineUserInfoViewController2"); message = YMLocalizedString(@"XPMineUserInfoViewController3"); }else{ title = YMLocalizedString(@"XPMineUserInfoViewController4"); message = YMLocalizedString(@"XPMineUserInfoViewController5"); } TTAlertConfig *config = [[TTAlertConfig alloc] init]; config.title = title; config.message = message; @kWeakify(self); [TTPopup alertWithConfig:config confirmHandler:^{ @kStrongify(self); if (isRemove) { [[NIMSDK sharedSDK].userManager removeFromBlackBlackList:uid completion:^(NSError * _Nullable error) { if (error == nil) { [self showSuccessToast:YMLocalizedString(@"XPMineUserInfoViewController6")]; } }]; } else { [[NIMSDK sharedSDK].userManager addToBlackList:uid completion:^(NSError * _Nullable error) { if (error == nil) { [self showSuccessToast:YMLocalizedString(@"XPMineUserInfoViewController7")]; } }]; } } cancelHandler:^{ }]; } #pragma mark - XPMineUserDataViewControllerDelegate - (void)showGameOrderView:(XPMineGamePartnerInfoModel *)model { XPMineGameMateOrderView *view = [[XPMineGameMateOrderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)]; [self.view addSubview:view]; view.infoModel = model; @kWeakify(self); view.payForGame = ^(NSInteger round) { @kStrongify(self); [self.userDataVC submitGameOrder:model round:round]; }; self.gameOrderView = view; } - (void)dismissGameOrderView { [self.gameOrderView removeFromSuperview]; } #pragma mark - JXCategoryViewDelegate - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView { return self.headerHeight; } - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView { return self.headView; } - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return 50; } - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return self.titleView; } - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView { return self.titles.count; } - (id)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index { if (index == 0) { return isMSRTL() ? self.userMomentVC : self.userDataVC; } else { return isMSRTL() ? self.userDataVC : self.userMomentVC; } } #pragma mark - JXPagerMainTableViewGestureDelegate - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { ///1000是外部的scrollView 1001是人气主播中的collectionView if (otherGestureRecognizer.view.tag == 1005 || otherGestureRecognizer.view.tag == 1009) { return NO; } return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]; } #pragma mark - XPMineCustomNavViewDelegate - (void)xPMineCustomNavView:(XPMineUserInfoCustomNavView *)view didClickEditButton:(UIButton *)sender { if (sender.isSelected) {///自己看自己的 去修改资料 self.editVC.area = self.userInfo.region; [self.navigationController pushViewController:self.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 { if (roomUid.length > 0 ) { if(roomUid.integerValue == [XPSkillCardPlayerManager shareInstance].roomUid.integerValue && [XPRoomMiniManager shareManager].getRoomInfo == nil){ [self.navigationController popViewControllerAnimated:YES]; return; } //退出原来的房间 如果有的话 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 - XPMineUserInfoIndividualTagView - (void)didClickGotoEditVC{ XPMineUserInfoTagVC *tagVC =[XPMineUserInfoTagVC new]; tagVC.tagModel = self.tagModel; tagVC.delegate = self; [self.navigationController pushViewController:tagVC animated:YES]; } #pragma mark- XPMineUserInfoTagVCDelegate - (void)xPMineUserInfoTagVC:(XPMineUserInfoTagVC *)vc didClickComplete:(NSArray *)meLabels{ self.headView.tagModel = self.tagModel; } #pragma mark - XPMineUserInfoProtocol - (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo { self.userInfo = userInfo; self.headView.userInfo = userInfo; XPMineUserInfoTagModel *tagModel = [XPMineUserInfoTagModel new]; tagModel.meLabels = userInfo.labels; self.tagModel = tagModel; self.editVC.tagModel = tagModel; self.headView.tagModel = tagModel; self.userDataVC.userInfo = userInfo; self.headerHeight = [XPMineUserInfoHeaderView headerHeight:userInfo]; [self.pagingView reloadData]; //获取用户详细信息 跟随进房目前使用的这个接口 [self.presenter getUserDetailInfoWithUid:@(self.uid).stringValue]; } - (void)onGetUserInfoFailure { [self.navigationController popViewControllerAnimated:YES]; } - (void)onGetDetailInfoSuccess:(UserInfoModel *)userInfo { self.userDataVC.giftWall = userInfo.userGiftWall; self.userDataVC.luckyGiftWall = userInfo.userLuckyBagGiftWall; self.userDataVC.dynamicInfo = userInfo.dynamicInfo; self.userDataVC.medalInfo = userInfo.medals; self.userMomentVC.dynamicInfo = userInfo.dynamicInfo; self.headView.roomUid = userInfo.roomUid; self.giftVC.userInfo = userInfo; if(isMSRTL()){ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.titleView selectItemAtIndex:0]; }); } } - (void)getAttentionStateSuccess:(BOOL)status { self.attentionButton.selected = status; } - (void)attentionUserSuccess:(BOOL)status { self.attentionButton.selected = status; } #pragma mark -XPMineUserInfoEditViewController - (void)xPMineUserInfoEditViewControllerC:(XPMineUserInfoEditViewController *)vc didClickComplete:(NSString *)meLabels{ self.headView.tagModel = self.tagModel; } - (void)xPMineUserInfoEditViewControllerC:(XPMineUserInfoEditViewController *)vc didClickCompleteArea:(NSString *)area{ self.userInfo.region = area; self.userDataVC.userInfo = self.userInfo; } #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 setImage:[UIImage imageNamed:@"mine_user_info_edit_self"] forState:UIControlStateNormal]; } else { [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.userDataVC.userUid = uidStr; self.giftVC.userUid = uidStr; self.editVC.uid = uidStr; } } - (XPMineUserInfoHeaderView *)headView { if (!_headView) { _headView = [[XPMineUserInfoHeaderView alloc] init]; _headView.delegate = self; } return _headView; } - (XPMineUserInfoCustomNavView *)navView { if (!_navView) { _navView = [[XPMineUserInfoCustomNavView alloc] init]; _navView.delegate = self; [_navView updateBackButtonImage:[UIImage imageNamed:@"home_search_white_back"]]; } 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(@"XPMineUserInfoViewController8") forState:UIControlStateNormal]; [_chatButton setTitleColor:UIColorFromRGB(0x9168FA) forState:UIControlStateNormal]; _chatButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; [_chatButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xCCF8F9),UIColorFromRGB(0xDEE4FF),UIColorFromRGB(0xEEDCFF)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal]; UIImage *lineImage = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientMiddleColor],[DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake((KScreenWidth - 30 - 25) / 2, 45)]; UIColor *lineColor = [UIColor colorWithPatternImage:lineImage]; _chatButton.layer.borderWidth = 1; _chatButton.layer.borderColor = lineColor.CGColor; _chatButton.layer.masksToBounds = YES; _chatButton.layer.cornerRadius = 45/2; [_chatButton addTarget:self action:@selector(chatButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _chatButton; } - (UIButton *)attentionButton { if (!_attentionButton) { _attentionButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_attentionButton setTitle:YMLocalizedString(@"XPMineUserInfoViewController9") forState:UIControlStateNormal]; [_attentionButton setTitle:YMLocalizedString(@"XPMineUserInfoViewController10") forState:UIControlStateSelected]; [_attentionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_attentionButton setTitleColor:UIColorFromRGB(0xB3B3C3) forState:UIControlStateSelected]; _attentionButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; [_attentionButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientMiddleColor],[DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal]; [_attentionButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xE6E6F0),UIColorFromRGB(0xE6E6F0),UIColorFromRGB(0xE6E6F0)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateSelected]; _attentionButton.layer.masksToBounds = YES; _attentionButton.layer.cornerRadius = 45/2; [_attentionButton addTarget:self action:@selector(attentionButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _attentionButton; } - (JXCategoryTitleView *)titleView { if (!_titleView) { _titleView = [[JXCategoryTitleView alloc] init]; _titleView.delegate = self; _titleView.backgroundColor = [UIColor whiteColor]; _titleView.titleColor = UIColorRGBAlpha(0x191919, 0.5); _titleView.titleSelectedColor = UIColorFromRGB(0x191919); _titleView.titleFont = [UIFont systemFontOfSize:18 weight:UIFontWeightBold]; _titleView.titleSelectedFont = [UIFont systemFontOfSize:20 weight:UIFontWeightBold]; _titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter; _titleView.contentScrollViewClickTransitionAnimationEnabled = NO; _titleView.defaultSelectedIndex = isMSRTL() ? 1 : 0; _titleView.averageCellSpacingEnabled = NO; _titleView.contentEdgeInsetLeft = 15; _titleView.titles = self.titles; _titleView.cellSpacing = 20; _titleView.listContainer = (id)self.pagingView.listContainerView; JXCategoryIndicatorImageView *lineView = [[JXCategoryIndicatorImageView alloc] init]; lineView.verticalMargin = 8; lineView.indicatorImageView.layer.masksToBounds = YES; lineView.indicatorImageView.layer.cornerRadius = 1.5; lineView.indicatorImageView.image = [UIImage imageWithColor:UIColorFromRGB(0x26cc9c)]; lineView.indicatorImageView.contentMode = UIViewContentModeScaleAspectFill; lineView.indicatorImageViewSize = CGSizeMake(18, 3); _titleView.indicators = @[lineView]; } return _titleView; } - (JXPagerView *)pagingView { if (!_pagingView) { _pagingView = [[JXPagerView alloc] initWithDelegate:self]; _pagingView.backgroundColor = [UIColor clearColor]; _pagingView.listContainerView.backgroundColor = [UIColor clearColor]; _pagingView.mainTableView.backgroundColor = [UIColor clearColor]; _pagingView.listContainerView.listCellBackgroundColor = UIColor.clearColor; _pagingView.listContainerView.scrollView.bounces = NO; _pagingView.mainTableView.gestureDelegate = self; } return _pagingView; } - (NSArray *)titles { if (!_titles) { _titles = @[YMLocalizedString(@"XPMineUserInfoViewController11"), YMLocalizedString(@"XPMineUserInfoViewController12") ]; } return _titles; } - (XPMineUserDataViewController *)userDataVC { if (!_userDataVC) { _userDataVC = [[XPMineUserDataViewController alloc] init]; _userDataVC.delegate = self; } return _userDataVC; } - (XPMomentUserDataViewController *)userMomentVC { if (!_userMomentVC) { _userMomentVC = [[XPMomentUserDataViewController alloc] init]; } return _userMomentVC; } -(XPGiftUserDataViewController *)giftVC{ if (!_giftVC){ _giftVC = [XPGiftUserDataViewController new]; } return _giftVC; } - (XPMineUserInfoEditViewController *)editVC{ if (!_editVC){ _editVC = [XPMineUserInfoEditViewController new]; _editVC.delegate = self; } return _editVC; } @end