backupsOptionViewController.m 12 KB

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