backupsOptionViewController.m 14 KB

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