BSetViewController.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //
  2. // BSetViewController.m
  3. // HappyJob
  4. //
  5. // Created by 张晓光 on 2019/7/4.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "BSetViewController.h"
  9. #import "BMyListCell.h"
  10. #import "BIdentitySwitchViewController.h"//身份切换
  11. #import "HJConfirmPanelViewController.h"//退出登录
  12. #import "HJLoginViewController.h"
  13. @interface BSetViewController ()<UITableViewDelegate,UITableViewDataSource>
  14. @property (nonatomic, strong) UITableView *tableView;
  15. @property (nonatomic, strong) UIButton *exitBtn;
  16. @end
  17. @implementation BSetViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.title = @"设置";
  21. [self hj_setupWhiteColorNavBar];
  22. [self autoLayOutViews];
  23. }
  24. #pragma mark - UITableView
  25. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  26. return 2 ;
  27. }
  28. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  29. static NSString *listCell = @"listCell";
  30. BMyListCell *cell = [tableView dequeueReusableCellWithIdentifier:listCell];
  31. if (cell == nil)
  32. {
  33. cell = [[BMyListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:listCell];
  34. }
  35. if (indexPath.row == 0)
  36. {
  37. cell.titleLabel.text = @"清除缓存";
  38. cell.leftImageV.image = [UIImage imageNamed:@"b_set_clear"];
  39. cell.rightLabel.text = [NSString stringWithFormat:@"%.2fMB",[self folderSize]];
  40. }
  41. if (indexPath.row == 1)
  42. {
  43. cell.titleLabel.text = @"切换身份";
  44. cell.leftImageV.image = [UIImage imageNamed:@"b_set_ID"];
  45. cell.rightLabel.text = @"";
  46. }
  47. return cell;
  48. }
  49. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  50. if (indexPath.row == 0)
  51. {
  52. [self removeCache];
  53. }
  54. if (indexPath.row == 1)
  55. {
  56. BIdentitySwitchViewController *vc = [[BIdentitySwitchViewController alloc]init];
  57. [self.navigationController pushViewController:vc animated:YES];
  58. }
  59. }
  60. /*
  61. *缓存大小
  62. */
  63. - (CGFloat)folderSize {
  64. CGFloat folderSize = 0.0;
  65. //获取路径
  66. NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)firstObject];
  67. //获取所有文件的数组
  68. NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachePath];
  69. for(NSString *path in files)
  70. {
  71. NSString*filePath = [cachePath stringByAppendingString:[NSString stringWithFormat:@"/%@",path]];
  72. //累加
  73. folderSize += [[NSFileManager defaultManager]attributesOfItemAtPath:filePath error:nil].fileSize;
  74. }
  75. //转换为M为单位
  76. CGFloat sizeM = folderSize /1024.0/1024.0;
  77. return sizeM;
  78. }
  79. /*
  80. *清除缓存
  81. */
  82. - (void)removeCache {
  83. NSString*cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)objectAtIndex:0];
  84. //返回路径中的文件数组
  85. NSArray*files = [[NSFileManager defaultManager]subpathsAtPath:cachePath];
  86. for(NSString *p in files)
  87. {
  88. NSError*error;
  89. NSString*path = [cachePath stringByAppendingString:[NSString stringWithFormat:@"/%@",p]];
  90. if([[NSFileManager defaultManager]fileExistsAtPath:path])
  91. {
  92. BOOL isRemove = [[NSFileManager defaultManager]removeItemAtPath:path error:&error];
  93. if(isRemove)
  94. {
  95. dispatch_async(dispatch_get_main_queue(), ^{
  96. //主线程刷新
  97. [self.tableView reloadData];
  98. [self.view fb_showSuccessWithStatus:@"清除成功"];
  99. });
  100. }
  101. }
  102. }
  103. }
  104. /* 退出登录*/
  105. - (void)exitButtonClick {
  106. HJConfirmPanelViewController *vc = [[HJConfirmPanelViewController alloc] init];
  107. vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  108. vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
  109. self.navigationController.definesPresentationContext = NO;
  110. vc.titleLabel.text = @"是否退出登录状态?";
  111. vc.titleIcon.image = nil;
  112. [vc.cancelButton setTitle:@"返回" forState:UIControlStateNormal];
  113. [vc.confirmButton setTitle:@"退出登录" forState:UIControlStateNormal];
  114. [vc.confirmButton addTarget:self
  115. action:@selector(logoutConfirmButtonClicked:)
  116. forControlEvents:UIControlEventTouchUpInside];
  117. [self presentViewController:vc animated:YES completion:nil];
  118. }
  119. - (void)logoutConfirmButtonClicked:(UIButton *)sender {
  120. [self dismissViewControllerAnimated:NO completion:^{
  121. // 清空所有本地用户信息
  122. [[HJAppUserType sharedInstance] loginoutType];
  123. [[HJAppUserType sharedInstance] saveUserType];
  124. [HJUserInfoModel clear];
  125. AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  126. [appdelegate switchTabBar];
  127. }];
  128. }
  129. #pragma mark - setter&getter
  130. - (void)autoLayOutViews {
  131. __weak typeof(self) weakSelf = self;
  132. [self.view addSubview:self.tableView];
  133. [self.view addSubview:self.exitBtn];
  134. self.view.backgroundColor = COLOR_GRAYFA;
  135. self.tableView.bounces = NO;
  136. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  137. make.left.right.offset(0);
  138. make.top.equalTo(weakSelf.view).offset(NAVIGATION_H);
  139. make.height.mas_equalTo(200);
  140. }];
  141. [self.exitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.centerX.equalTo(weakSelf.view);
  143. make.bottom.equalTo(weakSelf.view).offset(-64);
  144. make.size.mas_offset(CGSizeMake(280, 50));
  145. }];
  146. self.exitBtn.layer.cornerRadius = 50/2;
  147. self.exitBtn.layer.masksToBounds = YES;
  148. }
  149. - (UITableView *)tableView {
  150. if (_tableView == nil)
  151. {
  152. _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  153. _tableView.delegate = self;
  154. _tableView.dataSource = self;
  155. _tableView.separatorStyle = NO;
  156. _tableView.rowHeight = UITableViewAutomaticDimension;
  157. _tableView.backgroundColor = COLOR_GRAYFA;
  158. _tableView.estimatedRowHeight = 10.0;
  159. }
  160. return _tableView;
  161. }
  162. - (UIButton *)exitBtn {
  163. if (_exitBtn == nil)
  164. {
  165. _exitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  166. [_exitBtn setTitle:@"退出登录" forState:UIControlStateNormal];
  167. _exitBtn.titleLabel.font = [UIFont systemFontOfSize:17];
  168. _exitBtn.backgroundColor = COLOR_DEFAULT;
  169. [_exitBtn addTarget:self action:@selector(exitButtonClick) forControlEvents:UIControlEventTouchUpInside];
  170. [_exitBtn az_setGradientBackgroundWithColors:@[[UIColor colorFromHexString:@"219BEE"],[UIColor colorFromHexString:@"2BB0F5"]] locations:@[@(0.0),@(1.0f)] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  171. }
  172. return _exitBtn;
  173. }
  174. /*
  175. #pragma mark - Navigation
  176. // In a storyboard-based application, you will often want to do a little preparation before navigation
  177. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  178. // Get the new view controller using [segue destinationViewController].
  179. // Pass the selected object to the new view controller.
  180. }
  181. */
  182. @end