backupsOptionViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. //KWeakSelf
  156. /*弹窗提示恢复出厂*/
  157. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
  158. msg:NSLocalizedString(@"backups_need_read_msg",nil)
  159. imageStr:nil
  160. cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
  161. okTitle:nil
  162. isOkBtnHighlight:NO
  163. didClickOk:^{
  164. } didClickCancel:^{
  165. [HWDataManager setBoolWithKey:Const_file_backups_need_read value:YES];
  166. }];
  167. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  168. [[iTools appRootViewController] presentViewController:nextVC animated:YES completion:^{
  169. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  170. }];
  171. }
  172. - (void)setBackupsStateFun
  173. {
  174. BOOL haveOpenBackups = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_photo_backups_state)];
  175. _imageBackupsButton.selected = haveOpenBackups;
  176. if(haveOpenBackups){
  177. _imageBackupsLabel.text = NSLocalizedString(@"set_Privacy_title_image_open",nil) ;
  178. }
  179. else
  180. {
  181. _imageBackupsLabel.text = NSLocalizedString(@"set_Privacy_title_image_close",nil) ;
  182. }
  183. }
  184. #pragma mark 按钮点击事件
  185. - (void)didClickButFun:(UIButton*)but
  186. {
  187. //NSInteger tag = but.tag;
  188. //HLog(@"xxxx:%ld",tag)
  189. BOOL haveOpenBackups = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_photo_backups_state)];
  190. if(!haveOpenBackups){
  191. if(ksharedAppDelegate.DisabledFileTransferType){
  192. if(ksharedAppDelegate.isImageNewFor130){
  193. [[iToast makeText:NSLocalizedString(@"File_Transfer_Disable_tip",nil)] show];
  194. }
  195. else{
  196. [[iToast makeText:NSLocalizedString(@"File_Transfer_Disable_tip2",nil)] show];
  197. }
  198. return;
  199. }
  200. if(!ksharedAppDelegate.isWebSockLinkOKAginType){
  201. [[iToast makeText:NSLocalizedString(@"check_could_phone_state",nil)] show];
  202. return;
  203. }
  204. //相册权限
  205. if (![[TZImageManager manager] authorizationStatusAuthorized]){
  206. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  207. if(status == PHAuthorizationStatusAuthorized){
  208. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  209. [self openImageBackupsFun];
  210. });
  211. }
  212. }];
  213. }
  214. else{
  215. [self openImageBackupsFun];
  216. }
  217. return;
  218. }
  219. else{
  220. KWeakSelf
  221. /*弹窗提示关闭备份*/
  222. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_backups_set_close_title",nil)
  223. msg:NSLocalizedString(@"File_backups_set_close_tip",nil)
  224. imageStr:nil
  225. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  226. okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
  227. didClickOk:^{
  228. [weakSelf closeImageBackupsFun];
  229. } didClickCancel:^{
  230. }];
  231. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  232. [self presentViewController:nextVC animated:YES completion:^{
  233. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  234. }];
  235. }
  236. }
  237. - (void)checkFileTransferTask
  238. {//有个偶现的闪退在BGFMDB
  239. [[uploadFileManager shareInstance] checkHadUploadTaskWithComplete:^(BOOL isSuccess) {
  240. self->hadUploadTaskType = isSuccess;
  241. [self setRightButtonRedTypeFun];
  242. }];
  243. KWeakSelf
  244. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  245. [[downloadManager shareInstance] checkHadDownloadTaskWithComplete:^(BOOL isSuccess) {
  246. self->hadDownloadTaskType = isSuccess;
  247. [weakSelf setRightButtonRedTypeFun];
  248. }];
  249. });
  250. }
  251. - (void)setRightButtonRedTypeFun
  252. {
  253. mainBlock(^{
  254. if(self->hadUploadTaskType || self->hadDownloadTaskType){
  255. self->rightRedView.hidden = NO;
  256. }
  257. else{
  258. self->rightRedView.hidden = YES;
  259. }
  260. });
  261. }
  262. - (void)didiClikRightButGotoTransferListFun:(UIButton*)but
  263. {
  264. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  265. [self.navigationController pushViewController:vc animated:YES];
  266. }
  267. - (void)viewDidAppear:(BOOL)animated{
  268. [super viewDidAppear:animated];
  269. [self checkFileTransferTask];
  270. }
  271. @end