Files
yinmeng-ios/xplan-ios/Main/Mine/View/XPMineViewController.m

463 lines
15 KiB
Mathematica
Raw Normal View History

2021-09-16 19:30:22 +08:00
//
// XPMineViewController.m
// xplan-ios
//
// Created by on 2021/9/16.
//
#import "XPMineViewController.h"
///Third
#import <Masonry/Masonry.h>
2021-09-17 19:41:09 +08:00
#import <flutter_boost/FlutterBoost.h>
2021-09-16 19:30:22 +08:00
///Tool
2022-01-21 19:47:46 +08:00
#import "TTPopup.h"
2021-09-16 19:30:22 +08:00
#import "XPMacro.h"
2021-09-17 19:41:09 +08:00
#import "XPHtmlUrl.h"
#import "UIButton+EnlargeTouchArea.h"
2022-01-11 11:28:04 +08:00
#import "StatisticsServiceHelper.h"
2022-01-26 15:51:19 +08:00
#import "XPConstant.h"
2022-01-21 19:47:46 +08:00
#import "Api+Room.h"
2021-09-16 19:30:22 +08:00
///Model
#import "XPMineItemModel.h"
2021-09-23 18:38:33 +08:00
#import "UserInfoModel.h"
2022-01-26 15:51:19 +08:00
#import "XPMineVisitorUnReadModel.h"
2021-09-16 19:30:22 +08:00
///P
#import "XPMineProtocol.h"
#import "XPMinePresent.h"
///View
#import "XPMineMenuTableViewCell.h"
#import "XPMineHeadItemTableViewCell.h"
2021-09-16 19:30:22 +08:00
#import "XPMineHeadView.h"
2022-01-19 16:29:07 +08:00
#import "XPMineSkillTipView.h"
2022-01-21 19:47:46 +08:00
#import "XPLittleGameRoomOpenView.h"
2021-09-17 19:41:09 +08:00
///VC
#import "XPMineSettingViewController.h"
#import "XPMineTeenagerViewController.h"
2021-09-23 18:38:33 +08:00
#import "XPMineUserInfoViewController.h"
2021-09-24 19:17:19 +08:00
#import "XPMineRechargeViewController.h"
2021-09-17 19:41:09 +08:00
#import "XPWebViewController.h"
2021-10-14 21:10:04 +08:00
#import "XPRoomViewController.h"
2021-12-16 19:02:31 +08:00
#import "XPMineDressUpViewController.h"
#import "XPMineFansViewController.h"
#import "XPMineAttentionViewController.h"
2021-12-28 17:32:27 +08:00
#import "XPNobleCenterViewController.h"
#import "XPMatchManageViewController.h"
#import "XPSkillCardViewController.h"
2022-01-26 11:51:06 +08:00
#import "XPMineVisitorViewController.h"
2022-04-08 16:16:38 +08:00
#import "XPMineFansTeamViewController.h"
@interface XPMineViewController ()<UITableViewDelegate, UITableViewDataSource, XPMineProtocol, XPMineHeadItemTableViewCellDelegate, XPMineHeadViewDelegate>
///
@property (nonatomic, strong) UIView *bgImageView;
2021-09-16 19:30:22 +08:00
@property (nonatomic,strong) UITableView *tableView;
///
@property (nonatomic,strong) NSArray<XPMineItemModel *> *datasource;
///
@property (nonatomic,strong) NSArray<XPMineItemModel *> *matchItemArray;
///item
@property (nonatomic, strong) NSArray<XPMineItemModel *> *cardItemArray;
2021-09-16 19:30:22 +08:00
///
@property (nonatomic,strong) XPMineHeadView *headView;
///
@property (nonatomic,strong) UIButton *settingButton;
///
@property (nonatomic,strong) UserInfoModel *userInfo;
2021-09-16 19:30:22 +08:00
2022-01-19 16:29:07 +08:00
@property (nonatomic, strong) XPMineSkillTipView *skillTipView;
2021-09-16 19:30:22 +08:00
@end
@implementation XPMineViewController
2022-01-26 15:51:19 +08:00
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
2021-09-16 19:30:22 +08:00
- (BOOL)isHiddenNavBar {
return YES;
}
- (XPMinePresent *)createPresenter {
return [[XPMinePresent alloc] init];;
}
2022-01-26 15:51:19 +08:00
- (instancetype)init {
if (self = [super init]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onVisitorUnReadCountUpdate:) name:kVisitorUnReadCountNotificationKey object:nil];
}
return self;
}
2021-09-16 19:30:22 +08:00
- (void)viewDidLoad {
[super viewDidLoad];
2021-09-16 19:30:22 +08:00
[self initSubViews];
[self initSubViewConstraints];
2022-01-19 16:29:07 +08:00
[self showSkillCardTipView];
2021-09-16 19:30:22 +08:00
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.presenter getUserInfo];
}
#pragma mark - Response
- (void)settingButtonAction:(UIButton *)sender {
2021-09-17 19:41:09 +08:00
XPMineSettingViewController * settingVC = [[XPMineSettingViewController alloc] init];
settingVC.userInfo = self.userInfo;
2021-09-17 19:41:09 +08:00
[self.navigationController pushViewController:settingVC animated:YES];
2021-09-16 19:30:22 +08:00
}
#pragma mark - Private Method
- (void)initSubViews {
[self.view addSubview:self.bgImageView];
2021-09-16 19:30:22 +08:00
[self.view addSubview:self.tableView];
[self.view addSubview:self.settingButton];
self.tableView.tableHeaderView = self.headView;
[self.presenter getNormalItems];
[self.presenter getCardItems];
2022-01-19 16:29:07 +08:00
if (@available(iOS 15.0, *)) {//iOS1522
self.tableView.sectionHeaderTopPadding = 0;
}
2021-09-16 19:30:22 +08:00
}
- (void)initSubViewConstraints {
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(0);
}];
2021-09-16 19:30:22 +08:00
[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);
}];
}
2022-01-19 16:29:07 +08:00
///
- (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];
}
}
2021-09-16 19:30:22 +08:00
- (void)pushViewControllerWithType:(XPMineItemType)type {
switch (type) {
case XPMineItemType_Match_Manage: {
XPMatchManageViewController *vc = [[XPMatchManageViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
break;
2021-09-16 19:30:22 +08:00
case XPMineItemType_Match_Apply_Record:
2021-09-17 19:41:09 +08:00
[self pushMatchVCWithKey:@"quotaRecord"];
2021-09-16 19:30:22 +08:00
break;
case XPMineItemType_Match_Standings:
2021-09-17 19:41:09 +08:00
[self pushMatchVCWithKey:@"performance"];
2021-09-16 19:30:22 +08:00
break;
case XPMineItemType_Match_Card_Bag:
2021-09-17 19:41:09 +08:00
[self pushMatchVCWithKey:@"bag"];
2021-09-16 19:30:22 +08:00
break;
case XPMineItemType_Match_Shopping:
2021-09-17 19:41:09 +08:00
[self pushMatchVCWithKey:@"mall"];
2021-09-16 19:30:22 +08:00
break;
case XPMineItemType_Match_Relevance_Account:
2021-09-17 19:41:09 +08:00
[self pushWebViewWIthUrl:URLWithType(kGameBindAccountURL)];
2021-09-16 19:30:22 +08:00
break;
case XPMineItemType_Teenager_Mode:
{
XPMineTeenagerViewController * vc = [[XPMineTeenagerViewController alloc] init];
vc.userInfo = self.userInfo;
[self.navigationController pushViewController:vc animated:YES];
}
2021-09-16 19:30:22 +08:00
break;
case XPMineItemType_Real_Name_Authentic:
2021-09-17 19:41:09 +08:00
[self pushWebViewWIthUrl:URLWithType(kIdentityURL)];
break;
case XPMineItemType_Account:
2021-09-24 19:17:19 +08:00
{
2021-10-25 10:22:40 +08:00
XPMineRechargeViewController * rechargeVC = [[XPMineRechargeViewController alloc] init];
[self.navigationController pushViewController:rechargeVC animated:YES];
2021-09-24 19:17:19 +08:00
}
2021-09-17 19:41:09 +08:00
break;
case XPMineItemType_Invite_Friend:
[self pushWebViewWIthUrl:URLWithType(kUserInviteFriendURL)];
break;
case XPMineItemType_Personinfo:
2021-09-23 18:38:33 +08:00
{
XPMineUserInfoViewController * infoVC = [[XPMineUserInfoViewController alloc] init];
infoVC.uid = self.userInfo.uid;
[self.navigationController pushViewController:infoVC animated:YES];
}
2021-09-16 19:30:22 +08:00
break;
case XPMineItemType_My_Room:
{
NSString* roomUid = [NSString stringWithFormat:@"%ld", (long)self.userInfo.uid];
2022-01-21 19:47:46 +08:00
[Api getRoomInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
RoomInfoModel * roomInfo = [RoomInfoModel modelWithJSON:data.data];
if (roomInfo.isReselect) {
XPLittleGameRoomOpenView * roomOpenView = [[XPLittleGameRoomOpenView alloc] init];
roomOpenView.roomInfo = roomInfo;
roomOpenView.currentVC = self;
2022-01-21 19:47:46 +08:00
[TTPopup popupView:roomOpenView style:TTPopupStyleActionSheet];
} else {
[XPRoomViewController openRoom:roomUid viewController:self];
}
} else {
[self showErrorToast:msg];
}
} uid:roomUid intoUid:roomUid];
}
break;
2021-12-16 19:02:31 +08:00
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;
2021-12-28 17:32:27 +08:00
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];
2022-01-26 11:51:06 +08:00
}
break;
case XPMineItemType_Visitor:
{
2022-01-26 15:51:19 +08:00
[self.tabBarItem setBadgeValue:nil];
for (XPMineItemModel * model in self.datasource) {
if (model.type == XPMineItemType_Visitor) {
model.unReadCount = 0;
}
}
2022-01-26 11:51:06 +08:00
XPMineVisitorViewController *visitorVC = [[XPMineVisitorViewController alloc] init];
[self.navigationController pushViewController:visitorVC animated:YES];
2022-04-08 16:16:38 +08:00
}
break;
case XPMineItemType_FansTeam: {
XPMineFansTeamViewController *fansTeamVc = [[XPMineFansTeamViewController alloc] init];
[self.navigationController pushViewController:fansTeamVc animated:YES];
2021-12-28 17:32:27 +08:00
}
break;
2021-09-16 19:30:22 +08:00
default:
break;
}
}
2021-09-17 19:41:09 +08:00
- (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) {
}];
}
2021-09-16 19:30:22 +08:00
#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;
2021-09-16 19:30:22 +08:00
};
return 53;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
XPMineHeadItemTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineHeadItemTableViewCell class])];
2021-09-16 19:30:22 +08:00
if (cell == nil) {
cell = [[XPMineHeadItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineHeadItemTableViewCell class])];
2021-09-16 19:30:22 +08:00
}
cell.datasource = self.cardItemArray;
2021-09-16 19:30:22 +08:00
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) {
2022-01-19 16:29:07 +08:00
return 13;
2021-09-16 19:30:22 +08:00
}
2022-01-19 16:29:07 +08:00
return 16;
2021-09-16 19:30:22 +08:00
}
- (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 {
2021-09-17 19:41:09 +08:00
[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];
2021-09-16 19:30:22 +08:00
}
- (void)xpMineHeadViewClickFans {
[self pushViewControllerWithType:XPMineItemType_Fans_List];
}
- (void)xpMineHeadViewClickAttention {
[self pushViewControllerWithType:XPMineItemType_Attention_List];
}
- (void)xPMineHeadViewCliekNobleCenter {
2022-01-11 11:28:04 +08:00
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventvipEntranceMeClick];
[self pushViewControllerWithType:XPMineItemType_Noble_Center];
}
2021-09-16 19:30:22 +08:00
#pragma mark - XPMineProtocol
- (void)onGetNormalItemsSuccess:(NSArray<XPMineItemModel *> *)normalItems {
self.datasource = normalItems;
[self.tableView reloadData];
}
- (void)onGetCardItemsSuccess:(NSArray<XPMineItemModel *> *)cardItems {
self.cardItemArray = cardItems;
[self.tableView reloadData];
2021-09-16 19:30:22 +08:00
}
- (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo {
self.userInfo = userInfo;
2021-09-16 19:30:22 +08:00
self.headView.userInfo = userInfo;
2022-01-19 16:29:07 +08:00
[self.tableView reloadData];
2021-09-16 19:30:22 +08:00
}
#pragma mark - XPMineHeadItemTableViewCellDelegate
- (void)xPMineHeadItemTableViewCell:(XPMineHeadItemTableViewCell *)cell didSelectItem:(XPMineItemModel *)item {
[self pushViewControllerWithType:item.type];
2021-09-16 19:30:22 +08:00
}
2022-01-26 15:51:19 +08:00
#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<self.datasource.count; i++) {
XPMineItemModel * item = [self.datasource objectAtIndex:i];
if (item.type == XPMineItemType_Visitor) {
item.unReadCount = model.visitNum;
}
}
[self.tableView reloadData];
}
2021-09-16 19:30:22 +08:00
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[_tableView registerClass:[XPMineMenuTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineMenuTableViewCell class])];
[_tableView registerClass:[XPMineHeadItemTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineHeadItemTableViewCell class])];
2021-09-16 19:30:22 +08:00
_tableView.backgroundColor = [UIColor clearColor];
}
return _tableView;
}
- (XPMineHeadView *)headView {
if (!_headView) {
CGFloat nobleH = (KScreenWidth - 30.0)/ 345.0 * 44;
_headView = [[XPMineHeadView alloc] initWithFrame:CGRectMake(0, 0,KScreenWidth , 123 + nobleH + kSafeAreaTopHeight)];
2021-09-16 19:30:22 +08:00
_headView.delegate = self;
}
return _headView;
}
- (UIButton *)settingButton {
if (!_settingButton) {
_settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_settingButton setImage:[UIImage imageNamed:@"mine_nav_setting"] forState:UIControlStateNormal];
[_settingButton setImage:[UIImage imageNamed:@"mine_nav_setting"] forState:UIControlStateSelected];
[_settingButton addTarget:self action:@selector(settingButtonAction:) forControlEvents:UIControlEventTouchUpInside];
2021-09-17 19:41:09 +08:00
[_settingButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
2021-09-16 19:30:22 +08:00
}
return _settingButton;
}
- (UIView *)bgImageView {
if (!_bgImageView) {
_bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_head_bg"]];
_bgImageView.contentMode = UIViewContentModeScaleAspectFill;
}
return _bgImageView;
}
2021-09-16 19:30:22 +08:00
2022-01-19 16:29:07 +08:00
- (XPMineSkillTipView *)skillTipView {
if (!_skillTipView) {
_skillTipView = [[XPMineSkillTipView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
}
return _skillTipView;
}
2021-09-16 19:30:22 +08:00
@end