Files
yinmeng-ios/xplan-ios/Main/Tabbar/View/TabbarViewController.m

729 lines
32 KiB
Mathematica
Raw Normal View History

2021-09-07 23:05:43 +08:00
//
// ViewController.m
// xplan-ios
//
// Created by zu on 2021/8/31.
//
#import <UIKit/UIKit.h>
///Third
#import <flutter_boost/FlutterBoost.h>
2021-10-21 12:01:21 +08:00
#import <ReactiveObjC/ReactiveObjC.h>
#import <NIMSDK/NIMSDK.h>
2022-08-01 19:24:12 +08:00
#import <Masonry/Masonry.h>
2022-08-04 11:42:49 +08:00
#import <AudioToolbox/AudioToolbox.h>
///Tool
#import "XPMacro.h"
#import "ThemeColor.h"
#import "UIImage+Utils.h"
#import "NSObject+MJExtension.h"
2021-09-15 18:41:40 +08:00
#import "XCHUDTool.h"
2021-09-26 20:42:33 +08:00
#import "AccountInfoStorage.h"
2021-12-07 11:08:43 +08:00
#import "TTPopup.h"
#import "XPConstant.h"
#import "XPRoomMiniManager.h"
2021-12-11 16:15:40 +08:00
#import "ClientConfig.h"
#import "RtcManager.h"
#import "XCCurrentVCStackManager.h"
2022-06-02 18:53:45 +08:00
#import "Api+Home.h"
2022-07-27 17:12:06 +08:00
#import "XPConstant.h"
#import "StatisticsServiceHelper.h"
2022-08-26 17:13:20 +08:00
#import "Api+Monents.h"
2021-10-21 12:01:21 +08:00
///Model
#import "AccountModel.h"
#import "RoomInfoModel.h"
#import "AttachmentModel.h"
#import "NobleLevelUpModel.h"
#import "XPMineVisitorUnReadModel.h"
2022-06-02 18:53:45 +08:00
#import "InviteUserInfoModel.h"
#import "NewUserGreetModel.h"
#import "FindNewGreetMessageModel.h"
2022-08-01 19:24:12 +08:00
#import "XPTabAnchorCardModel.h"
2022-08-02 18:13:51 +08:00
#import "FirstRechargeModel.h"
2022-08-26 17:13:20 +08:00
#import "MonentsUnReadModel.h"
#import "XPReceiveRedPacketModel.h"
///VC
2021-09-07 23:05:43 +08:00
#import "TabbarViewController.h"
#import "BaseViewController.h"
#import "LoginViewController.h"
2021-09-14 21:01:09 +08:00
#import "BaseNavigationController.h"
#import "LoginBindPhoneViewController.h"
#import "LoginFullInfoViewController.h"
2021-09-16 17:21:52 +08:00
#import "XplanFBFlutterViewContainer.h"
2021-09-16 19:30:22 +08:00
#import "XPMineViewController.h"
2021-11-26 20:25:23 +08:00
#import "SessionListViewController.h"
2022-02-21 20:06:09 +08:00
#import "XPHomeViewController.h"
2021-12-03 17:07:21 +08:00
#import "XPMiniRoomView.h"
2021-12-07 11:08:43 +08:00
#import "XPTeenagerAlertView.h"
#import "XPRoomViewController.h"
#import "XPNobleUpgradeLevelView.h"
2022-06-02 18:53:45 +08:00
#import "XPNewUserGreetRoomAlertView.h"
#import "XPSessionFindNewAlertView.h"
2022-07-27 17:12:06 +08:00
#import "XPHomeLivesViewController.h"
2022-07-28 11:56:59 +08:00
#import "XPNewUserRechargeViewController.h"
2022-08-01 19:24:12 +08:00
#import "XPAnchorCardView.h"
2022-08-02 18:13:51 +08:00
#import "XPNewUserRechargeSucessView.h"
#import "XPTaskCompleteTipView.h"
#import "XPWebViewController.h"
#import "XPMineUserInfoViewController.h"
2022-05-13 11:32:35 +08:00
#import "XPMonentsRecommendViewController.h"
2022-05-19 10:39:04 +08:00
#import "XPMonentsViewController.h"
2022-09-02 18:59:36 +08:00
#import "XPReceiveRedPacketView.h"
///Present
2021-09-07 23:05:43 +08:00
#import "MainPresenter.h"
#import "MainProtocol.h"
#import "RoomHostDelegate.h"
2022-06-02 18:53:45 +08:00
UIKIT_EXTERN NSString * kUserCompleteInfoFinishKey;
NSString * const kUserFirstLoginKey = @"kUserFirstLoginKey";
NSString * const kHadLaunchApp = @"kHadLaunchApp";
NSString * const kLastShowAnchorCardTime = @"kLastShowAnchorCardTime";
2022-07-28 11:56:59 +08:00
UIKIT_EXTERN NSString * kNewUserRechargeKey;
2022-08-01 19:24:12 +08:00
UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
2022-06-02 18:53:45 +08:00
2022-08-01 19:24:12 +08:00
@interface TabbarViewController () <BaseMvpProtocol, MainProtocol, NIMLoginManagerDelegate, NIMSystemNotificationManagerDelegate, NIMChatManagerDelegate, XPAnchorCardViewDelegate>
2021-09-07 23:05:43 +08:00
@property (nonatomic, strong) MainPresenter *presenter;
///
@property (nonatomic,strong) XPMiniRoomView *roomMineView;
///
@property (nonatomic,copy) NSString *inviteCode;
2022-07-28 11:56:59 +08:00
///
@property (nonatomic, assign) BOOL needShowNewUserRecharge;
2022-08-01 19:24:12 +08:00
///(
@property (nonatomic, assign) BOOL needShowAnchorCard;
///
@property (nonatomic, assign) BOOL delayShowAnchorCard;
///
@property (nonatomic, strong) XPAnchorCardView *anchorCardView;
2022-08-02 18:13:51 +08:00
///
@property (nonatomic, strong) XPTaskCompleteTipView *taskTipView;
///
@property (nonatomic,weak) id<RoomHostDelegate>delegate;
2022-07-28 11:56:59 +08:00
2021-09-07 23:05:43 +08:00
@end
@implementation TabbarViewController
- (void)viewDidLoad {
[super viewDidLoad];
2021-09-07 23:05:43 +08:00
[self configTheme];
[self initTabs:NO];
2021-12-11 16:15:40 +08:00
[[ClientConfig shareConfig] clientInit];
[[NIMSDK sharedSDK].loginManager addDelegate:self];
[[NIMSDK sharedSDK].chatManager addDelegate:self];
[[NIMSDK sharedSDK].systemNotificationManager addDelegate:self];
2021-11-01 17:17:56 +08:00
[self.presenter juliandAdCallBackApi];
[self.view addSubview:self.roomMineView];
[[NSNotificationCenter defaultCenter] addObserverForName:kRoomMiniNotificationKey object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
[self configRoomMiniNView:note.userInfo];
}];
2022-06-02 18:53:45 +08:00
[[NSNotificationCenter defaultCenter] addObserverForName:kUserCompleteInfoFinishKey object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
[self completeUserInfoFinish:note.object];
}];
2022-07-28 11:56:59 +08:00
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showNewUserRecharge) name:kNewUserRechargeKey object:nil];
2022-08-01 19:24:12 +08:00
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showAnchorCardKey:) name:kTabShowAnchorCardKey object:nil];
2021-09-07 23:05:43 +08:00
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.presenter autoLogin];
if ([XPRoomMiniManager shareManager].getRoomInfo == nil) {
[self.roomMineView hiddenRoomMiniView];
}
2021-09-07 23:05:43 +08:00
}
2022-08-01 19:24:12 +08:00
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.delayShowAnchorCard = NO;
[self.anchorCardView removeFromSuperview];
self.anchorCardView = nil;
2022-08-01 19:24:12 +08:00
}
2022-07-28 11:56:59 +08:00
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (self.needShowNewUserRecharge) {
self.needShowNewUserRecharge = NO;
XPNewUserRechargeViewController *vc = [[XPNewUserRechargeViewController alloc] initWithNavigation:self.selectedViewController.navigationController];
2022-08-03 15:57:14 +08:00
vc.hadAnimate = YES;
2022-07-28 11:56:59 +08:00
[self.selectedViewController.navigationController presentViewController:vc animated:YES completion:nil];
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventNugiftPopShow];
2022-07-28 11:56:59 +08:00
}
2022-08-04 11:42:49 +08:00
if ([self hadLaunchApp] && [self canShowAnchorCard]) {
2022-08-01 19:24:12 +08:00
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.view.window && self.isViewLoaded) {
[self.presenter getAnchorCardInfo];
}
2022-08-01 19:24:12 +08:00
});
}
if (self.needShowAnchorCard && !self.delayShowAnchorCard) {
[self.presenter getAnchorCardInfo];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kHadLaunchApp];///
[[NSUserDefaults standardUserDefaults] synchronize];
}
2022-07-28 11:56:59 +08:00
}
2021-09-07 23:05:43 +08:00
- (MainPresenter *)presenter {
if (_presenter == nil) {
_presenter = [[MainPresenter alloc] init];
[_presenter attatchView:self];
}
return _presenter;
}
/** tokenticket
1.
2.
3. VP
*/
- (void)autoLoginSuccess {
[self.presenter loginNIM];
[self.presenter getUserInfo];
///
[self.presenter checkTranscation];
if (self.inviteCode && self.inviteCode.length > 0) {
///
[self.presenter checkInviteUserInfo:self.inviteCode];
}
}
/// 12
/// ticket
/// BaseMvpPresenter1415
- (void)getUserInfoSuccess:(UserInfoModel *)userInfo {
if (!userInfo.isBindPhone && [ClientConfig shareConfig].iosPhoneBind) {
2021-11-30 18:28:21 +08:00
LoginBindPhoneViewController * bindPhoneVC = [[LoginBindPhoneViewController alloc] init];
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:bindPhoneVC];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[self.navigationController presentViewController:nav animated:YES completion:nil];
return;
}
if (userInfo.nick == nil || userInfo.avatar == nil) {
[self completeUserInfo];
return;
}
[self initTabs:YES];
if (self.inviteCode.length <= 0) {
[self initQuickEnterRoom];
}
if (self.inviteCode) {
self.inviteCode = nil;
}
2021-12-07 11:08:43 +08:00
[self showTeenagerAlertView:userInfo];
2022-08-26 17:13:20 +08:00
[self monentsUnReadCount];
}
2022-06-02 18:53:45 +08:00
- (void)checkInviteUserInfoSuccess:(InviteUserInfoModel *)inviteInfo {
if (inviteInfo && inviteInfo.isInRoom) {
[XPRoomViewController openRoom:inviteInfo.roomUid fromNick:inviteInfo.inviteNick fromType:inviteInfo.fromType fromUid:inviteInfo.inviteUid viewController:self];
} else { //
///
[self.presenter getNewUserGreetInfo];
}
}
- (void)getNewUserGreetInfoSucces:(NewUserGreetModel *)greetInfo {
NSString * key = [NSString stringWithFormat:@"%@_%@", kUserFirstLoginKey, [AccountInfoStorage instance].getUid];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:key];
2022-06-02 18:53:45 +08:00
if (greetInfo.sayHello) {
XPNewUserGreetRoomAlertView * alertView = [[XPNewUserGreetRoomAlertView alloc] init];
alertView.greetInfo = greetInfo;
alertView.currentVC = self;
TTPopupService * config = [[TTPopupService alloc] init];
config.contentView = alertView;
config.shouldDismissOnBackgroundTouch = NO;
config.maskBackgroundAlpha = 0.8;
[TTPopup popupWithConfig:config];
} else {
[self.presenter getShortCutRecommendRoom];
}
}
- (void)getShortCutRecommendRoomSuccces:(NSString *)roomUid {
if (roomUid.length > 0) {
[XPRoomViewController openRoom:roomUid viewController:self];
}
}
#pragma mark - BaseMvpProtocol
2021-09-07 23:05:43 +08:00
- (void)tokenInvalid {
LoginViewController *lvc = [[LoginViewController alloc] init];
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:lvc];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[self.navigationController presentViewController:nav animated:YES completion:nil];
2021-09-07 23:05:43 +08:00
}
- (void)completeUserInfo {
LoginFullInfoViewController * bindPhoneVC = [[LoginFullInfoViewController alloc] init];
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:bindPhoneVC];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[self.navigationController presentViewController:nav animated:YES completion:nil];
2021-09-14 21:01:09 +08:00
}
2022-08-01 19:24:12 +08:00
///
- (void)getAnchorCardInfoSuccess:(XPTabAnchorCardModel *)cardInfo {
if (!self.anchorCardView.superview && cardInfo && self.isViewLoaded && self.view.window) {
self.anchorCardView.frame = CGRectMake(0, -90-kStatusBarHeight, KScreenWidth, 90);
[UIView animateWithDuration:0.5 animations:^{
self.anchorCardView.frame = CGRectMake(0, kStatusBarHeight, KScreenWidth, 90);
2022-08-04 11:42:49 +08:00
} completion:nil];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//
long time = (long)([[NSDate date] timeIntervalSince1970]*1000);
[[NSUserDefaults standardUserDefaults] setObject:@(time) forKey:kLastShowAnchorCardTime];
[[NSUserDefaults standardUserDefaults] synchronize];
2022-08-01 19:24:12 +08:00
self.anchorCardView.cardInfo = cardInfo;
[self.view addSubview:self.anchorCardView];
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleAnchorCardSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[self.anchorCardView addGestureRecognizer:recognizer];
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventPersonalshowTopCardShow];
2022-08-01 19:24:12 +08:00
}
}
#pragma mark - NIMLoginManagerDelegate
- (void)onAutoLoginFailed:(NSError *)error {
// autoLogin 417
if (error.code == 417) {
@weakify(self);
AccountModel* accountModel = [AccountInfoStorage instance].getCurrentAccountInfo;
[[NIMSDK sharedSDK].loginManager login:accountModel.uid token:accountModel.netEaseToken completion:^(NSError * _Nullable error) {
if (error) {
@strongify(self);
[self.presenter logout];
}
}];
return;
}
[self.presenter logout];
2021-09-07 23:05:43 +08:00
}
- (void)onKickout:(NIMLoginKickoutResult *)result {
[XCHUDTool showErrorWithMessage:@"您已被踢下线,若非正常行为,请及时修改密码"];
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
if ([rootViewController presentedViewController]) { //present dismiss
[[rootViewController presentedViewController] dismissViewControllerAnimated:YES completion:^{
if ([[XCCurrentVCStackManager shareManager] getCurrentVC].navigationController.viewControllers.count > 1) {
[[[XCCurrentVCStackManager shareManager] getCurrentVC].navigationController popToRootViewControllerAnimated:YES];
}
if ([[UIApplication sharedApplication].delegate.window.rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tabVC = (UITabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
if (tabVC.selectedViewController.navigationController) {
[tabVC.selectedViewController.navigationController popToRootViewControllerAnimated:YES];
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[tabVC setSelectedIndex:0];
});
}
}];
}else { //present rootvcpush navvc pop
if ([[XCCurrentVCStackManager shareManager] getCurrentVC].navigationController.viewControllers.count > 1) {
[[[XCCurrentVCStackManager shareManager] getCurrentVC].navigationController popToRootViewControllerAnimated:YES];
}
if ([[UIApplication sharedApplication].delegate.window.rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tabVC = (UITabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
if (tabVC.selectedViewController) {
if ([tabVC.selectedViewController isKindOfClass:[UINavigationController class]]) {
[tabVC.selectedViewController popToRootViewControllerAnimated:YES];
} else {
[tabVC.selectedViewController.navigationController popToRootViewControllerAnimated:YES];
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[tabVC setSelectedIndex:0];
});
}
}
}
if ([XPRoomMiniManager shareManager].getRoomInfo) {
[[RtcManager instance] exitRoom];
[[NIMSDK sharedSDK].chatroomManager exitChatroom:[NSString stringWithFormat:@"%ld", [XPRoomMiniManager shareManager].getRoomInfo.roomId] completion:nil];
[self.roomMineView hiddenRoomMiniView];
}
[self.presenter logout];
2021-10-21 12:01:21 +08:00
}
#pragma mark - NIMChatManagerDelegate
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
for (NIMMessage * message in messages) {
if (message.session.sessionType == NIMSessionTypeP2P) {
if(message.messageType == NIMMessageTypeCustom) {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel * attachment = obj.attachment;
if (attachment.first == CustomMessageType_FindNew && attachment.second == Custom_Message_Find_New_Greet_New_User) {
FindNewGreetMessageModel * greetInfo = [FindNewGreetMessageModel modelWithDictionary:attachment.data];
if (greetInfo.uid.integerValue != [AccountInfoStorage instance].getUid.integerValue) {
[TTPopup dismiss];
XPSessionFindNewAlertView * alertView = [[XPSessionFindNewAlertView alloc] init];
alertView.userInfo = greetInfo;
TTPopupService *service = [[TTPopupService alloc] init];
service.contentView = alertView;
service.shouldDismissOnBackgroundTouch = NO;
service.style = TTPopupStyleAlert;
[TTPopup popupWithConfig:service];
}
} else if (attachment.first == CustomMessageType_RedPacket && attachment.second == Custom_Message_Sub_AllDiamandRedPacket) {
XPReceiveRedPacketModel *data = [XPReceiveRedPacketModel modelWithDictionary:attachment.data];
2022-09-02 18:59:36 +08:00
//
__block BOOL isInRoom;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[XPRoomViewController class]]) {
XPRoomViewController<RoomHostDelegate> * roomVC = obj;
RoomInfoModel *roomInfo = [roomVC getRoomInfo];
XPReceiveRedPacketView *view = [[XPReceiveRedPacketView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
if (roomInfo.uid == data.roomUid.integerValue) {
view.inAllPacketRoom = YES;
} else {
view.inAllPacketRoom = NO;
}
XPReceiveRedPacketModel *data = [XPReceiveRedPacketModel modelWithJSON:attachment.data];
view.redPacketModel = data;
2022-09-27 16:51:18 +08:00
for (UIView *subView in roomVC.view.subviews) {
if([subView isKindOfClass:[XPReceiveRedPacketView class]]) {
view.alphaView.backgroundColor = [UIColor clearColor];
break;
}
}
[roomVC.view addSubview:view];
[roomVC.view bringSubviewToFront:view];
*stop = YES;
isInRoom = YES;
}
}];
if (!isInRoom) {
UIViewController *currentVc = [[XCCurrentVCStackManager shareManager] getCurrentVC];
XPReceiveRedPacketView *view = [[XPReceiveRedPacketView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
view.inAllPacketRoom = NO;
XPReceiveRedPacketModel *data = [XPReceiveRedPacketModel modelWithJSON:attachment.data];
view.redPacketModel = data;
2022-09-27 16:51:18 +08:00
for (UIView *subView in currentVc.view.subviews) {
if([subView isKindOfClass:[XPReceiveRedPacketView class]]) {
view.alphaView.backgroundColor = [UIColor clearColor];
break;
}
}
[currentVc.view addSubview:view];
[currentVc.view bringSubviewToFront:view];
2022-09-02 18:59:36 +08:00
}
}
}
}
}
}
}
2021-09-07 23:05:43 +08:00
- (void)configTheme {
2021-12-17 19:31:26 +08:00
self.view.backgroundColor = [ThemeColor tabbarViewColor];
[[UITabBar appearance] setBackgroundImage:[UIImage imageWithColor:[ThemeColor tabbarViewColor] size:CGSizeMake(KScreenWidth, kTabBarHeight)]];
2021-09-07 23:05:43 +08:00
[[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
if (@available(iOS 10.0, *)) {
[[UITabBar appearance] setUnselectedItemTintColor:[ThemeColor tabbarNormalColor]];
2021-09-07 23:05:43 +08:00
}
}
- (void)initTabs:(BOOL)logined {
2022-04-26 10:16:50 +08:00
self.viewControllers = nil;
2022-05-13 11:32:35 +08:00
NSArray *normalImageNames = @[@"tab_gameHome_normal",@"tab_monents_normal",@"tab_message_normal", @"tab_mine_normal"];
NSArray *selectImageNames = @[@"tab_gameHome_selected",@"tab_monents_select",@"tab_message_selected", @"tab_mine_selected"];
NSArray *tabLabel = @[@"派对",@"广场",@"消息", @"我的"];
2021-09-07 23:05:43 +08:00
UIViewController *game;
2021-11-26 20:25:23 +08:00
UIViewController *msg;
UIViewController *me;
2021-11-29 21:40:11 +08:00
UIViewController * home;
2022-05-13 11:32:35 +08:00
UIViewController * monents;
if (logined) {
XplanFBFlutterViewContainer *fvcGame = XplanFBFlutterViewContainer.new;
#ifdef DEBUG
[fvcGame setName:@"debug" uniqueId:nil params:nil];
#else
[fvcGame setName:@"/" uniqueId:nil params:nil];
#endif
2021-11-26 20:25:23 +08:00
msg = [[SessionListViewController alloc] init];
me = [[XPMineViewController alloc] init];
2021-11-29 21:40:11 +08:00
2022-02-21 20:06:09 +08:00
home = [[XPHomeViewController alloc] init];
2022-05-19 10:39:04 +08:00
monents = [[XPMonentsViewController alloc] init];
} else {
game = [[BaseViewController alloc]init];
msg = [[SessionListViewController alloc]init];
me = [[BaseViewController alloc]init];
2021-11-29 21:40:11 +08:00
home = [[BaseViewController alloc] init];
2022-05-13 11:32:35 +08:00
monents = [[BaseViewController alloc] init];
}
2021-11-29 21:40:11 +08:00
[self createTabBarItem:home title:tabLabel[0] image:normalImageNames[0] selectedImage:selectImageNames[0]];
2022-05-13 11:32:35 +08:00
[self createTabBarItem:monents title:tabLabel[1] image:normalImageNames[1] selectedImage:selectImageNames[1]];
2021-11-29 21:40:11 +08:00
[self createTabBarItem:msg title:tabLabel[2] image:normalImageNames[2] selectedImage:selectImageNames[2]];
[self createTabBarItem:me title:tabLabel[3] image:normalImageNames[3] selectedImage:selectImageNames[3]];
2022-05-13 11:32:35 +08:00
self.viewControllers = @[home,monents,msg,me];
2021-09-18 16:04:50 +08:00
self.selectedIndex = 0;
2021-09-07 23:05:43 +08:00
}
2021-09-16 17:21:52 +08:00
- (BaseNavigationController *)createTabBarItem:(UIViewController *)itemVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
2021-09-07 23:05:43 +08:00
itemVc.title = title;
itemVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
itemVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
2022-09-22 14:08:26 +08:00
[itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[ThemeColor appMainColor]} forState:UIControlStateSelected];
[itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[ThemeColor secondTextColor]} forState:UIControlStateNormal];
2021-09-16 17:21:52 +08:00
BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:itemVc];
return nav;
2021-09-07 23:05:43 +08:00
}
2021-09-15 18:41:40 +08:00
- (void)showSuccessToast:(NSString *)msg {
[XCHUDTool showSuccessWithMessage:msg];
2021-09-15 18:41:40 +08:00
}
- (void)showErrorToast:(NSString *)msg {
[XCHUDTool showErrorWithMessage:msg];
2021-09-15 18:41:40 +08:00
}
- (void)showLoading {
[XCHUDTool showLoading];
2021-09-15 18:41:40 +08:00
}
- (void)hideHUD {
[XCHUDTool hideHUD];
2021-09-15 18:41:40 +08:00
}
2022-08-26 17:13:20 +08:00
#pragma mark -
- (void)monentsUnReadCount {
[Api monentsUnReadCount:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) {
MonentsUnReadModel * model = [MonentsUnReadModel modelWithDictionary:data.data];
NSString *badge = model.total > 0 ? @(model.total).stringValue : nil;
if (model.total > 99) {
badge = @"99+";
}
NSUInteger index = 1;
UITabBarItem *item = self.tabBar.items.count > index ? self.tabBar.items[index] : nil;
[item setBadgeValue:badge];
}
} uid:[AccountInfoStorage instance].getUid];
}
#pragma mark -
- (void)configRoomMiniNView:(NSDictionary *)dic {
UserInfoModel * userInfo = [UserInfoModel modelWithDictionary:dic[@"userInfo"]];
RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:dic[@"roomInfo"]];
NSMutableDictionary * microQueue = dic[@"microQueue"];
[self.roomMineView configRoomMiniView:roomInfo userInfo:userInfo micQueue:microQueue];
2021-12-03 17:07:21 +08:00
}
2021-12-07 11:08:43 +08:00
#pragma mark -
- (void)showTeenagerAlertView:(UserInfoModel *)userInfo {
if (!userInfo || userInfo.uid <=0) return; ///
if (userInfo.parentMode) return;//
NSString * teenagerKey = [NSString stringWithFormat:@"%@_%ld", kTeenagerAlertDatekey, userInfo.uid];
NSDate * oldDate = [[NSUserDefaults standardUserDefaults] objectForKey:teenagerKey];
BOOL isSameDay = [[NSCalendar currentCalendar] isDateInToday:oldDate];
if (isSameDay) return;
2021-12-08 17:29:00 +08:00
XPTeenagerAlertView * teenagerView = [[XPTeenagerAlertView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth - 45 * 2, 260)];
2021-12-07 11:08:43 +08:00
teenagerView.controller = self;
[TTPopup popupView:teenagerView style:TTPopupStyleAlert];
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:teenagerKey];
}
2022-06-02 18:53:45 +08:00
#pragma mark -
- (void)initQuickEnterRoom {
NSString * key = [NSString stringWithFormat:@"%@_%@", kUserFirstLoginKey, [AccountInfoStorage instance].getUid];
BOOL isNotFirstLogin = [[NSUserDefaults standardUserDefaults] boolForKey:key];
2022-06-02 18:53:45 +08:00
if (isNotFirstLogin) {
2022-06-17 10:26:34 +08:00
[self.presenter getShortCutRecommendRoom];
2022-06-02 18:53:45 +08:00
} else {
///
[self.presenter getNewUserGreetInfo];
}
}
/// linkedMe
- (void)completeUserInfoFinish:(NSString *)inviteCode {
self.inviteCode = inviteCode;
2022-06-02 18:53:45 +08:00
}
#pragma mark -NIMSystemNotificationManagerDelegate
- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification {
if (notification.receiverType == NIMSessionTypeP2P) {
if (notification.content != nil) {
NSData *jsonData = [notification.content dataUsingEncoding:NSUTF8StringEncoding];
NSError *err;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
if(err) {
NSLog(@"json解析失败%@",err);
return;
}
if ([dic[@"first"] intValue] == CustomMessageType_Noble_VIP && [dic[@"second"] intValue] == Custom_Message_Sub_Noble_LevelUp_User) { //
if ([dic isKindOfClass:[NSDictionary class]]) {
[self receiveNobleLevelUp:dic];
}
} else if ([dic[@"first"] integerValue] == CustomMessageType_First_VisitorRecord){//访
AttachmentModel *attachment = [AttachmentModel modelWithJSON:notification.content];
XPMineVisitorUnReadModel *model = [XPMineVisitorUnReadModel modelWithJSON:attachment.data];
if ([model isKindOfClass:XPMineVisitorUnReadModel.class]) {
[[NSNotificationCenter defaultCenter] postNotificationName:kVisitorUnReadCountNotificationKey object:model];
}
2022-08-02 18:13:51 +08:00
} else if ([dic[@"first"] intValue] == CustomMessageType_First_Recharge_Reward && [dic[@"second"] intValue] == Custom_Message_Sub_New_User_Recharge_Reward) { //
if ([dic isKindOfClass:[NSDictionary class]]) {
FirstRechargeModel *model = [FirstRechargeModel modelWithDictionary:dic[@"data"]];
XPNewUserRechargeSucessView * firstRechargeView= [[XPNewUserRechargeSucessView alloc] init];
firstRechargeView.rechargeInfo = model;
[TTPopup popupView:firstRechargeView style:TTPopupStyleAlert];
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventnugift_pop_finish_click eventAttributes:@{@"buy_level" : [NSString stringWithFormat:@"%zd", model.chargeMoney]}];
2022-08-02 18:13:51 +08:00
}
} else if ([dic[@"first"] intValue] == CustomMessageType_Task_Complete && [dic[@"second"] intValue] == Custom_Message_Sub_TaskComplete) {///
if ([dic isKindOfClass:[NSDictionary class]]) {
NSDictionary *dict = dic[@"data"];
[self handleActivityTaskTip:dict[@"taskCompleteMsg"] url:dic[@"taskUrl"]];
}
}
}
}
}
- (void)receiveNobleLevelUp:(NSDictionary *)data {
XPNobleUpgradeLevelView *view = [[XPNobleUpgradeLevelView alloc] initWithFrame:CGRectMake(0, 0, 300, 285 + 22 + 44)];
NobleLevelUpModel *receiveInfo = [NobleLevelUpModel modelWithDictionary:data[@"data"]];
view.levelUpInfo = receiveInfo;
[TTPopup popupView:view style:TTPopupStyleAlert];
}
2022-08-01 19:24:12 +08:00
#pragma mark -
//
- (void)showNewUserRecharge {
self.needShowNewUserRecharge = YES;
}
///
- (void)showAnchorCardKey:(NSNotification *)noti {
NSDictionary * dic = noti.object;
self.delayShowAnchorCard = [[dic objectForKey:@"delayShow"] boolValue];
self.needShowAnchorCard = YES;
}
///
- (BOOL)hadLaunchApp {
return [[NSUserDefaults standardUserDefaults] valueForKey:kHadLaunchApp];
}
- (BOOL)canShowAnchorCard {
if ([[XPRoomMiniManager shareManager] getRoomInfo]) {//
return NO;
}
2022-08-01 19:24:12 +08:00
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber *lastTime = [defaults objectForKey:kLastShowAnchorCardTime];
if ([lastTime longValue] < 1) {
return NO;
}
NSDate *datenow = [NSDate date];//
long time2 = (long)([datenow timeIntervalSince1970]*1000);
long aTime = (time2 - [lastTime longValue]) / 1000;
if (aTime > 15*60) {
return YES;
} else {
return NO;
2022-08-01 19:24:12 +08:00
}
}
2022-08-02 18:13:51 +08:00
#pragma mark -
- (void)handleActivityTaskTip:(NSString *)msg url:(NSString *)url {
if (!self.taskTipView.superview && url.length) {
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventtask_toast_show];
2022-08-02 18:13:51 +08:00
[self.view addSubview:self.taskTipView];
self.taskTipView.desc = msg;
self.taskTipView.url = url;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(jumpToTask:)];
[self.taskTipView addGestureRecognizer:tap];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.taskTipView.superview) {
[self.taskTipView removeFromSuperview];
}
self.taskTipView = nil;
});
}
}
- (void)jumpToTask:(UITapGestureRecognizer *)ges {
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventtask_toast_click];
2022-08-02 18:13:51 +08:00
XPWebViewController * webVC =[[XPWebViewController alloc] init];
webVC.url = self.taskTipView.url;
[self.selectedViewController.navigationController pushViewController:webVC animated:YES];
if (self.taskTipView.superview) {
[self.taskTipView removeFromSuperview];
}
self.taskTipView = nil;
}
2022-08-01 19:24:12 +08:00
#pragma mark - XPAnchorCardViewDelegate
- (void)xPAnchorCardViewEnterRoom:(NSString *)roomUid {
2022-08-05 18:08:26 +08:00
if (roomUid.length) {
2022-08-01 19:24:12 +08:00
[self.anchorCardView removeFromSuperview];
self.anchorCardView = nil;
self.needShowAnchorCard = NO;
[XPRoomViewController openRoom:roomUid viewController:self];
} else {
[UIView animateWithDuration:0.5 animations:^{
self.anchorCardView.frame = CGRectMake(0, -90-kStatusBarHeight, KScreenWidth, 90);
} completion:^(BOOL finished) {
[self.anchorCardView removeFromSuperview];
self.anchorCardView = nil;
self.needShowAnchorCard = NO;
}];
}
}
- (void)xPAnchorCardViewClickAvatar:(NSString *)uid {
if (uid.length) {
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
userInfoVC.uid = uid.integerValue;
[self.selectedViewController.navigationController pushViewController:userInfoVC animated:YES];
[self.anchorCardView removeFromSuperview];
self.anchorCardView = nil;
self.needShowAnchorCard = NO;
} else {
[self.anchorCardView removeFromSuperview];
self.anchorCardView = nil;
self.needShowAnchorCard = NO;
}
}
2022-08-01 19:24:12 +08:00
- (void)handleAnchorCardSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
if(recognizer.direction == UISwipeGestureRecognizerDirectionUp) {
[UIView animateWithDuration:0.5 animations:^{
self.anchorCardView.frame = CGRectMake(0, -90-kStatusBarHeight, KScreenWidth, 90);
} completion:^(BOOL finished) {
[self.anchorCardView removeFromSuperview];
self.anchorCardView = nil;
self.needShowAnchorCard = NO;
}];
}
}
#pragma mark - Getters And Setters
- (XPMiniRoomView *)roomMineView {
if (!_roomMineView) {
_roomMineView = [[XPMiniRoomView alloc] init];
_roomMineView.controller = self;
_roomMineView.hidden = YES;
}
return _roomMineView;
}
2022-08-01 19:24:12 +08:00
- (XPAnchorCardView *)anchorCardView {
if (!_anchorCardView) {
_anchorCardView = [[XPAnchorCardView alloc] init];
_anchorCardView.delegate = self;
}
return _anchorCardView;
}
2022-08-02 18:13:51 +08:00
- (XPTaskCompleteTipView *)taskTipView {
if (!_taskTipView) {
_taskTipView = [[XPTaskCompleteTipView alloc] initWithFrame:CGRectMake(0, KScreenHeight - kSafeAreaBottomHeight-60-20, KScreenWidth, 20)];
}
return _taskTipView;
}
2021-09-07 23:05:43 +08:00
@end