mineViewController.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. //
  2. // mineViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/6/21.
  6. //
  7. #import "mineViewController.h"
  8. #import "MineCommonUsedView.h"
  9. #import "privacyModeViewController.h"
  10. #import "TipsQRCodeForChangeDeviceViewController.h"
  11. #import "AboutViewController.h"
  12. #import "clearCacheAlretViewController.h"
  13. #import "inputPWDViewController.h"
  14. #import "customerServiceViewController.h"
  15. #import "customDownloadCacheManager.h"
  16. #import "CustomerWebViewController.h"
  17. #import "audioPlayingView.h"
  18. #import "DFPlayer.h"
  19. #import "audioPlayerViewController.h"
  20. @interface mineViewController ()
  21. @property(nonatomic,strong)UIButton *netButton;
  22. @property(nonatomic,strong)UILabel *snLabel;
  23. @property(nonatomic,strong)MineCommonUsedView *MineCommonUsedV;
  24. @end
  25. @implementation mineViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. // Do any additional setup after loading the view.
  29. [self.view setBackgroundColor:HWF5F7FAColor];
  30. [self.toolBar setHidden:YES];
  31. [self.navigationBar setHidden:YES];
  32. [self.navBarBGView setHidden:YES];
  33. [self drawAnyView];
  34. }
  35. - (void)drawAnyView{
  36. //顶底底部图片
  37. UIImageView *topImageV = [UIImageView new];
  38. topImageV.image = [UIImage imageNamed:@"Nas_top_img"];
  39. [self.view addSubview:topImageV];
  40. [topImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.mas_equalTo(0);
  42. make.left.mas_equalTo(0);
  43. make.right.mas_equalTo(0);
  44. make.height.mas_equalTo(280.0*AUTOSCALE);
  45. }];
  46. //商标图片
  47. UIImageView *TipImageV = [UIImageView new];
  48. TipImageV.image = [UIImage imageNamed:@"mine_head_icon"];
  49. [self.view addSubview:TipImageV];
  50. [TipImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.mas_equalTo(68);
  52. make.left.mas_equalTo(16);
  53. make.width.mas_equalTo(48);
  54. make.height.mas_equalTo(48);
  55. }];
  56. _netButton = [[UIButton alloc] init];
  57. [_netButton setImage:[UIImage imageNamed:@"mine_net_icon"] forState:UIControlStateNormal];
  58. [_netButton setTitleColor:[UIColor hwColor:@"#058DFB"] forState:UIControlStateNormal];
  59. _netButton.titleLabel.font = [UIFont systemFontOfSize:12.0];
  60. //_netButton.tag = 1;
  61. //[_netButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  62. _netButton.userInteractionEnabled = NO;
  63. [self.view addSubview:_netButton];
  64. _netButton.layer.cornerRadius = 12;
  65. _netButton.layer.borderWidth = 1.5;
  66. _netButton.layer.borderColor = [UIColor hwColor:@"#058DFB"].CGColor;
  67. _netButton.layer.masksToBounds = YES;
  68. [_netButton mas_makeConstraints:^(MASConstraintMaker *make) {
  69. //make.width.mas_equalTo(58);
  70. make.width.mas_equalTo(70);
  71. make.height.mas_equalTo(24);
  72. make.right.mas_equalTo(-16);
  73. make.centerY.mas_equalTo(TipImageV.mas_centerY).offset(0);
  74. }];
  75. _snLabel = [[UILabel alloc] init];
  76. _snLabel.font = [UIFont boldSystemFontOfSize:14.0];
  77. _snLabel.textColor = [UIColor hwColor:@"#0A132B"];
  78. //_fileNamelabel.backgroundColor = [UIColor greenColor];
  79. [self.view addSubview:_snLabel];
  80. [_snLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.equalTo(TipImageV.mas_right).offset(5);
  82. make.right.equalTo(_netButton.mas_left).offset(-5);
  83. make.centerY.mas_equalTo(TipImageV.mas_centerY).offset(0);
  84. }];
  85. //常用功能
  86. _MineCommonUsedV = [[MineCommonUsedView alloc] init];
  87. [self.view addSubview:_MineCommonUsedV];
  88. [_MineCommonUsedV mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.top.equalTo(TipImageV.mas_bottom).offset(15);
  90. make.left.mas_equalTo(0);
  91. make.right.mas_equalTo(0);
  92. make.height.mas_equalTo(210);
  93. }];
  94. KWeakSelf
  95. _MineCommonUsedV.didClickButtonFun = ^(NSInteger tag) {
  96. [weakSelf didClickCommonUsedFunBy:tag];
  97. };
  98. }
  99. #pragma mark 点击常用模块模块
  100. - (void)didClickCommonUsedFunBy:(NSInteger)tag
  101. {
  102. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
  103. {
  104. [[iToast makeText:NSLocalizedString(@"phone_network_fail_Tips",nil)] show];
  105. return;
  106. }
  107. switch (tag)
  108. {
  109. case 10:{
  110. inputPWDViewController *nextVC = [inputPWDViewController new];
  111. nextVC.isCheckPwdType = YES;
  112. [self pushViewController:nextVC animated:YES];
  113. KWeakSelf
  114. nextVC.didInputRightPwdFun = ^{
  115. [weakSelf gotoPrivacyModeVCFun];
  116. };
  117. }
  118. break;
  119. case 11:{
  120. TipsQRCodeForChangeDeviceViewController *nextVC = [TipsQRCodeForChangeDeviceViewController new];
  121. [self pushViewController:nextVC animated:YES];
  122. }
  123. break;
  124. case 12:{
  125. CustomerWebViewController *vc = [[CustomerWebViewController alloc] init];
  126. vc.titleStr = NSLocalizedString(@"mine_help_title",nil);
  127. NSString *url = @"http://testprivacy.phone.armclouding.com:1801/problemFeedback/#/pages/fileSharing/problem/index?sn=";
  128. if([CloudService rangeOfString:@"hiboxde.armclouding.com"].location != NSNotFound){
  129. //url = @"http://hiboxde.armclouding.com:7780/h5/rule.html";;
  130. }
  131. vc.webUrl = [[NSString alloc] initWithFormat:@"%@%@",url,[connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn];
  132. [self pushViewController:vc animated:YES];
  133. //数据埋点
  134. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Help_feedback"];
  135. }
  136. break;
  137. case 13:{
  138. customerServiceViewController *vc = [customerServiceViewController new];
  139. [self pushViewController:vc animated:YES];
  140. }
  141. break;
  142. case 14:{
  143. CustomerWebViewController *vc = [[CustomerWebViewController alloc] init];
  144. vc.titleStr = NSLocalizedString(@"mine_newuser_title",nil);
  145. NSString *url = @"http://testprivacy.phone.androidscloud.com:1801/warrantyService/index.html#/novice";
  146. if([CloudService rangeOfString:@"hiboxde.armclouding.com"].location != NSNotFound){
  147. //url = @"http://hiboxde.armclouding.com:7780/h5/rule.html";;
  148. }
  149. vc.webUrl = url;
  150. [self pushViewController:vc animated:YES];
  151. }
  152. break;
  153. case 15:{
  154. [self clickClearCacheButtonFun];
  155. }
  156. break;
  157. case 16:{
  158. AboutViewController *nextVC = [[AboutViewController alloc] init];
  159. nextVC.getSysInfo = ^{
  160. [[webSocketManager shareInstance] getSysInfoFun];
  161. };
  162. [self pushViewController:nextVC animated:YES];
  163. }
  164. break;
  165. case 17:{
  166. [[iToast makeText:@"点击了注销"] show];
  167. }
  168. break;
  169. default:
  170. break;
  171. }
  172. }
  173. #pragma mark 去设置隐私
  174. - (void)gotoPrivacyModeVCFun
  175. {
  176. privacyModeViewController *nextVC = [[privacyModeViewController alloc] init];
  177. [self pushViewController:nextVC animated:YES];
  178. }
  179. #pragma mark 清理缓存相关
  180. - (void)clickClearCacheButtonFun
  181. {
  182. KWeakSelf
  183. /*弹窗提示清除缓存*/
  184. clearCacheAlretViewController *nextVC = [[clearCacheAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_clear_cache",nil)
  185. msg:NSLocalizedString(@"clear_cache_tip",nil)
  186. imageStr:nil
  187. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  188. okTitle:NSLocalizedString(@"other_clear",nil) isOkBtnHighlight:YES
  189. didClickOk:^(BOOL isSelect) {
  190. [weakSelf handleClearCacheFunWith:isSelect];
  191. } didClickCancel:^{
  192. }];
  193. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  194. [self presentViewController:nextVC animated:YES completion:^{
  195. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  196. }];
  197. }
  198. - (void)handleClearCacheFunWith:(BOOL)isSelectFileTransfer
  199. {
  200. [self ClearCommonCacheFun:isSelectFileTransfer];
  201. //数据埋点
  202. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Clear_cache"];
  203. }
  204. - (void)ClearCommonCacheFun:(BOOL)isSelectFileTransfer
  205. {
  206. NSString *ruiyunLogPath = [NSString stringWithFormat:@"%@/logs/debug_0.log",CachesPatch];
  207. long logSize1 = [iTools fileSizeAtPath:ruiyunLogPath];
  208. [[NSFileManager defaultManager] removeItemAtPath:ruiyunLogPath error:nil];
  209. NSString *appLogPath = [NSString stringWithFormat:@"%@/logs/app.log",CachesPatch];
  210. long logSize2 = [iTools fileSizeAtPath:appLogPath];
  211. [[NSFileManager defaultManager] removeItemAtPath:appLogPath error:nil];
  212. //
  213. NSString *downLoadThumbnailPath = [NSString stringWithFormat:@"%@/DownLoadThumbnail",CachesPatch];
  214. long logSize3 = [iTools folderSizeAtPath:downLoadThumbnailPath];
  215. [[NSFileManager defaultManager] removeItemAtPath:downLoadThumbnailPath error:nil];
  216. NSString *downLoadNasDowmPath = [customDownloadCacheManager getFullDirector];
  217. long logSize4 = [iTools folderSizeAtPath:downLoadNasDowmPath];
  218. [[NSFileManager defaultManager] removeItemAtPath:downLoadNasDowmPath error:nil];
  219. long clearTotal = logSize1 + logSize2 + logSize3 +logSize4 ;
  220. if(isSelectFileTransfer){
  221. [self clearCacheByFileTransferFun:clearTotal];
  222. }
  223. else{
  224. [self showClearAllTipBy:clearTotal];
  225. }
  226. }
  227. - (void)showClearAllTipBy:(long)clearTotal
  228. {
  229. long clearTotalK = clearTotal /1024;
  230. NSString *tipStr1 = NSLocalizedString(@"my_set_no_clear_finish",nil);
  231. NSString *tipStr2 = @"";
  232. if(clearTotalK > 1024*1024){
  233. tipStr2 = [[NSString alloc] initWithFormat:@"%.02fGB",clearTotalK/1024.0/1024.0];
  234. }
  235. else if(clearTotalK > 1024){
  236. tipStr2 = [[NSString alloc] initWithFormat:@"%.02fMB",clearTotalK/1024.0];
  237. }
  238. else //if(clearTotalK > 0)
  239. {
  240. tipStr2 = [[NSString alloc] initWithFormat:@"%ldKB",clearTotalK];
  241. }
  242. NSString *tipfullStr = [[NSString alloc] initWithFormat:@"%@%@",tipStr1,tipStr2];
  243. //提示语
  244. [[iToast makeText:tipfullStr] show];
  245. }
  246. - (void)clearCacheByFileTransferFun:(long)clearTotal
  247. {
  248. //清理图片
  249. BOOL needReUploadingType = NO;
  250. NSString *ImagePath = [NSString stringWithFormat:@"%@/Image",CachesPatch];
  251. long imageAllSize = [iTools folderSizeAtPath:ImagePath];
  252. if([uploadFileManager shareInstance].curUploadFileDataModel
  253. && [uploadFileManager shareInstance].curUploadFileDataModel.curUploadFileType == uploadFileTypeImage
  254. && [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType == uploadStateUploading){
  255. [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateSuspend;
  256. needReUploadingType = YES;
  257. }
  258. [[NSFileManager defaultManager] removeItemAtPath:ImagePath error:nil];
  259. if(needReUploadingType){
  260. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  261. [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateUploading;
  262. });
  263. }
  264. //清理视频文件
  265. NSString *videoPath = [NSString stringWithFormat:@"%@/Video",CachesPatch];
  266. long vide0AllSizeBeforeClear = [iTools folderSizeAtPath:videoPath];
  267. NSString *backupsingVideoName = nil;
  268. if([backupsFileManager shareInstance].curPhotosBackupsTaskMod
  269. && [backupsFileManager shareInstance].curPhotosBackupsTaskMod.curUploadFileType == uploadFileTypeVideo){
  270. backupsingVideoName = [backupsFileManager shareInstance].curPhotosBackupsTaskMod.filename;
  271. }
  272. NSString *uploadingVideoName = nil;
  273. if([uploadFileManager shareInstance].curUploadFileDataModel
  274. && [uploadFileManager shareInstance].curUploadFileDataModel.curUploadFileType == uploadFileTypeVideo){
  275. uploadingVideoName = [uploadFileManager shareInstance].curUploadFileDataModel.filename;
  276. }
  277. if(backupsingVideoName || uploadingVideoName){
  278. NSMutableString *fileName = [NSMutableString new];
  279. if(backupsingVideoName){
  280. [fileName appendString:backupsingVideoName];
  281. }
  282. if(uploadingVideoName){
  283. if(fileName.length > 0){
  284. [fileName appendString:@"|"];
  285. }
  286. [fileName appendString:uploadingVideoName];
  287. }
  288. [self deleteFilesInDirectoryAtPath:videoPath withOutFileName:fileName];
  289. }
  290. else{
  291. [[NSFileManager defaultManager] removeItemAtPath:videoPath error:nil];
  292. }
  293. long vide0AllSizeAfterClear = [iTools folderSizeAtPath:videoPath];
  294. //清理下载中
  295. NSString *downLoadingPath = [NSString stringWithFormat:@"%@/DownLoadFlie",CachesPatch];
  296. long downLoadingSizeBeforeClear = [iTools folderSizeAtPath:downLoadingPath];
  297. NSString *downLoadingFileName = nil;
  298. if([downloadManager shareInstance].curDownloadFileModel
  299. && ([downloadManager shareInstance].curDownloadFileModel.curDownloadStateType == downloadStateUploading
  300. ||[downloadManager shareInstance].curDownloadFileModel.curDownloadStateType == downloadStateSuspend)){
  301. downLoadingFileName = [[downloadManager shareInstance].curDownloadFileModel getFileNameFun];
  302. [self deleteFilesInDirectoryAtPath:downLoadingPath withOutFileName:downLoadingFileName];
  303. }
  304. else{
  305. [[NSFileManager defaultManager] removeItemAtPath:downLoadingPath error:nil];
  306. }
  307. long downLoadingSizeAfterClear = [iTools folderSizeAtPath:downLoadingPath];
  308. //清理数据库表 完成的
  309. //下载完成
  310. NSMutableString* where = [[NSMutableString alloc] initWithString:@"where "];
  311. NSString *curStr = [NSString stringWithFormat:@"%@=%@ or %@=%@ ",bg_sqlKey(@"curDownloadStateType"),bg_sqlValue([NSNumber numberWithInt:downloadStateDone]),bg_sqlKey(@"curDownloadStateType"),bg_sqlValue([NSNumber numberWithInt:downloadStateFail])];
  312. [where appendString:curStr];
  313. [couldPhoneFileModel bg_deleteAsync:download_tableName where:where complete:^(BOOL isSuccess) {
  314. }];
  315. //上传完成
  316. NSMutableString* where2 = [[NSMutableString alloc] initWithString:@"where "];
  317. NSString *curStr2 = [NSString stringWithFormat:@"%@=%@ or %@=%@ ",bg_sqlKey(@"curUploadStateType"),bg_sqlValue([NSNumber numberWithInt:uploadStateDone]),
  318. bg_sqlKey(@"curUploadStateType"),bg_sqlValue([NSNumber numberWithInt:uploadStateFail])];
  319. [where2 appendString:curStr2];
  320. [uploadFileDataModel bg_deleteAsync:upLoadFile_image_tableName where:where2 complete:^(BOOL isSuccess) {
  321. }];
  322. //清理音频播放缓存
  323. NSString *audioPlayPath = [NSString stringWithFormat:@"%@/%@",DocumentPath,@"playAudioCache"];;
  324. long audioPlayAllSize = [iTools folderSizeAtPath:audioPlayPath];
  325. [[NSFileManager defaultManager] removeItemAtPath:audioPlayPath error:nil];
  326. long curTotolSize = (downLoadingSizeBeforeClear - downLoadingSizeAfterClear) + (vide0AllSizeBeforeClear - vide0AllSizeAfterClear) + imageAllSize + clearTotal + audioPlayAllSize;
  327. [self showClearAllTipBy:curTotolSize];
  328. }
  329. - (BOOL)deleteFilesInDirectoryAtPath:(NSString *)path withOutFileName:(NSString*)fileNames {
  330. NSFileManager *fileManager = [NSFileManager defaultManager];
  331. NSArray *fileNameArr = [fileNames componentsSeparatedByString:@"|"];
  332. // 使用NSDirectoryEnumerator遍历目录
  333. NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:path];
  334. NSString *fileName;
  335. while ((fileName = [directoryEnumerator nextObject])) {
  336. BOOL canDelType = YES;
  337. for (NSString*noDelfileName in fileNameArr) {
  338. if([noDelfileName isEqualToString:fileName]){
  339. canDelType = NO;
  340. break;
  341. }
  342. }
  343. if(canDelType){
  344. NSString *filePath = [path stringByAppendingPathComponent:fileName];
  345. // 如果是文件,则删除它
  346. if ([fileManager fileExistsAtPath:filePath]) {
  347. BOOL success = [fileManager removeItemAtPath:filePath error:nil];
  348. if (!success) {
  349. // 如果删除失败,返回NO并处理错误
  350. return NO;
  351. }
  352. }
  353. }
  354. }
  355. // 所有文件都成功删除,返回YES
  356. return YES;
  357. }
  358. #pragma mark 数据设置
  359. - (void)setDataFun
  360. {
  361. NSString *fullSNStr = [[NSString alloc] initWithFormat:@"SN:%@",[connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn];
  362. _snLabel.text = fullSNStr;
  363. NSString *NetButText = NSLocalizedString(@"mine_net_LAN",nil);
  364. if(![connectDeviceManager shareInstance].isPingOk){
  365. NetButText = NSLocalizedString(@"mine_net_WAN",nil);
  366. }
  367. RCSocketCloudPhoneStatus status = [[webSocketManager shareInstance].commandChannelManager rc_socketStatus];
  368. HLog(@"rc_socketStatus:%ld",status)
  369. if(status == RCSocketCloudPhoneStatusFailed
  370. ||status == RCSocketCloudPhoneStatusClosedByServer
  371. ||status == RCSocketCloudPhoneStatusClosedByUser
  372. ||!ksharedAppDelegate.isWebSockLinkOKAginType//断开了
  373. )
  374. {
  375. NetButText = NSLocalizedString(@"mine_net_unLink",nil);
  376. }
  377. [_netButton setTitle:NetButText forState:UIControlStateNormal];
  378. }
  379. - (void)viewWillAppear:(BOOL)animated
  380. {
  381. [super viewWillAppear:animated];
  382. [self setDataFun];
  383. [self handelAudioPlayingViewFun];
  384. }
  385. - (void)viewWillDisappear:(BOOL)animated{
  386. [super viewWillDisappear:animated];
  387. }
  388. - (void)pushViewController:(UIViewController*)vc animated:(BOOL)animated
  389. {
  390. [self.navigationController pushViewController:vc animated:animated];
  391. }
  392. #pragma mark 处理音频播放中的视图状态
  393. - (void)handelAudioPlayingViewFun
  394. {
  395. audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance];
  396. if([DFPlayer sharedPlayer].state == DFPlayerStateBuffering
  397. ||[DFPlayer sharedPlayer].state == DFPlayerStatePlaying
  398. ||[DFPlayer sharedPlayer].state == DFPlayerStatePause){//播放中
  399. [self showAudioPlayingViewFun];
  400. }
  401. else{
  402. [self hideAudioPlayingViewFun];
  403. }
  404. KWeakSelf
  405. audioPlayingV.didClickButtonFun = ^(NSInteger tag) {
  406. if(tag == 1){
  407. [weakSelf hideAudioPlayingViewFun];
  408. }
  409. else if(tag == 5){
  410. [weakSelf AudioPlayingGotoAudioPlayerVCFun];
  411. }
  412. };
  413. }
  414. - (void)AudioPlayingGotoAudioPlayerVCFun{
  415. audioPlayerViewController *vc = [audioPlayerViewController new];
  416. vc.isfirstEnterType = NO;
  417. [self.navigationController pushViewController:vc animated:YES];
  418. }
  419. #pragma mark 显示音频播放中的视图
  420. - (void)showAudioPlayingViewFun
  421. {
  422. audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance];
  423. [self.view addSubview:audioPlayingV];
  424. [audioPlayingV mas_makeConstraints:^(MASConstraintMaker *make) {
  425. make.height.mas_equalTo(49);
  426. make.left.mas_equalTo(0);
  427. make.right.mas_equalTo(0);
  428. make.bottom.mas_equalTo(-TABBARHEIGHT);
  429. }];
  430. }
  431. #pragma mark 隐藏音频播放中的视图
  432. - (void)hideAudioPlayingViewFun
  433. {
  434. // audioPlayingView * audioPlayingV = [audioPlayingView sharedInstance];
  435. // [audioPlayingV removeFromSuperview];
  436. }
  437. @end