211 lines
6.8 KiB
Objective-C
211 lines
6.8 KiB
Objective-C
//
|
||
// ViewController.m
|
||
// xplan-ios
|
||
//
|
||
// Created by zu on 2021/8/31.
|
||
//
|
||
#import <UIKit/UIKit.h>
|
||
///Third
|
||
#import <flutter_boost/FlutterBoost.h>
|
||
#import <ReactiveObjC/ReactiveObjC.h>
|
||
///Tool
|
||
#import "XPMacro.h"
|
||
#import "ThemeColor.h"
|
||
#import "UIImage+Utils.h"
|
||
#import "XCHUDTool.h"
|
||
#import "RechargeStorage.h"
|
||
#import "AccountInfoStorage.h"
|
||
#import "XPIMManager.h"
|
||
///Model
|
||
#import "AccountModel.h"
|
||
///VC
|
||
#import "TabbarViewController.h"
|
||
#import "BaseViewController.h"
|
||
#import "LoginViewController.h"
|
||
#import "BaseNavigationController.h"
|
||
#import "LoginBindPhoneViewController.h"
|
||
#import "LoginFullInfoViewController.h"
|
||
#import "XplanFBFlutterViewContainer.h"
|
||
#import "XPMineViewController.h"
|
||
///Present
|
||
#import "MainPresenter.h"
|
||
#import "MainProtocol.h"
|
||
#import "XPIMLoginDelegate.h"
|
||
|
||
|
||
|
||
@interface TabbarViewController () <BaseMvpProtocol, MainProtocol, XPIMLoginDelegate>
|
||
|
||
@property (nonatomic, strong) MainPresenter *presenter;
|
||
|
||
@end
|
||
|
||
@implementation TabbarViewController
|
||
|
||
- (void)dealloc {
|
||
[[XPIMManager shareManager].imLoginManager removeDelegate:self];
|
||
}
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
[self configTheme];
|
||
[self initTabs:NO];
|
||
[self configImDelegate];
|
||
}
|
||
|
||
- (void)viewWillAppear:(BOOL)animated {
|
||
[super viewWillAppear:animated];
|
||
[self.navigationController setNavigationBarHidden:YES animated:YES];
|
||
[self.presenter autoLogin];
|
||
[self checkTranscationIds];
|
||
}
|
||
|
||
- (MainPresenter *)presenter {
|
||
if (_presenter == nil) {
|
||
_presenter = [[MainPresenter alloc] init];
|
||
[_presenter attatchView:self];
|
||
}
|
||
return _presenter;
|
||
}
|
||
|
||
/// 换取ticket后获取用户信息
|
||
/// 重新获取ticket后才会回调该方法,详见MainPresenter.autoLogin()
|
||
- (void)autoLoginSuccess {
|
||
[self.presenter getUserInfo];
|
||
}
|
||
|
||
/// 获取用户信息后检查:1、是否绑定手机号;2、是否需要完善用户信息。
|
||
/// 该逻辑仅在刷新ticket后执行一次。
|
||
/// 当前服务端接口是有未完善信息的全局拦截的,在BaseMvpPresenter里会触发1415去完善用户信息。
|
||
- (void)getUserInfoSuccess:(UserInfoModel *)userInfo {
|
||
if (!userInfo.isBindPhone) {
|
||
// 绑定手机号
|
||
[self bindPhone];
|
||
return;
|
||
}
|
||
if (userInfo.nick == nil || userInfo.avatar == nil) {
|
||
[self completeUserInfo];
|
||
return;
|
||
}
|
||
[self initTabs:YES];
|
||
}
|
||
|
||
- (void)tokenInvalid {
|
||
LoginViewController *lvc = [[LoginViewController alloc] init];
|
||
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:lvc];
|
||
nav.modalPresentationStyle = UIModalPresentationFullScreen;
|
||
[self.navigationController presentViewController:nav animated:YES completion:nil];
|
||
}
|
||
|
||
- (void)completeUserInfo {
|
||
LoginFullInfoViewController * bindPhoneVC = [[LoginFullInfoViewController alloc] init];
|
||
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:bindPhoneVC];
|
||
nav.modalPresentationStyle = UIModalPresentationFullScreen;
|
||
[self.navigationController presentViewController:nav animated:YES completion:nil];
|
||
}
|
||
|
||
///批量验证内购凭据成功
|
||
- (void)checkTranscationIdsSuccess {
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
[RechargeStorage delegateAllTranscationIdsWithUid:uid];
|
||
}
|
||
|
||
#pragma mark - XPIMLoginDelegate
|
||
///用户被踢
|
||
- (void)imKickOut:(NSString *)reason {
|
||
[self tokenInvalid];
|
||
}
|
||
|
||
#pragma mark - 批量验证内购凭据
|
||
- (void)checkTranscationIds {
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
NSArray * array = [RechargeStorage getAllReciptsWithUid:uid];
|
||
if (array.count > 0) {
|
||
[self.presenter checkTranscationIds:array];
|
||
}
|
||
}
|
||
|
||
#pragma mark - 绑定手机号
|
||
- (void)bindPhone {
|
||
LoginBindPhoneViewController * bindPhoneVC = [[LoginBindPhoneViewController alloc] init];
|
||
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:bindPhoneVC];
|
||
nav.modalPresentationStyle = UIModalPresentationFullScreen;
|
||
[self.navigationController presentViewController:nav animated:YES completion:nil];
|
||
}
|
||
|
||
- (void)configImDelegate {
|
||
[[XPIMManager shareManager].imLoginManager addDelegate:self];
|
||
[RACObserve([AccountInfoStorage instance], accountModel) subscribeNext:^(id _Nullable x) {
|
||
if (x) {
|
||
AccountModel * model = x;
|
||
[[XPIMManager shareManager].imLoginManager autoLoginIm:model.uid token:model.netEaseToken];
|
||
}
|
||
}];
|
||
}
|
||
|
||
- (void)configTheme {
|
||
[[UITabBar appearance] setBackgroundImage:[UIImage imageWithColor:[ThemeColor appCellBackgroundColor] size:CGSizeMake(KScreenWidth, kTabBarHeight)]];
|
||
[[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
|
||
if (@available(iOS 10.0, *)) {
|
||
[[UITabBar appearance] setUnselectedItemTintColor:[ThemeColor tabbarNormalColor]];
|
||
}
|
||
}
|
||
|
||
- (void)initTabs:(BOOL)logined {
|
||
NSArray *normalImageNames = @[@"tab_game_normal", @"tab_mine_normal"];
|
||
NSArray *selectImageNames = @[@"tab_game_selected", @"tab_mine_selected"];
|
||
NSArray *tabLabel = @[@"赛事", @"我的"];
|
||
|
||
UIViewController *game;
|
||
UIViewController *me;
|
||
if (logined) {
|
||
XplanFBFlutterViewContainer *fvcGame = XplanFBFlutterViewContainer.new;
|
||
#ifdef DEBUG
|
||
[fvcGame setName:@"debug" uniqueId:nil params:nil];
|
||
#else
|
||
[fvcGame setName:@"/" uniqueId:nil params:nil];
|
||
#endif
|
||
game = fvcGame;
|
||
me = [[XPMineViewController alloc] init];
|
||
} else {
|
||
game = [[BaseViewController alloc]init];
|
||
me = [[BaseViewController alloc]init];
|
||
}
|
||
|
||
[self createTabBarItem:game title:tabLabel[0] image:normalImageNames[0] selectedImage:selectImageNames[0]];
|
||
[self createTabBarItem:me title:tabLabel[1] image:normalImageNames[1] selectedImage:selectImageNames[1]];
|
||
|
||
self.viewControllers = @[game, me];
|
||
|
||
self.selectedIndex = 0;
|
||
}
|
||
|
||
- (BaseNavigationController *)createTabBarItem:(UIViewController *)itemVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
|
||
itemVc.title = title;
|
||
itemVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
||
itemVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
||
[itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[ThemeColor appMainColor]} forState:UIControlStateSelected];
|
||
[itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[ThemeColor tabbarNormalColor]} forState:UIControlStateNormal];
|
||
|
||
BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:itemVc];
|
||
return nav;
|
||
}
|
||
|
||
- (void)showSuccessToast:(NSString *)msg {
|
||
[XCHUDTool showSuccessWithMessage:msg];
|
||
}
|
||
|
||
- (void)showErrorToast:(NSString *)msg {
|
||
[XCHUDTool showErrorWithMessage:msg];
|
||
}
|
||
|
||
- (void)showLoading {
|
||
[XCHUDTool showLoading];
|
||
}
|
||
|
||
- (void)hideHUD {
|
||
[XCHUDTool hideHUD];
|
||
}
|
||
|
||
@end
|