backupsOptionViewController.m 12 KB

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