mineViewController.m 18 KB

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