mineViewController.m 16 KB

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