WFCSettingTableViewController.m 11 KB

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