backupsOptionViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. //
  2. // backupsOptionViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/15.
  6. //
  7. #import "backupsOptionViewController.h"
  8. #import "uploadFileRecordViewController.h"
  9. #import "downloadManager.h"
  10. #import "backupsFileManager.h"
  11. #import "AFNetworkReachabilityManager.h"
  12. #import "backupsOptionTipView.h"
  13. #import "fileTransfeSetViewController.h"
  14. @interface backupsOptionViewController ()
  15. {
  16. UIButton* rightTransferListButton;//传输列表
  17. UIView* rightRedView;
  18. BOOL hadUploadTaskType;
  19. BOOL hadDownloadTaskType;
  20. }
  21. @property(nonatomic,strong) UIButton* imageBackupsButton;
  22. @property(nonatomic,strong)UILabel*imageBackupsLabel;
  23. @end
  24. @implementation backupsOptionViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view.
  28. [self.toolBar setHidden:YES];
  29. [self.navigationBar setHidden:YES];
  30. [self.navBarBGView setHidden:NO];
  31. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  32. [self.view setBackgroundColor:[UIColor hwColor:@"#F5F7FA"]];
  33. self.titleLabel.text = NSLocalizedString(@"my_set_no_File_backups",nil);
  34. [self drawAnyView];
  35. rightTransferListButton = [[UIButton alloc] init];
  36. [rightTransferListButton setImage:[UIImage imageNamed:@"icon_file_transfer"] forState:UIControlStateNormal];
  37. [rightTransferListButton addTarget:self action:@selector(didiClikRightButGotoTransferListFun:) forControlEvents:UIControlEventTouchUpInside];
  38. [self.navBarBGView addSubview:rightTransferListButton];
  39. [rightTransferListButton mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.width.mas_equalTo(40);
  41. make.height.mas_equalTo(40);
  42. make.right.mas_equalTo(-15);
  43. make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  44. }];
  45. rightRedView = [[UIView alloc] init];
  46. rightRedView.backgroundColor = [UIColor hwColor:@"#DD4E4E" alpha:1.0];
  47. [rightTransferListButton addSubview:rightRedView];
  48. rightRedView.layer.cornerRadius = 7;
  49. rightRedView.hidden = YES;
  50. [rightRedView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.width.mas_equalTo(14);
  52. make.height.mas_equalTo(14);
  53. make.right.mas_equalTo(0);
  54. make.top.mas_equalTo(6);
  55. }];
  56. [self setBackupsStateFun];
  57. //数据埋点
  58. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Backup"];
  59. }
  60. - (void)drawAnyView
  61. {
  62. UIView*imageBackupsBgView = [[UIView alloc] init];
  63. imageBackupsBgView.backgroundColor = [UIColor whiteColor];
  64. imageBackupsBgView.layer.cornerRadius = 8;
  65. [self.view addSubview:imageBackupsBgView];
  66. [imageBackupsBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.right.mas_equalTo(-10);
  68. make.left.mas_equalTo(10);
  69. make.top.equalTo(self.navBarBGView.mas_bottom).offset(16.f);
  70. make.height.mas_equalTo(56);
  71. }];
  72. UIImageView *backupsImageV = [[UIImageView alloc] init];
  73. backupsImageV.image = [UIImage imageNamed:@"image_backups_icon"];
  74. [imageBackupsBgView addSubview:backupsImageV];
  75. [backupsImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.centerY.mas_equalTo(0);
  77. make.left.mas_equalTo(10);
  78. make.width.mas_equalTo(28);
  79. make.height.mas_equalTo(28);
  80. }];
  81. UILabel *imageBackupsTitleLabel = [[UILabel alloc] init];
  82. imageBackupsTitleLabel.text = NSLocalizedString(@"set_Privacy_title_image",nil) ;
  83. imageBackupsTitleLabel.font = [UIFont systemFontOfSize:14.0];
  84. imageBackupsTitleLabel.textColor = [UIColor blackColor];
  85. [imageBackupsBgView addSubview:imageBackupsTitleLabel];
  86. [imageBackupsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.centerY.mas_equalTo(-10);
  88. make.left.mas_equalTo(backupsImageV.mas_right).offset(10);
  89. make.right.mas_equalTo(-(10+60+10));
  90. make.height.mas_equalTo(20);
  91. }];
  92. _imageBackupsLabel = [[UILabel alloc] init];
  93. //_imageBackupsLabel.text = NSLocalizedString(@"set_Privacy_title_image_open",nil) ;
  94. _imageBackupsLabel.font = [UIFont systemFontOfSize:12.0];
  95. _imageBackupsLabel.textColor = [UIColor hwColor:@"#6A6A6A" alpha:1.0];
  96. [imageBackupsBgView addSubview:_imageBackupsLabel];
  97. [_imageBackupsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.centerY.mas_equalTo(10);
  99. make.left.mas_equalTo(backupsImageV.mas_right).offset(10);
  100. make.right.mas_equalTo(-(10+60+10));
  101. make.height.mas_equalTo(20);
  102. }];
  103. _imageBackupsButton = [[UIButton alloc] init];
  104. _imageBackupsButton.backgroundColor = [UIColor hwColor:@"#DCF4FB" alpha:1.0];
  105. _imageBackupsButton.tag = 7;
  106. [_imageBackupsButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  107. _imageBackupsButton.layer.cornerRadius = 12.0;
  108. _imageBackupsButton.layer.masksToBounds = YES;
  109. [_imageBackupsButton setTitle:NSLocalizedString(@"common_open",nil) forState:UIControlStateNormal];
  110. [_imageBackupsButton setTitle:NSLocalizedString(@"common_close",nil) forState:UIControlStateSelected];
  111. [_imageBackupsButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  112. _imageBackupsButton.titleLabel.font = [UIFont systemFontOfSize:12.0];
  113. [imageBackupsBgView addSubview:_imageBackupsButton];
  114. [_imageBackupsButton mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.right.mas_equalTo(-10);
  116. make.centerY.mas_equalTo(0);
  117. make.width.mas_equalTo(60);
  118. make.height.mas_equalTo(24);
  119. }];
  120. }
  121. - (void)closeImageBackupsFun
  122. {
  123. [HWDataManager setBoolWithKey:stringKeyAddSn(Const_photo_backups_state) value:NO];
  124. [self setBackupsStateFun];
  125. //处理相册备份
  126. [[backupsFileManager shareInstance] suspendBackupsFileFun];
  127. //数据埋点
  128. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Album_Backup_off"];
  129. }
  130. - (void)openImageBackupsFun
  131. {
  132. BOOL isCanUseCellular = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular_all)];
  133. if(!isCanUseCellular){//不允许流量上传
  134. //
  135. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN){
  136. mainBlock(^{
  137. [[iToast makeText:NSLocalizedString(@"File_Transfer_By_Cellular_tip",nil)] show];
  138. });
  139. return;
  140. }
  141. }
  142. [self showBackupsReadTipFun];
  143. [HWDataManager setBoolWithKey:stringKeyAddSn(Const_photo_backups_state) value:YES];
  144. [self setBackupsStateFun];
  145. [[iToast makeText:NSLocalizedString(@"set_Privacy_title_image_open",nil)] show];
  146. //处理相册备份
  147. [[backupsFileManager shareInstance] handlePhotosBackupsFun];
  148. //数据埋点
  149. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Album_Backup_on"];
  150. }
  151. - (void)showBackupsReadTipFun
  152. {
  153. BOOL didReadbackupsTipType = [HWDataManager getBoolWithKey:Const_file_backups_need_read];
  154. if(didReadbackupsTipType){//阅读过
  155. return;
  156. }
  157. backupsOptionTipView * backupsOptionTipV = [[backupsOptionTipView alloc] init];
  158. [ksharedAppDelegate.window addSubview:backupsOptionTipV];
  159. [backupsOptionTipV mas_makeConstraints:^(MASConstraintMaker *make) {
  160. make.left.mas_equalTo(0.0);
  161. make.right.mas_equalTo(0.0);
  162. make.top.mas_equalTo(0.0);
  163. make.bottom.mas_equalTo(0.0);
  164. }];
  165. KWeakSelf
  166. backupsOptionTipV.didClickButtonFun = ^(NSInteger tag) {
  167. if(tag==10){
  168. [weakSelf gotoFileTransfeSetVCFun];
  169. }
  170. };
  171. // NSString*msgStr1 = NSLocalizedString(@"backups_need_read_msg",nil);
  172. // NSString*msgStr2 = NSLocalizedString(@"backups_need_read_msg2",nil);
  173. //
  174. // NSString *totalMsgstr = [[NSString alloc] initWithFormat:@"%@%@",msgStr1,msgStr2];
  175. //
  176. // //KWeakSelf
  177. // /*弹窗提示恢复出厂*/
  178. // ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:@""
  179. // msg:totalMsgstr
  180. // imageStr:@""
  181. // cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  182. // okTitle:@""
  183. // isOkBtnHighlight:NO
  184. // didClickOk:^{
  185. //
  186. // } didClickCancel:^{
  187. // [HWDataManager setBoolWithKey:Const_file_backups_need_read value:YES];
  188. // }];
  189. //
  190. // nextVC.modalPresentationStyle = UIModalPresentationCustom;
  191. // [nextVC setMsgTextAlignment:NSTextAlignmentLeft];
  192. //
  193. // [[iTools appRootViewController] presentViewController:nextVC animated:YES completion:^{
  194. // nextVC.view.superview.backgroundColor = [UIColor clearColor];
  195. // }];
  196. }
  197. #pragma mark 调整传输设置
  198. - (void)gotoFileTransfeSetVCFun
  199. {
  200. if(!ksharedAppDelegate.isWebSockLinkOKAginType){
  201. [[iToast makeText:NSLocalizedString(@"check_could_phone_state",nil)] show];
  202. return;
  203. }
  204. fileTransfeSetViewController *nextVC = [fileTransfeSetViewController new];
  205. [self.navigationController pushViewController:nextVC animated:YES];
  206. }
  207. - (void)setBackupsStateFun
  208. {
  209. BOOL haveOpenBackups = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_photo_backups_state)];
  210. _imageBackupsButton.selected = haveOpenBackups;
  211. if(haveOpenBackups){
  212. _imageBackupsLabel.text = NSLocalizedString(@"set_Privacy_title_image_open",nil) ;
  213. }
  214. else
  215. {
  216. _imageBackupsLabel.text = NSLocalizedString(@"set_Privacy_title_image_close",nil) ;
  217. }
  218. }
  219. #pragma mark 按钮点击事件
  220. - (void)didClickButFun:(UIButton*)but
  221. {
  222. //NSInteger tag = but.tag;
  223. //HLog(@"xxxx:%ld",tag)
  224. BOOL haveOpenBackups = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_photo_backups_state)];
  225. if(!haveOpenBackups){
  226. if(ksharedAppDelegate.DisabledFileTransferType){
  227. if(ksharedAppDelegate.isImageNewFor130){
  228. [[iToast makeText:NSLocalizedString(@"File_Transfer_Disable_tip",nil)] show];
  229. }
  230. else{
  231. [[iToast makeText:NSLocalizedString(@"File_Transfer_Disable_tip2",nil)] show];
  232. }
  233. return;
  234. }
  235. if(!ksharedAppDelegate.isWebSockLinkOKAginType){
  236. [[iToast makeText:NSLocalizedString(@"check_could_phone_state",nil)] show];
  237. return;
  238. }
  239. //相册权限
  240. if (![[TZImageManager manager] authorizationStatusAuthorized]){
  241. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  242. if(status == PHAuthorizationStatusAuthorized){
  243. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  244. [self openImageBackupsFun];
  245. });
  246. }
  247. }];
  248. }
  249. else{
  250. [self openImageBackupsFun];
  251. }
  252. return;
  253. }
  254. else{
  255. KWeakSelf
  256. /*弹窗提示关闭备份*/
  257. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_backups_set_close_title",nil)
  258. msg:NSLocalizedString(@"File_backups_set_close_tip",nil)
  259. imageStr:nil
  260. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  261. okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
  262. didClickOk:^{
  263. [weakSelf closeImageBackupsFun];
  264. } didClickCancel:^{
  265. }];
  266. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  267. [self presentViewController:nextVC animated:YES completion:^{
  268. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  269. }];
  270. }
  271. }
  272. - (void)checkFileTransferTask
  273. {//有个偶现的闪退在BGFMDB
  274. [[nasUploadFileManager shareInstance] checkHadUploadTaskWithComplete:^(BOOL isSuccess) {
  275. self->hadUploadTaskType = isSuccess;
  276. [self setRightButtonRedTypeFun];
  277. }];
  278. KWeakSelf
  279. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  280. [[nasDownloadFileManager shareInstance] checkHadDownloadTaskWithComplete:^(BOOL isSuccess) {
  281. self->hadDownloadTaskType = isSuccess;
  282. [weakSelf setRightButtonRedTypeFun];
  283. }];
  284. });
  285. }
  286. - (void)setRightButtonRedTypeFun
  287. {
  288. mainBlock(^{
  289. if(self->hadUploadTaskType || self->hadDownloadTaskType){
  290. self->rightRedView.hidden = NO;
  291. }
  292. else{
  293. self->rightRedView.hidden = YES;
  294. }
  295. });
  296. }
  297. - (void)didiClikRightButGotoTransferListFun:(UIButton*)but
  298. {
  299. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  300. [self.navigationController pushViewController:vc animated:YES];
  301. }
  302. - (void)viewDidAppear:(BOOL)animated{
  303. [super viewDidAppear:animated];
  304. [self checkFileTransferTask];
  305. }
  306. @end