// // XPMineViewController.m // xplan-ios // // Created by 冯硕 on 2021/9/16. // #import "XPMineViewController.h" ///Third #import #import ///Tool #import "XPMacro.h" #import "XPHtmlUrl.h" #import "UIButton+EnlargeTouchArea.h" #import "StatisticsServiceHelper.h" #import "XPConstant.h" ///Model #import "XPMineItemModel.h" #import "UserInfoModel.h" #import "XPMineVisitorUnReadModel.h" ///P #import "XPMineProtocol.h" #import "XPMinePresent.h" ///View #import "XPMineMenuTableViewCell.h" #import "XPMineHeadItemTableViewCell.h" #import "XPMineHeadView.h" #import "XPMineSkillTipView.h" ///VC #import "XPMineSettingViewController.h" #import "XPMineTeenagerViewController.h" #import "XPMineUserInfoViewController.h" #import "XPMineRechargeViewController.h" #import "XPWebViewController.h" #import "XPRoomViewController.h" #import "XPMineDressUpViewController.h" #import "XPMineFansViewController.h" #import "XPMineAttentionViewController.h" #import "XPNobleCenterViewController.h" #import "XPMatchManageViewController.h" #import "XPSkillCardViewController.h" #import "XPMineVisitorViewController.h" @interface XPMineViewController () ///顶部背景 @property (nonatomic, strong) UIView *bgImageView; @property (nonatomic,strong) UITableView *tableView; ///数据源 @property (nonatomic,strong) NSArray *datasource; ///赛事模块的 @property (nonatomic,strong) NSArray *matchItemArray; ///卡片item @property (nonatomic, strong) NSArray *cardItemArray; ///头部 @property (nonatomic,strong) XPMineHeadView *headView; ///设置 @property (nonatomic,strong) UIButton *settingButton; /// @property (nonatomic,strong) UserInfoModel *userInfo; @property (nonatomic, strong) XPMineSkillTipView *skillTipView; @end @implementation XPMineViewController - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (BOOL)isHiddenNavBar { return YES; } - (XPMinePresent *)createPresenter { return [[XPMinePresent alloc] init];; } - (instancetype)init { if (self = [super init]) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onVisitorUnReadCountUpdate:) name:kVisitorUnReadCountNotificationKey object:nil]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self initSubViews]; [self initSubViewConstraints]; [self showSkillCardTipView]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.presenter getUserInfo]; } #pragma mark - Response - (void)settingButtonAction:(UIButton *)sender { XPMineSettingViewController * settingVC = [[XPMineSettingViewController alloc] init]; settingVC.userInfo = self.userInfo; [self.navigationController pushViewController:settingVC animated:YES]; } #pragma mark - Private Method - (void)initSubViews { [self.view addSubview:self.bgImageView]; [self.view addSubview:self.tableView]; [self.view addSubview:self.settingButton]; self.tableView.tableHeaderView = self.headView; [self.presenter getNormalItems]; [self.presenter getCardItems]; if (@available(iOS 15.0, *)) {//移除iOS15列表头默认增加的22高度 self.tableView.sectionHeaderTopPadding = 0; } } - (void)initSubViewConstraints { [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.mas_equalTo(0); }]; [self.settingButton mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(18, 18)); make.right.mas_equalTo(self.view).offset(-14); make.top.mas_equalTo(self.view).offset(kSafeAreaTopHeight + 29); }]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.view); make.left.right.bottom.mas_equalTo(self.view); }]; } ///展示技能卡引导 - (void)showSkillCardTipView { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *skillCardTip = [defaults objectForKey:kYinyouSkillCardTipKey]; if (!skillCardTip) { UIWindow *window = [UIApplication sharedApplication].delegate.window; [window addSubview:self.skillTipView]; [window bringSubviewToFront:self.skillTipView]; } } - (void)pushViewControllerWithType:(XPMineItemType)type { switch (type) { case XPMineItemType_Match_Manage: { XPMatchManageViewController *vc = [[XPMatchManageViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } break; case XPMineItemType_Match_Apply_Record: [self pushMatchVCWithKey:@"quotaRecord"]; break; case XPMineItemType_Match_Standings: [self pushMatchVCWithKey:@"performance"]; break; case XPMineItemType_Match_Card_Bag: [self pushMatchVCWithKey:@"bag"]; break; case XPMineItemType_Match_Shopping: [self pushMatchVCWithKey:@"mall"]; break; case XPMineItemType_Match_Relevance_Account: [self pushWebViewWIthUrl:URLWithType(kGameBindAccountURL)]; break; case XPMineItemType_Teenager_Mode: { XPMineTeenagerViewController * vc = [[XPMineTeenagerViewController alloc] init]; vc.userInfo = self.userInfo; [self.navigationController pushViewController:vc animated:YES]; } break; case XPMineItemType_Real_Name_Authentic: [self pushWebViewWIthUrl:URLWithType(kIdentityURL)]; break; case XPMineItemType_Account: { XPMineRechargeViewController * rechargeVC = [[XPMineRechargeViewController alloc] init]; [self.navigationController pushViewController:rechargeVC animated:YES]; } break; case XPMineItemType_Invite_Friend: [self pushWebViewWIthUrl:URLWithType(kUserInviteFriendURL)]; break; case XPMineItemType_Personinfo: { XPMineUserInfoViewController * infoVC = [[XPMineUserInfoViewController alloc] init]; infoVC.uid = self.userInfo.uid; [self.navigationController pushViewController:infoVC animated:YES]; } break; case XPMineItemType_My_Room: { NSString* roomUid = [NSString stringWithFormat:@"%ld", (long)self.userInfo.uid]; [XPRoomViewController openRoom:roomUid viewController:self]; } break; case XPMineItemType_My_Dressup: { XPMineDressUpViewController * dressUpVC = [[XPMineDressUpViewController alloc] init]; [self.navigationController pushViewController:dressUpVC animated:YES]; } break; case XPMineItemType_Fans_List: { XPMineFansViewController * fansVC = [[XPMineFansViewController alloc] init]; [self.navigationController pushViewController:fansVC animated:YES]; } break; case XPMineItemType_Attention_List: { XPMineAttentionViewController * attentionVC = [[XPMineAttentionViewController alloc] init]; [self.navigationController pushViewController:attentionVC animated:YES]; } break; case XPMineItemType_My_Level: [self pushWebViewWIthUrl:URLWithType(kUserLevelURL)]; break; case XPMineItemType_Noble_Center: { XPNobleCenterViewController *nobleCenterVC = [[XPNobleCenterViewController alloc] init]; [self.navigationController pushViewController:nobleCenterVC animated:YES]; } break; case XPMineItemType_Skill_Card: { XPSkillCardViewController *skillCardVC = [[XPSkillCardViewController alloc] init]; skillCardVC.uid = self.userInfo.uid; [self.navigationController pushViewController:skillCardVC animated:YES]; } break; case XPMineItemType_Visitor: { [self.tabBarItem setBadgeValue:nil]; for (XPMineItemModel * model in self.datasource) { if (model.type == XPMineItemType_Visitor) { model.unReadCount = 0; } } XPMineVisitorViewController *visitorVC = [[XPMineVisitorViewController alloc] init]; [self.navigationController pushViewController:visitorVC animated:YES]; } break; default: break; } } - (void)pushWebViewWIthUrl:(NSString *)url { XPWebViewController * webVC = [[XPWebViewController alloc] init]; webVC.url = url; [self.navigationController pushViewController:webVC animated:YES]; } - (void)pushMatchVCWithKey:(NSString *)key { [[FlutterBoost instance] open:key arguments:@{@"animated":@(YES)} completion:^(BOOL success) { }]; } #pragma mark - UITableViewDelegate And UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 0) { return 1; } return self.datasource.count; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { return 96; }; return 53; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { XPMineHeadItemTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineHeadItemTableViewCell class])]; if (cell == nil) { cell = [[XPMineHeadItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineHeadItemTableViewCell class])]; } cell.datasource = self.cardItemArray; cell.delegate = self; return cell; } else { XPMineMenuTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineMenuTableViewCell class])]; if (cell == nil) { cell = [[XPMineMenuTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineMenuTableViewCell class])]; } XPMineItemModel * item = [self.datasource objectAtIndex:indexPath.row]; cell.itemModel = item; return cell; } } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == 1) { return 13; } return 16; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView * view = [[UIView alloc] init]; view.backgroundColor = [UIColor clearColor]; return view; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; XPMineItemModel * model = [self.datasource objectAtIndex:indexPath.row]; [self pushViewControllerWithType:model.type]; } #pragma mark - XPMineHeadViewDelegate ///点击头像 - (void)xPMineHeadView:(XPMineHeadView *)view didClickAvatar:(UserInfoModel *)info { [self pushViewControllerWithType:XPMineItemType_Personinfo]; } - (void)xPMineHeadView:(XPMineHeadView *)view didClickAccount:(UserInfoModel *)info { [self pushViewControllerWithType:XPMineItemType_Account]; } - (void)xPMineHeadView:(XPMineHeadView *)view didClickInviteFriend:(UserInfoModel *)info { [self pushViewControllerWithType:XPMineItemType_Invite_Friend]; } - (void)xpMineHeadViewClickFans { [self pushViewControllerWithType:XPMineItemType_Fans_List]; } - (void)xpMineHeadViewClickAttention { [self pushViewControllerWithType:XPMineItemType_Attention_List]; } - (void)xPMineHeadViewCliekNobleCenter { [StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventvipEntranceMeClick]; [self pushViewControllerWithType:XPMineItemType_Noble_Center]; } #pragma mark - XPMineProtocol - (void)onGetNormalItemsSuccess:(NSArray *)normalItems { self.datasource = normalItems; [self.tableView reloadData]; } - (void)onGetCardItemsSuccess:(NSArray *)cardItems { self.cardItemArray = cardItems; [self.tableView reloadData]; } - (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo { self.userInfo = userInfo; self.headView.userInfo = userInfo; [self.tableView reloadData]; } #pragma mark - XPMineHeadItemTableViewCellDelegate - (void)xPMineHeadItemTableViewCell:(XPMineHeadItemTableViewCell *)cell didSelectItem:(XPMineItemModel *)item { [self pushViewControllerWithType:item.type]; } #pragma mark - NSNotification - (void)onVisitorUnReadCountUpdate:(NSNotification *)noti { XPMineVisitorUnReadModel *model = (XPMineVisitorUnReadModel *)noti.object; if (model.visitNum > 0) { [self.tabBarItem setBadgeValue:[NSString stringWithFormat:@"%ld", model.visitNum]]; } else { [self.tabBarItem setBadgeValue:nil]; } for (int i = 0; i