backupsOptionViewController.m 12 KB

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