WFCSettingTableViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. //
  2. // SettingTableViewController.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/6.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCSettingTableViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <SDWebImage/SDWebImage.h>
  11. #import <WFChatUIKit/WFChatUIKit.h>
  12. #import "WFCSecurityTableViewController.h"
  13. #import "WFCAboutViewController.h"
  14. #import "WFCPrivacyViewController.h"
  15. #import "WFCPrivacyTableViewController.h"
  16. #import "WFCDiagnoseViewController.h"
  17. #import "UIColor+YH.h"
  18. #import "UIFont+YH.h"
  19. #import "WFCThemeTableViewController.h"
  20. #import "AppService.h"
  21. #import "OrgService.h"
  22. #import "WFCDestroyAccountViewController.h"
  23. #import "SSKeychain.h"
  24. @interface WFCSettingTableViewController () <UITableViewDataSource, UITableViewDelegate>
  25. @property (nonatomic, strong)UITableView *tableView;
  26. @end
  27. @implementation WFCSettingTableViewController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
  31. if (@available(iOS 15, *)) {
  32. self.tableView.sectionHeaderTopPadding = 0;
  33. }
  34. self.tableView.delegate = self;
  35. self.tableView.dataSource = self;
  36. self.tableView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  37. self.title = LocalizedString(@"Settings");
  38. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.1)];
  39. [self.tableView reloadData];
  40. [self.view addSubview:self.tableView];
  41. }
  42. - (void)didReceiveMemoryWarning {
  43. [super didReceiveMemoryWarning];
  44. // Dispose of any resources that can be recreated.
  45. }
  46. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  47. return 48;
  48. }
  49. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  50. if (indexPath.section == 0) {
  51. WFCPrivacyTableViewController *pvc = [[WFCPrivacyTableViewController alloc] init];
  52. pvc.hidesBottomBarWhenPushed = YES;
  53. [self.navigationController pushViewController:pvc animated:YES];
  54. }else if(indexPath.section == 1) {
  55. WFCThemeTableViewController *vc = [[WFCThemeTableViewController alloc] init];
  56. [self.navigationController pushViewController:vc animated:YES];
  57. } else if (indexPath.section == 2) {
  58. if (indexPath.row == 1) {
  59. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  60. mvc.conversation = [[WFCCConversation alloc] init];
  61. mvc.conversation.type = Single_Type;
  62. mvc.conversation.target = @"cgc8c8VV";
  63. mvc.conversation.line = 0;
  64. mvc.hidesBottomBarWhenPushed = YES;
  65. [self.navigationController pushViewController:mvc animated:YES];
  66. } else if (indexPath.row == 2) {
  67. WFCAboutViewController *avc = [[WFCAboutViewController alloc] init];
  68. [self.navigationController pushViewController:avc animated:YES];
  69. }
  70. } else if(indexPath.section == 3) {
  71. if (indexPath.row == 0) {
  72. WFCPrivacyViewController * pvc = [[WFCPrivacyViewController alloc] init];
  73. pvc.isPrivacy = NO;
  74. [self.navigationController pushViewController:pvc animated:YES];
  75. } else if(indexPath.row == 1) {
  76. WFCPrivacyViewController * pvc = [[WFCPrivacyViewController alloc] init];
  77. pvc.isPrivacy = YES;
  78. [self.navigationController pushViewController:pvc animated:YES];
  79. }
  80. } else if(indexPath.section == 4) {
  81. __weak typeof(self)ws = self;
  82. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"举报" message:@"如果您发现有违反法律和道德的内容,或者您的合法权益受到侵犯,请截图之后发送给我们。我们会在24小时之内处理。处理办法包括不限于删除内容,对作者进行警告,冻结账号,甚至报警处理。举报请到\"设置->设置->举报\"联系我们!" preferredStyle:UIAlertControllerStyleAlert];
  83. UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  84. }];
  85. [alertController addAction:action1];
  86. UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"举报" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  87. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  88. mvc.conversation = [[WFCCConversation alloc] init];
  89. mvc.conversation.type = Single_Type;
  90. mvc.conversation.target = @"cgc8c8VV";
  91. mvc.conversation.line = 0;
  92. mvc.hidesBottomBarWhenPushed = YES;
  93. [ws.navigationController pushViewController:mvc animated:YES];
  94. }];
  95. [alertController addAction:action2];
  96. [self presentViewController:alertController animated:YES completion:nil];
  97. } else if (indexPath.section == 5) {
  98. WFCDiagnoseViewController *vc = [[WFCDiagnoseViewController alloc] init];
  99. [self.navigationController pushViewController:vc animated:YES];
  100. }
  101. }
  102. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  103. if (section == 0) {
  104. return 0.01;
  105. } else {
  106. return 9;
  107. }
  108. }
  109. - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
  110. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  111. }
  112. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  113. if (section == 0) {
  114. return nil;
  115. } else {
  116. UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 9)];
  117. v.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  118. return v;
  119. }
  120. }
  121. //#pragma mark - Table view data source
  122. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  123. return 7;
  124. }
  125. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  126. if (section == 0) {
  127. return 1;
  128. } else if (section == 1) {
  129. return 1; //
  130. } else if (section == 2) {
  131. return 3; //
  132. } else if (section == 3) {
  133. return 2; // 用户协议和隐私声明
  134. } else if (section == 4) {
  135. return 1; //举报
  136. } else if (section == 5) {
  137. return 1; //diagnose
  138. } else if (section == 6) {
  139. return 1; //logout
  140. }
  141. return 0;
  142. }
  143. - (UIEdgeInsets)hiddenSeparatorLine:(UITableViewCell *)cell {
  144. return cell.separatorInset = UIEdgeInsetsMake(self.view.frame.size.width, 0, 0, 0);
  145. }
  146. - (void)showSeparatorLine:(UITableViewCell *)cell {
  147. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  148. }
  149. - (void)setLastCellSeperatorToLeft:(UITableViewCell*) cell
  150. {
  151. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  152. [cell setSeparatorInset:UIEdgeInsetsZero];
  153. }
  154. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  155. [cell setLayoutMargins:UIEdgeInsetsZero];
  156. }
  157. if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
  158. [cell setPreservesSuperviewLayoutMargins:NO];
  159. }
  160. }
  161. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  162. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"style1Cell"];
  163. if (cell == nil) {
  164. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"style1Cell"];
  165. }
  166. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  167. cell.accessoryView = nil;
  168. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  169. if(indexPath.section == 0) {
  170. cell.textLabel.text = LocalizedString(@"PrivacySettings");
  171. [self hiddenSeparatorLine:cell];
  172. } else if(indexPath.section == 1) {
  173. cell.textLabel.text = LocalizedString(@"Theme");
  174. [self hiddenSeparatorLine:cell];
  175. } else if(indexPath.section == 2) {
  176. if (indexPath.row == 0) {
  177. [self showSeparatorLine:cell];
  178. cell.textLabel.text = LocalizedString(@"CurrentVersion");
  179. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@(%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"], [[WFCCNetworkService sharedInstance] getProtoRevision]];
  180. cell.accessoryType = UITableViewCellAccessoryNone;
  181. } if (indexPath.row == 1) {
  182. cell.textLabel.text = LocalizedString(@"HelpFeedback");
  183. [self showSeparatorLine:cell];
  184. } else if (indexPath.row == 2) {
  185. cell.textLabel.text = LocalizedString(@"AboutWFChat");
  186. [self hiddenSeparatorLine:cell];
  187. }
  188. } else if(indexPath.section == 3) {
  189. if (indexPath.row == 0) {
  190. cell.textLabel.text = LocalizedString(@"UserAgreement");
  191. [self showSeparatorLine:cell];
  192. } if (indexPath.row == 1) {
  193. cell.textLabel.text = LocalizedString(@"PrivacyPolicy");
  194. [self hiddenSeparatorLine:cell];
  195. }
  196. } else if(indexPath.section == 4) {
  197. if (indexPath.row == 0) {
  198. [self hiddenSeparatorLine:cell];
  199. cell.textLabel.text = LocalizedString(@"Complain");
  200. }
  201. } else if (indexPath.section == 5) {
  202. [self hiddenSeparatorLine:cell];
  203. cell.textLabel.text = LocalizedString(@"Diagnose");
  204. } else if (indexPath.section == 6) {
  205. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  206. for (UIView *subView in cell.subviews) {
  207. [subView removeFromSuperview];
  208. }
  209. [self setLastCellSeperatorToLeft:cell];
  210. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 48)];
  211. [btn setTitle:LocalizedString(@"Logout") forState:UIControlStateNormal];
  212. [btn addTarget:self action:@selector(onLogoutBtn:) forControlEvents:UIControlEventTouchUpInside];
  213. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  214. [btn setTitleColor:[UIColor colorWithHexString:@"0xf95569"]
  215. forState:UIControlStateNormal];
  216. if (@available(iOS 14, *)) {
  217. [cell.contentView addSubview:btn];
  218. } else {
  219. [cell addSubview:btn];
  220. }
  221. }
  222. return cell;
  223. }
  224. - (void)onLogoutBtn:(id)sender {
  225. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:LocalizedString(@"Quit") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  226. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:LocalizedString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  227. }];
  228. UIAlertAction *actionLogout = [UIAlertAction actionWithTitle:LocalizedString(@"Logout") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  229. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"savedName"];
  230. [SSKeychain deletePasswordForWFService:@"savedToken"];
  231. [SSKeychain deletePasswordForWFService:@"savedUserId"];
  232. [[AppService sharedAppService] clearAppServiceAuthInfos];
  233. [[OrgService sharedOrgService] clearOrgServiceAuthInfos];
  234. [[NSUserDefaults standardUserDefaults] synchronize];
  235. //退出后就不需要推送了,第一个参数为YES
  236. //如果希望再次登录时能够保留历史记录,第二个参数为NO。如果需要清除掉本地历史记录第二个参数用YES
  237. [[WFCCNetworkService sharedInstance] disconnect:YES clearSession:NO];
  238. }];
  239. UIAlertAction *actionDestroy = [UIAlertAction actionWithTitle:LocalizedString(@"DestroyAccount") style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  240. WFCDestroyAccountViewController *destroyVC = [[WFCDestroyAccountViewController alloc] init];
  241. [self.navigationController pushViewController:destroyVC animated:YES];
  242. }];
  243. //把action添加到actionSheet里
  244. [actionSheet addAction:actionLogout];
  245. [actionSheet addAction:actionDestroy];
  246. [actionSheet addAction:actionCancel];
  247. //相当于之前的[actionSheet show];
  248. [self presentViewController:actionSheet animated:YES completion:nil];
  249. }
  250. @end