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

1051 lines
45 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>
2023-08-24 17:03:32 +08:00
#import <AudioToolbox/AudioToolbox.h>
///Third
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>
2022-12-27 10:48:47 +08:00
#import <AFNetworkReachabilityManager.h>
2022-12-10 12:07:35 +08:00
#import <POP.h>
#import <QYSDK_NIM/QYSDK.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"
2022-10-31 12:15:01 +08:00
#import "XPAdImageTool.h"
2022-12-15 18:48:35 +08:00
#import "YYUtility.h"
#import "NSMutableDictionary+Saft.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"
2022-12-10 12:07:35 +08:00
#import "XPRoomGiftBroadCastModel.h"
2022-12-05 18:56:02 +08:00
#import "XPVersionUpdateModel.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 19:30:22 +08:00
#import "XPMineViewController.h"
2021-11-26 20:25:23 +08:00
#import "SessionListViewController.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"
2022-12-10 12:07:35 +08:00
#import "XPRoomYearActivityView.h"
2022-12-05 18:56:02 +08:00
#import "XPUpgradeView.h"
2023-12-21 18:42:16 +08:00
#import "MewMainHomeViewController.h"
2023-03-06 20:34:42 +08:00
#import "XPNewMomentsViewController.h"
#import "XPPartyViewController.h"
2023-03-08 18:52:49 +08:00
#import "XPMessageViewController.h"
2023-08-24 17:03:32 +08:00
#import "XPRoomGameInviteBannerView.h"
#import "SessionViewController.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-12-27 10:48:47 +08:00
NSString * const kNetworkReachabilityKey = @"kNetworkReachabilityKey";
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
2023-08-25 14:48:58 +08:00
@interface TabbarViewController () <BaseMvpProtocol, MainProtocol, NIMLoginManagerDelegate, NIMSystemNotificationManagerDelegate, NIMChatManagerDelegate, XPAnchorCardViewDelegate, NIMBroadcastManagerDelegate, XPRoomYearActivityViewDelegate,XPRoomGameInviteBannerViewDelegate>
2021-09-07 23:05:43 +08:00
2023-03-21 17:59:16 +08:00
/// 线
@property (nonatomic, strong) UIView *lineView;
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-12-10 12:07:35 +08:00
///广
@property (nonatomic,strong) NSMutableArray<XPRoomGiftBroadCastModel *> *giftBroadcastQueue;
2022-09-27 15:07:31 +08:00
///
@property (nonatomic, assign) BOOL parentMode;
///
@property (nonatomic,assign) BOOL isFirstReachability;
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];
[[NIMSDK sharedSDK].broadcastManager addDelegate:self];
2021-11-01 17:17:56 +08:00
[self.presenter juliandAdCallBackApi];
2022-12-27 10:48:47 +08:00
[self networkReachability];
[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];
2022-09-27 15:07:31 +08:00
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(teenagerStatusChange:) name:kTeenagerStatusChange object:nil];
2022-12-15 18:48:35 +08:00
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];
2022-09-27 15:07:31 +08:00
if (self.needShowNewUserRecharge && !self.parentMode) {
2022-07-28 11:56:59 +08:00
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
}
}
2023-03-21 17:59:16 +08:00
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.lineView.frame = CGRectMake(0, 0, self.tabBar.frame.size.width, 1);
}
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];
2022-12-27 14:36:11 +08:00
///
[self.presenter getVersionUpdate];
2023-03-16 21:04:03 +08:00
///
[[ClientConfig shareConfig] addHeartBratTimer];
if (self.inviteCode && self.inviteCode.length > 0) {
///
[self.presenter checkInviteUserInfo:self.inviteCode];
}
2022-10-31 12:15:01 +08:00
XPAdImageTool.shareImageTool.isImLogin = YES;
if ([self hadLaunchApp] && [self canShowAnchorCard]) {
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];
}
});
}
if (self.needShowAnchorCard && !self.delayShowAnchorCard && !self.parentMode) {
[self.presenter getAnchorCardInfo];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kHadLaunchApp];///
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
/// 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-09-27 15:07:31 +08:00
self.parentMode = userInfo.parentMode;
for (BaseViewController *vc in self.viewControllers) {
vc.parentMode = self.parentMode;
}
NSLog(@"登录陈宫");
NSString * uid = [AccountInfoStorage instance].getUid;
2023-04-14 11:07:42 +08:00
QYUserInfo * userinfo = [[QYUserInfo alloc] init];
userinfo.userId = uid;
NSMutableArray * array = [NSMutableArray array];
NSMutableDictionary * nickDic = [NSMutableDictionary dictionary];
[nickDic safeSetObject:@"real_name" forKey:@"key"];
[nickDic safeSetObject:userInfo.nick forKey:@"value"];
NSMutableDictionary * phoneDic = [NSMutableDictionary dictionary];
[phoneDic safeSetObject:@"mobile_phone" forKey:@"key"];
[phoneDic safeSetObject:userInfo.phone?:@"" forKey:@"value"];
NSMutableDictionary * accountDic = [NSMutableDictionary dictionary];
[accountDic safeSetObject:@"0" forKey:@"index"];
[accountDic safeSetObject:@"account" forKey:@"key"];
[accountDic safeSetObject:@"ID" forKey:@"label"];
[accountDic safeSetObject:@(userInfo.erbanNo) forKey:@"value"];
NSMutableDictionary * genderDic = [NSMutableDictionary dictionary];
[genderDic safeSetObject:@"1" forKey:@"index"];
[genderDic safeSetObject:@"sex" forKey:@"key"];
[genderDic safeSetObject:@"性别" forKey:@"label"];
[genderDic safeSetObject:userInfo.gender == GenderType_Male ? @"男" : @"女" forKey:@"value"];
[array addObject:nickDic];
[array addObject:phoneDic];
[array addObject:accountDic];
[array addObject:genderDic];
userinfo.data = array.toJSONString;
[[QYSDK sharedSDK] setUserInfo:userinfo];
}
2022-06-02 18:53:45 +08:00
- (void)checkInviteUserInfoSuccess:(InviteUserInfoModel *)inviteInfo {
2022-09-27 15:07:31 +08:00
if (inviteInfo && inviteInfo.isInRoom && !self.parentMode) {
2022-06-02 18:53:45 +08:00
[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.maskBackgroundAlpha = 0.8;
[TTPopup popupWithConfig:config];
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRoom_sayhi_pop_show eventAttributes:@{@"uid":greetInfo.roomUid}];
2022-06-02 18:53:45 +08:00
} else {
[self.presenter getShortCutRecommendRoom];
}
}
- (void)getShortCutRecommendRoomSuccces:(NSString *)roomUid {
2022-09-27 15:07:31 +08:00
if (self.parentMode) {
return;
}
2022-06-02 18:53:45 +08:00
if (roomUid.length > 0) {
[XPRoomViewController openRoom:roomUid viewController:self];
}
}
2022-12-27 10:48:47 +08:00
#pragma mark -
- (void)networkReachability{
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown:
self.isFirstReachability = YES;
2022-12-27 10:48:47 +08:00
break;
case AFNetworkReachabilityStatusNotReachable:
self.isFirstReachability = YES;
2022-12-27 10:48:47 +08:00
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
case AFNetworkReachabilityStatusReachableViaWiFi:
{
if (self.isFirstReachability) {
[[NSNotificationCenter defaultCenter] postNotificationName:kNetworkReachabilityKey object:nil userInfo:nil];
[self.presenter autoLogin];
[[ClientConfig shareConfig] clientInit];
}
self.isFirstReachability = YES;
2022-12-27 10:48:47 +08:00
}
break;
default:
break;
}
}];
}
#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];
2022-10-31 12:15:01 +08:00
XPAdImageTool.shareImageTool.isImLogin = NO;
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 {
2022-09-27 15:07:31 +08:00
if (self.parentMode) {
return;
}
2022-08-01 19:24:12 +08:00
if (!self.anchorCardView.superview && cardInfo && self.isViewLoaded && self.view.window) {
self.anchorCardView.frame = CGRectMake(0, -90-kStatusBarHeight, KScreenWidth, 90);
2023-03-08 19:23:32 +08:00
[UIView animateWithDuration:0.25 animations:^{
2022-08-01 19:24:12 +08:00
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
}
}
2022-12-05 18:56:02 +08:00
///
- (void)getVersionUpdate:(XPVersionUpdateModel *)versionModel {
2022-12-15 18:48:35 +08:00
XPUpgradeView *view = [[XPUpgradeView alloc] init];
view.versionModel = versionModel;
TTPopupService * service = [[TTPopupService alloc] init];
service.contentView = view;
service.shouldDismissOnBackgroundTouch = NO;
[TTPopup popupWithConfig:service];
2022-12-05 18:56:02 +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)onLogin:(NIMLoginStep)step {
if (step == NIMLoginStepLoginOK) {
[self addMessageBadge];
}
}
- (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 {
2022-09-27 15:07:31 +08:00
if (self.parentMode) {
return;
}
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];
}
2022-09-02 18:59:36 +08:00
}
}
}
2022-08-01 14:21:27 +08:00
}
if (message.messageType == NIMMessageTypeCustom) {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if (obj.attachment != nil && [obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel *attachment = (AttachmentModel *)obj.attachment;
if (attachment.first == CustomMessageType_First_Recharge_Reward && attachment.second == Custom_Message_Sub_New_User_Recharge_Reward) {
FirstRechargeModel *model = [FirstRechargeModel modelWithJSON:attachment.data];
XPNewUserRechargeSucessView * firstRechargeView= [[XPNewUserRechargeSucessView alloc] init];
firstRechargeView.rechargeInfo = model;
[TTPopup popupView:firstRechargeView style:TTPopupStyleAlert];
2023-08-25 14:48:58 +08:00
}else if(attachment.first == CustomMessageType_Initiat_Invitation && attachment.second == Custom_Message_Sub_Initiat_Invitation_Initiating_User){
UserGameInfoVo *gameInfo = [UserGameInfoVo modelWithDictionary:attachment.data];
[self showGameVeiwWithGameInfo:gameInfo];
2022-08-01 14:21:27 +08:00
}
}
}
}
}
- (void)onReceiveBroadcastMessage:(NIMBroadcastMessage *)broadcastMessage {
if (broadcastMessage.content) {
NSDictionary *msgDictionary = [broadcastMessage.content toJSONObject];
AttachmentModel *attachment = [AttachmentModel modelWithJSON:msgDictionary[@"body"]];
if (attachment.first == CustomMessageType_RedPacket && attachment.second == Custom_Message_Sub_AllDiamandRedPacket) {
XPReceiveRedPacketModel *data = [XPReceiveRedPacketModel modelWithDictionary:attachment.data];
//
__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;
[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;
[currentVc.view addSubview:view];
[currentVc.view bringSubviewToFront:view];
}
2022-12-10 12:07:35 +08:00
} else if (attachment.first == CustomMessageType_Gift && attachment.second == Custom_Message_Sub_Gift_ChannelNotify){///广
[self receiveBroadcastGift:attachment];
2022-12-15 18:48:35 +08:00
}else if(attachment.first == CustomMessageType_Version_Update && attachment.second == Custom_Message_Version_Update_Value){
NSString *osValue = attachment.data[@"updateOs"];
2022-12-27 14:36:11 +08:00
if([osValue isEqualToString:@"ios"] && [AccountInfoStorage instance].getUid.length > 0){
2022-12-15 18:48:35 +08:00
XPVersionUpdateModel *updateModel = [XPVersionUpdateModel modelWithDictionary:attachment.data];
[self getVersionUpdate:updateModel];
}
2023-08-24 17:03:32 +08:00
}
}
}
2023-08-24 17:03:32 +08:00
-(void)showGameVeiwWithGameInfo:(UserGameInfoVo *)gameInfo{
__block BOOL isInChat = NO;
[self.getKeyWindowNav.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[SessionViewController class]]) {
2023-08-25 14:48:58 +08:00
SessionViewController *chatVC = (SessionViewController *)obj;
2023-08-31 17:50:20 +08:00
if([gameInfo.fromUid isEqualToString:chatVC.session.sessionId]){
2023-08-25 14:48:58 +08:00
isInChat = YES;
}
2023-08-24 17:03:32 +08:00
*stop = YES;
}
}];
if(isInChat == YES)return;
2023-08-25 14:48:58 +08:00
if([gameInfo.fromUid isEqualToString:[AccountInfoStorage instance].getUid]){
return;
}
2023-08-24 17:03:32 +08:00
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
XPRoomGameInviteBannerView *gameView = [[XPRoomGameInviteBannerView alloc]initWithFrame:CGRectMake(0, -kGetScaleWidth(92), KScreenWidth, kGetScaleWidth(92))];
gameView.gameInfo = gameInfo;
[kWindow addSubview:gameView];
2023-08-25 14:48:58 +08:00
gameView.delegate = self;
[UIView animateWithDuration:0.5 animations:^{
UIWindow *window = UIApplication.sharedApplication.windows.firstObject;
CGFloat topPadding = window.safeAreaInsets.top;
gameView.frame = CGRectMake(0, topPadding + 15, KScreenWidth, kGetScaleWidth(92));
}completion:^(BOOL finished) {
[gameView show];
2023-08-24 17:03:32 +08:00
}];
}
2023-08-25 14:48:58 +08:00
#pragma mark - XPRoomGameInviteBannerViewDelegate
-(void)sendGameInviteMessageWithGameInfo:(UserGameInfoVo *)gameInfo{
2023-08-28 18:55:29 +08:00
2023-08-25 14:48:58 +08:00
NSString * sessionId = [NSString stringWithFormat:@"%@",gameInfo.fromUid];
NIMSession * session = [NIMSession session:sessionId type:NIMSessionTypeP2P];
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
2023-08-28 18:55:29 +08:00
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:sessionVC animated:YES];
2023-08-25 14:48:58 +08:00
}
2023-08-24 17:03:32 +08:00
- (UINavigationController *)getKeyWindowNav {
if ([XCCurrentVCStackManager shareManager].getCurrentVC) {
return [XCCurrentVCStackManager shareManager].getCurrentVC.navigationController;
}
return self.navigationController;
}
2021-09-07 23:05:43 +08:00
- (void)configTheme {
2023-03-21 17:59:16 +08:00
[self.tabBar addSubview:self.lineView];
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
}
}
2023-12-27 18:06:18 +08:00
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
if([item.title isEqualToString:@"首页"]){
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_bar_click eventAttributes:@{@"type" : @"首页"}];
}else if([item.title isEqualToString:@"广场"]){
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_bar_click eventAttributes:@{@"type" : @"广场"}];
}else if([item.title isEqualToString:@"消息"]){
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_bar_click eventAttributes:@{@"type" : @"消息"}];
}else{
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventRecent_homepage_bar_click eventAttributes:@{@"type" : @"我的"}];
}
}
2021-09-07 23:05:43 +08:00
- (void)initTabs:(BOOL)logined {
2022-04-26 10:16:50 +08:00
self.viewControllers = nil;
2023-12-26 14:34:26 +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
2023-12-26 14:34:26 +08:00
// UIViewController *party;
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) {
2023-03-08 18:52:49 +08:00
// msg = [[SessionListViewController alloc] init];
msg = [[XPMessageViewController alloc] init];
me = [[XPMineViewController alloc] init];
2023-12-26 14:34:26 +08:00
// party = [[XPPartyViewController alloc]init];
2023-12-21 18:42:16 +08:00
home = [[MewMainHomeViewController alloc] init];
2023-03-06 20:34:42 +08:00
// monents = [[XPMonentsViewController alloc] init];
monents = [[XPNewMomentsViewController alloc] init];
} else {
2023-12-26 14:34:26 +08:00
// party = [[BaseViewController alloc]init];
2023-03-08 18:52:49 +08:00
msg = [[XPMessageViewController 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]];
2023-12-26 14:34:26 +08:00
// [self createTabBarItem:party title:tabLabel[1] image:normalImageNames[1] selectedImage:selectImageNames[1]];
[self createTabBarItem:monents title:tabLabel[1] image:normalImageNames[1] selectedImage:selectImageNames[1]];
[self createTabBarItem:msg title:tabLabel[2] image:normalImageNames[2] selectedImage:selectImageNames[2]];
[self createTabBarItem:me title:tabLabel[3] image:normalImageNames[3] selectedImage:selectImageNames[3]];
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];
2023-03-06 18:55:01 +08:00
[itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[ThemeColor mainTextColor]} forState:UIControlStateSelected];
[itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[ThemeColor textThirdColor]} 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 = 2;
// UITabBarItem *item = self.tabBar.items.count > index ? self.tabBar.items[index] : nil;
// [item setBadgeValue:badge];
// }
2022-08-26 17:13:20 +08:00
} 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-12-10 14:57:23 +08:00
if (!isNotFirstLogin) {
2022-06-02 18:53:45 +08:00
///
[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 {
2022-09-27 15:07:31 +08:00
if (self.parentMode) {
return;
}
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 {
2022-09-27 15:07:31 +08:00
if (self.parentMode) {
return;
}
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];
}
- (void)addMessageBadge {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSArray * array = [NIMSDK sharedSDK].conversationManager.allRecentSessions;
__block int unreadCount = 0;
[array enumerateObjectsUsingBlock:^(NIMRecentSession * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (![[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:obj.session.sessionId]) {
if (obj.session.sessionId.integerValue > 0) {
unreadCount += obj.unreadCount;
}
}
}];
if (self.parentMode) {
unreadCount = 0;
}
if (unreadCount > 0) {
2023-12-26 14:34:26 +08:00
[self.tabBar.items[2] setBadgeValue:[NSString stringWithFormat:@"%d", unreadCount]];
} else {
2023-12-26 14:34:26 +08:00
[self.tabBar.items[2] setBadgeValue:nil];
}
});
}
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];
}
2022-09-27 15:07:31 +08:00
///
- (void)teenagerStatusChange:(NSNotification *)noti {
NSDictionary * dic = noti.object;
self.parentMode = [[dic objectForKey:@"parentMode"] boolValue];
for (BaseViewController *vc in self.viewControllers) {
vc.parentMode = self.parentMode;
}
2022-10-09 16:47:38 +08:00
if ([XPRoomMiniManager shareManager].getRoomInfo && self.parentMode) {
[[RtcManager instance] exitRoom];
[[NIMSDK sharedSDK].chatroomManager exitChatroom:[NSString stringWithFormat:@"%ld", [XPRoomMiniManager shareManager].getRoomInfo.roomId] completion:nil];
[self.roomMineView hiddenRoomMiniView];
}
2022-09-27 15:07:31 +08:00
}
- (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;
}];
}
}
2022-12-10 12:07:35 +08:00
#pragma mark -
- (void)receiveBroadcastGift:(AttachmentModel *)attachment {
XPRoomGiftBroadCastModel *giftNotifyInfo = [XPRoomGiftBroadCastModel modelWithJSON:attachment.data];
if (!giftNotifyInfo.ceremonyGift) {
return;
}
2022-12-10 12:07:35 +08:00
if (self.giftBroadcastQueue.count == 0) {
[self createGiftBroadcastViewAnimation:giftNotifyInfo];
}
[self.giftBroadcastQueue addObject:giftNotifyInfo];
}
- (void)createGiftBroadcastViewAnimation:(XPRoomGiftBroadCastModel *)giftModel {
XPRoomYearActivityView * view = [[XPRoomYearActivityView alloc] init];
view.delegate = self;
view.frame = CGRectMake(KScreenWidth, 35 + statusbarHeight, KScreenWidth, 150);
view.model = giftModel;
[[XCCurrentVCStackManager shareManager].getCurrentVC.view addSubview:view];
2022-12-10 12:07:35 +08:00
[self beginGiftBraodcastViewAnimation:view notifyStaySecond:giftModel.notifyStaySecond];
}
- (void)beginGiftBraodcastViewAnimation:(XPRoomYearActivityView *)view notifyStaySecond:(int)notifyStaySecond{
CGFloat startTime = notifyStaySecond > 0 ? notifyStaySecond : 3.0;
POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
springAnimation.springSpeed = 12;
springAnimation.springBounciness = 10.f;
springAnimation.fromValue = [NSValue valueWithCGPoint:view.center];
springAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(0 + view.frame.size.width / 2, view.center.y)];
[springAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
if (finished) {
[self removeGiftBroadcastOutAnimation:view stayTime:startTime];
}
}];
[view pop_addAnimation:springAnimation forKey:@"spingOutAnimation"];
}
- (void)removeGiftBroadcastOutAnimation:(XPRoomYearActivityView *)view stayTime:(CGFloat)stayTime{
POPBasicAnimation *moveAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewCenter];
moveAnimation.fromValue = [NSValue valueWithCGPoint:view.center];
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(-KScreenWidth/2, view.center.y)];
moveAnimation.beginTime = CACurrentMediaTime() + stayTime;
moveAnimation.duration = 0.5;
moveAnimation.repeatCount = 1;
moveAnimation.removedOnCompletion = YES;
@kWeakify(self);
[moveAnimation setCompletionBlock:^(POPAnimation *anim, BOOL finished) {
@kStrongify(self);
if (finished) {
[view removeFromSuperview];
if (self.giftBroadcastQueue.count > 0) {
[self.giftBroadcastQueue removeObjectAtIndex:0];
}
2022-12-10 12:07:35 +08:00
if (self.giftBroadcastQueue.count > 0) {
[self createGiftBroadcastViewAnimation:self.giftBroadcastQueue.firstObject];
}
}
}];
[view pop_addAnimation:moveAnimation forKey:@"moveOutAnimation"];
}
#pragma mark - XPRoomGiftBroadcastViewDelegate
- (void)xPRoomYearActivityViewEnterRoom:(NSString *)roomUid{
if (roomUid.length > 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[XPRoomViewController openRoom:roomUid viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
});
}
}
#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;
}
2022-12-10 12:07:35 +08:00
- (NSMutableArray<XPRoomGiftBroadCastModel *> *)giftBroadcastQueue {
if (!_giftBroadcastQueue) {
_giftBroadcastQueue = [NSMutableArray array];
}
return _giftBroadcastQueue;
}
2023-03-21 17:59:16 +08:00
- (UIView *)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [ThemeColor colorWithHexString:@"#F4F4F6"];
}
return _lineView;
}
2021-09-07 23:05:43 +08:00
@end