SettingViewController.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // SettingViewController.m
  3. // DSH
  4. //
  5. // Created by 张毅成 on 2018/9/26.
  6. // Copyright © 2018 WZX. All rights reserved.
  7. //
  8. #import "SettingViewController.h"
  9. #import "SettingModel.h"
  10. #import "MyDetailTableViewCell.h"
  11. #import "LoginViewController.h"
  12. #import "FeedbackViewController.h"
  13. #import <SDWebImage/SDImageCache.h>
  14. #import "AboutViewController.h"
  15. //#import "JPUSHService.h"
  16. #import "AccountAndSecurityViewController.h"
  17. #import "BlacklistViewController.h"
  18. @interface SettingViewController ()<UITableViewDelegate, UITableViewDataSource>
  19. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  20. @property (weak, nonatomic) IBOutlet UIButton *buttonLogOut;
  21. @property (assign, nonatomic) BOOL haveCache;
  22. @end
  23. @implementation SettingViewController
  24. - (void)Network {
  25. SHOWLOADING
  26. NSString *URL = @"my/logOut";
  27. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  28. // [NetWorkRequest postJSONWithUrl:URL parameters:parameters success:^(id result) {
  29. // NSLog(@"%@",result);
  30. // REMOVESHOW
  31. // if ([result[@"code"] integerValue] == 0) {
  32. // [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"nickname"];
  33. // [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"headimgurl"];
  34. // [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"userId"];
  35. // [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"LOGINTOKEN"];
  36. // [[NSUserDefaults standardUserDefaults] setBool:false forKey:@"isLogin"];
  37. // [[NSUserDefaults standardUserDefaults] synchronize];
  38. // [self.navigationController popToRootViewControllerAnimated:false];
  39. // [[NSNotificationCenter defaultCenter] postNotificationName:@"pushToLogin" object:nil];
  40. // [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadBookCase" object:nil];
  41. // [JPUSHService setAlias:@"" completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {} seq:0];
  42. // }
  43. // } fail:^(NSError *error) {
  44. // REMOVESHOW
  45. // }];
  46. }
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. self.title = @"设置";
  50. self.view.backgroundColor = kBackgroundColor;
  51. [self.buttonLogOut setCorner];
  52. [self.buttonLogOut addEventHandler:^(id sender) {
  53. [ZYCTool alertControllerTwoButtonWithTitle:@"确认退出?" message:@"" target:self notarizeButtonTitle:nil cancelButtonTitle:nil notarizeAction:^{
  54. [self Network];
  55. } cancelAction:^{}];
  56. } forControlEvents:(UIControlEventTouchUpInside)];
  57. [self createTableView];
  58. }
  59. - (void)createTableView {
  60. self.tableView.delegate = self;
  61. self.tableView.dataSource = self;
  62. self.tableView.tableFooterView = [UIView new];
  63. self.tableView.rowHeight = UITableViewAutomaticDimension;
  64. self.tableView.estimatedRowHeight = 60;
  65. self.tableView.backgroundColor = kBackgroundColor;
  66. self.tableView.scrollEnabled = false;
  67. }
  68. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  69. return 10;
  70. }
  71. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  72. return 0.01;
  73. }
  74. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  75. UIView *view = [UIView new];
  76. view.backgroundColor = kBackgroundColor;
  77. return view;
  78. }
  79. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  80. UIView *view = [UIView new];
  81. view.backgroundColor = kBackgroundColor;
  82. return view;
  83. }
  84. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  85. return SettingModel.arrayData.count;
  86. }
  87. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  88. NSArray *array = SettingModel.arrayData[section];
  89. return array.count;
  90. }
  91. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  92. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  93. [cell setSeparatorInset:UIEdgeInsetsZero];
  94. }
  95. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  96. [cell setLayoutMargins:UIEdgeInsetsZero];
  97. }
  98. if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  99. [cell setPreservesSuperviewLayoutMargins:NO];
  100. }
  101. }
  102. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  103. MyDetailTableViewCell *cell = [MyDetailTableViewCell cellWithTableView:tableView];
  104. [cell setDataWithModel:SettingModel.arrayData[indexPath.section][indexPath.row]];
  105. cell.labelDetail.text = @"";
  106. if (indexPath.section == 1) {
  107. cell.labelDetail.text = [self checkCache];
  108. [cell.labelDetail setTextColor:[UIColor hexStringToColor:@"999999"]];
  109. }
  110. return cell;
  111. }
  112. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  113. if (indexPath.section == 0) {//账号与安全
  114. AccountAndSecurityViewController *controller = [AccountAndSecurityViewController new];
  115. controller.modelMy = self.modelMy;
  116. [self.navigationController pushViewController:controller animated:true];
  117. }else if (indexPath.section == 1) {//清理缓存
  118. if (self.haveCache) {
  119. [ZYCTool alertControllerTwoButtonWithTitle:@"是否清理缓存?" message:@"" target:self notarizeButtonTitle:nil cancelButtonTitle:nil notarizeAction:^{
  120. [[SDImageCache sharedImageCache] clearMemory];
  121. [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
  122. }];
  123. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  124. [self.tableView reloadData];
  125. });
  126. } cancelAction:^{}];
  127. }else
  128. SHOWSUCCESS(@"暂无缓存")
  129. }else if (indexPath.section == 2) {//黑名单
  130. BlacklistViewController *controller = [BlacklistViewController new];
  131. [self.navigationController pushViewController:controller animated:true];
  132. }else if (indexPath.section == 3) {
  133. if (indexPath.row == 0) {//意见反馈
  134. FeedbackViewController *controller = [FeedbackViewController new];
  135. controller.controllerType = FeedbackViewControllerTypeFeedback;
  136. controller.URL = @"my/sendSuggestion";
  137. [self.navigationController pushViewController:controller animated:true];
  138. }else{//关于我们
  139. AboutViewController *controller = [AboutViewController new];
  140. [self.navigationController pushViewController:controller animated:true];
  141. }
  142. }
  143. }
  144. - (NSString *)checkCache {
  145. float tmpSize = [[SDImageCache sharedImageCache] totalDiskSize];
  146. NSLog(@"%f",tmpSize);
  147. if (tmpSize > 0) {
  148. self.haveCache = true;
  149. }else
  150. self.haveCache = false;
  151. if (tmpSize >= 1024*1024*1024) {
  152. return [NSString stringWithFormat:@"(%0.2fG)",tmpSize /(1024.f*1024.f*1024.f)];
  153. }else if (tmpSize >= 1024*1024) {
  154. return [NSString stringWithFormat:@"%0.2fM",tmpSize /(1024.f*1024.f)];
  155. }else{
  156. return [NSString stringWithFormat:@"%0.2fK",tmpSize / 1024.f];
  157. }
  158. }
  159. @end