// // cloudPhoneViewController.m // Private-X // // Created by xd h on 2024/6/20. // #import "cloudPhoneViewController.h" #import "cloudPhoneSetView.h" #import "audioPlayingView.h" #import "DFPlayer.h" #import "audioPlayerViewController.h" #import "webRtcMsgModel.h" #import "webRtcPlayerViewController.h" @interface cloudPhoneViewController () @property (nonatomic,strong) cloudPhoneSetView *cloudPhoneSetV; @property (nonatomic,strong) webRtcMsgModel *webRtcMsgMod; @end @implementation cloudPhoneViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //输入密码完成 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didInpuPwdOkFun) name:didInputPWDNotification object:nil]; [self.view setBackgroundColor:HWF5F7FAColor]; [self.toolBar setHidden:YES]; [self.navigationBar setHidden:YES]; [self.navBarBGView setHidden:YES]; [self drawAnyView]; } - (void)drawAnyView{ //顶底底部图片 UIImageView *topImageV = [UIImageView new]; topImageV.userInteractionEnabled = YES; topImageV.image = [UIImage imageNamed:@"cloudPhone_bg"]; [self.view addSubview:topImageV]; [topImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; CGFloat width = SCREEN_W; CGFloat height = SCREEN_H; BOOL isSmallPhoneType = NO; if(width == 375 && height == 667){ isSmallPhoneType = YES; } CGFloat adjustSmallScale = 1.0; if(isSmallPhoneType){ adjustSmallScale = 0.9; } CGFloat imageTopY = 54.0; if(isSmallPhoneType){ imageTopY = 20.0; } //设置按钮 UIButton *setButton = [[UIButton alloc] init]; //[setButton setBackgroundImage:[UIImage imageNamed:@"cloudPhone_set"] forState:UIControlStateNormal]; [setButton setImage:[UIImage imageNamed:@"cloudPhone_set"] forState:UIControlStateNormal]; setButton.tag = 1; [setButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:setButton]; //setButton.backgroundColor = [UIColor greenColor]; [setButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(imageTopY); if(isSmallPhoneType){ make.right.mas_equalTo(-5); } else{ make.right.mas_equalTo(-16); } make.width.mas_equalTo(50); make.height.mas_equalTo(50); // make.top.mas_equalTo(imageTopY); // make.right.mas_equalTo(-16); // make.width.mas_equalTo(24); // make.height.mas_equalTo(24); }]; //中间图片 UIImageView *midImageV = [UIImageView new]; midImageV.userInteractionEnabled = YES; midImageV.image = [UIImage imageNamed:@"cloudPhone_mid_img"]; [self.view addSubview:midImageV]; [midImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(326*WAUTOSCALE*adjustSmallScale); make.height.mas_equalTo(608*WAUTOSCALE*adjustSmallScale); make.centerX.mas_equalTo(0); make.centerY.mas_equalTo(-10); }]; NSString *midTopTipImageStr = @"cloudPhone_topTip_img_cs"; //欢迎 //en-US 英文 ja-JP 日文 NSArray *arLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]; NSLog(@"arLanguages:%@",arLanguages); ///获取设备当前地区的代码和APP语言环境 NSString *languageCode = [NSLocale preferredLanguages][0]; //目前支持 中文(简体 繁体) 英文 日语 if([languageCode rangeOfString:@"zh-Hans"].location != NSNotFound) { midTopTipImageStr = @"cloudPhone_topTip_img_cs"; } else if([languageCode rangeOfString:@"zh-Hant"].location != NSNotFound) { midTopTipImageStr = @"cloudPhone_topTip_img_ct"; } else{ midTopTipImageStr = @"cloudPhone_topTip_img_en"; } //提示文字图片 UIImageView *midTopTipImageV = [UIImageView new]; midTopTipImageV.image = [UIImage imageNamed:midTopTipImageStr]; [midImageV addSubview:midTopTipImageV]; [midTopTipImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(282*WAUTOSCALE*adjustSmallScale); make.height.mas_equalTo(84*WAUTOSCALE*adjustSmallScale); make.centerX.mas_equalTo(0); make.top.equalTo(midImageV.mas_top).offset(64); }]; //进入云机 UIButton*enterCloudPhoneButton = [[UIButton alloc] init]; CGFloat w_btn = SCREEN_W - 15*2 - 50*2; // gradient CAGradientLayer *gl = [CAGradientLayer layer]; gl.frame = CGRectMake(0,0,w_btn,44.f); gl.startPoint = CGPointMake(0, 0.5); gl.endPoint = CGPointMake(0.97, 0.5); gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor]; gl.locations = @[@(0), @(1.0f)]; [enterCloudPhoneButton.layer addSublayer:gl]; [enterCloudPhoneButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; //[enterCloudPhoneButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:(UIControlEventTouchUpInside)]; [enterCloudPhoneButton setTitle:NSLocalizedString(@"cloudPhone_enter_tip",nil) forState:(UIControlStateNormal)]; [enterCloudPhoneButton.titleLabel setFont:[UIFont systemFontOfSize:16.f]]; [enterCloudPhoneButton.layer setCornerRadius:21.f]; enterCloudPhoneButton.layer.borderWidth = 1.5; enterCloudPhoneButton.layer.borderColor = [UIColor whiteColor].CGColor; enterCloudPhoneButton.clipsToBounds = YES; //enterCloudPhoneButton.tag = 2; [midImageV addSubview:enterCloudPhoneButton]; [enterCloudPhoneButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(w_btn); make.height.mas_equalTo(42); make.centerX.mas_equalTo(0); make.bottom.equalTo(midImageV.mas_bottom).offset(-60); }]; //扩大金融云机范围按钮 UIButton *bigButton = [[UIButton alloc] init]; bigButton.tag = 2; [bigButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:bigButton]; //bigButton.backgroundColor = [UIColor greenColor]; [bigButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(midImageV.mas_top).offset(0); make.right.equalTo(midImageV.mas_right).offset(0); make.left.equalTo(midImageV.mas_left).offset(0); make.bottom.equalTo(midImageV.mas_bottom).offset(0); }]; } #pragma mark 点击按钮 - (void)didClickButtonFun:(UIButton*)but { if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable) { [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show]; return; } // if (!ksharedAppDelegate.isWebSockLinkOKAginType) {//未链接 // [[iToast makeText:NSLocalizedString(@"box_link_error_show_tip",nil)] show]; // return; // } NSInteger tag = but.tag; HLog(@"%ld",tag); switch (tag) { case 1: { //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Cloud_settings"]; _cloudPhoneSetV = [cloudPhoneSetView new]; [ksharedAppDelegate.window addSubview:_cloudPhoneSetV]; [_cloudPhoneSetV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; KWeakSelf _cloudPhoneSetV.didClickButtonFun = ^(NSInteger tag) { if (tag == 10) {//重启 [weakSelf didClickRestartFun]; } else if (tag == 11){//恢复出厂 [weakSelf RestoreFactoryAleartFun]; } }; } break; case 2: { //[self checkFullScreenWithTVShowStateFun]; // PlayerViewController *vc = [PlayerViewController new]; // [self pushViewController:vc animated:YES]; // // if(ksharedAppDelegate.TvStatusMod.isTVShowType){ // [[iToast makeText:NSLocalizedString(@"tv_p2p_ing",nil)] show]; // } [self queryWebRtcMsgFun:YES]; //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Cloud_enter"]; } break; default: break; } } #pragma mark 点击了重启空间 - (void)didClickRestartFun { KWeakSelf /*弹窗提示重启*/ ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_restart_phone_tips",nil) msg:@"" imageStr:@"" cancelTitle:NSLocalizedString(@"other_cancel",nil) okTitle:NSLocalizedString(@"my_set_no_restart_phone_btn_ok",nil) isOkBtnHighlight:NO didClickOk:^{ [weakSelf sureToRestartCloudPhoneFun]; } didClickCancel:^{ }]; nextVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:nextVC animated:YES completion:^{ nextVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } #pragma mark 确认重启云机 - (void)sureToRestartCloudPhoneFun{ // /*重启云手机*/ // 通过指令通道发送 {"type":"reboot"} [[webRtcManager shareManager] needToRebootFun]; //提示语 [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show]; } #pragma mark 点击恢复出厂 - (void)RestoreFactoryAleartFun { KWeakSelf /*弹窗提示恢复出厂*/ ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factory_tips",nil) msg:NSLocalizedString(@"my_set_no_Restore_Factory_msg",nil) imageStr:@"icon_Restore_Factory_big" cancelTitle:NSLocalizedString(@"my_set_TVP2P_Open_sure",nil) okTitle:NSLocalizedString(@"other_cancel",nil) isOkBtnHighlight:YES didClickOk:^{ } didClickCancel:^{ //点击确定 [weakSelf gotoResetFun]; }]; nextVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:nextVC animated:YES completion:^{ nextVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } #pragma mark 点击了恢复出厂 - (void)gotoResetFun { [[webRtcManager shareManager] needToResetFun]; [self RestoreFactoryingFun]; } #pragma mark 恢复出厂中 - (void)RestoreFactoryingFun { KWeakSelf /*弹窗提示恢复出厂*/ ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factorying_tips",nil) msg:NSLocalizedString(@"my_set_no_Restore_Factorying_msg",nil) imageStr:@"" cancelTitle:NSLocalizedString(@"my_set_no_Restore_Factorying",nil) okTitle:@"" isOkBtnHighlight:NO didClickOk:^{ [weakSelf RestoreFactoryCompleteFun]; } didClickCancel:^{ }]; [nextVC setButtonCountdownFun:180];//90 nextVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:nextVC animated:YES completion:^{ nextVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } #pragma mark 恢复出厂倒计时结束 - (void)RestoreFactoryCompleteFun { //KWeakSelf //瑞云发起重连 //[[connectDeviceManager shareInstance] onConnectFun]; /*弹窗提示恢复出厂*/ ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_Restore_Factory_ok_tips",nil) msg:@"" imageStr:@"" cancelTitle:NSLocalizedString(@"my_set_no_Restore_FactoryOK",nil) okTitle:@"" isOkBtnHighlight:NO didClickOk:^{ } didClickCancel:^{ }]; nextVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:nextVC animated:YES completion:^{ nextVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self handelAudioPlayingViewFun]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; } - (void)pushViewController:(UIViewController*)vc animated:(BOOL)animated { [self.navigationController pushViewController:vc animated:animated]; } #pragma mark 处理音频播放中的视图状态 - (void)handelAudioPlayingViewFun { audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance]; if([DFPlayer sharedPlayer].state == DFPlayerStateBuffering ||[DFPlayer sharedPlayer].state == DFPlayerStatePlaying ||[DFPlayer sharedPlayer].state == DFPlayerStatePause){//播放中 [self showAudioPlayingViewFun]; } else{ [self hideAudioPlayingViewFun]; } KWeakSelf audioPlayingV.didClickButtonFun = ^(NSInteger tag) { if(tag == 1){ [weakSelf hideAudioPlayingViewFun]; } else if(tag == 5){ [weakSelf AudioPlayingGotoAudioPlayerVCFun]; } }; } - (void)AudioPlayingGotoAudioPlayerVCFun{ audioPlayerViewController *vc = [audioPlayerViewController new]; vc.isfirstEnterType = NO; [self.navigationController pushViewController:vc animated:YES]; } #pragma mark 显示音频播放中的视图 - (void)showAudioPlayingViewFun { audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance]; [self.view addSubview:audioPlayingV]; if([DFPlayer sharedPlayer].state == DFPlayerStatePlaying){ [audioPlayingV startRotatingImage]; } else if ([DFPlayer sharedPlayer].state == DFPlayerStatePause){ [audioPlayingV stopRotatingImage]; } [audioPlayingV mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(49); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(-TABBARHEIGHT); }]; } #pragma mark 隐藏音频播放中的视图 - (void)hideAudioPlayingViewFun { // audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance]; // [audioPlayingV removeFromSuperview]; } #pragma mark 获取webrct 的链接信息 -(void)queryWebRtcMsgFun:(BOOL)isPlayerType { if(isPlayerType){ if(ksharedAppDelegate.DeviceWebRtcMsgMod && ksharedAppDelegate.DeviceWebRtcMsgMod.data.sn){ [self gotoWebRtcVcBy:ksharedAppDelegate.DeviceWebRtcMsgMod]; return; } [self showNewIndicatorWithCanBack:YES canTouch:NO]; } NSMutableDictionary *paraDict = [NSMutableDictionary new]; KWeakSelf [[netWorkManager shareInstance] CommonPostCallBackCode:webrctQueryByClient Parameters:paraDict success:^(id _Nonnull responseObject){ if(isPlayerType){ [weakSelf removeNewIndicator]; } webRtcMsgModel *curModel = [[webRtcMsgModel alloc] initWithDictionary:responseObject error:nil]; if(curModel && curModel.status == 0){ ksharedAppDelegate.DeviceWebRtcMsgMod = curModel; if(isPlayerType){ [weakSelf gotoWebRtcVcBy:curModel]; } } else { if(isPlayerType && curModel.msg){ [[iToast makeText:curModel.msg] show]; } } } failure:^(NSError * _Nonnull error) { if(isPlayerType){ [weakSelf removeNewIndicator]; [[iToast makeText:NSLocalizedString(@"get_webrtcMsg_fail_tip",nil)] show]; } }]; } #pragma mark 跳转webrtc 页面 - (void)gotoWebRtcVcBy:(webRtcMsgModel*)webRtcMsgMod { NSArray * vcArrs = self.navigationController.viewControllers; if(vcArrs.count != 1){ return; } [cachesFileManager writeLogsWithMsg:@"webRtcPlayer push webRtcPlayerVC"]; webRtcPlayerViewController *vc = [webRtcPlayerViewController new]; vc.webRtcMsgMod = webRtcMsgMod; [self.navigationController pushViewController:vc animated:YES]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ ksharedAppDelegate.isCloudPhoneModeNotPrivacyModeOpenType = NO; ksharedAppDelegate.isCloudPhoneModeAndPrivacyModeOpenType = NO; ksharedAppDelegate.needToPushWebRtcVCType = NO; }); } #pragma mark 输入密码完成 - (void)didInpuPwdOkFun { KWeakSelf mainBlock(^{ if(ksharedAppDelegate.isCloudPhoneModeAndPrivacyModeOpenType || ksharedAppDelegate.needToPushWebRtcVCType){ [weakSelf queryWebRtcMsgFun:YES]; } }); } @end