WFCPrivacyTableViewController.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // WFCPrivacyTableViewController.h
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/6.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCPrivacyTableViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <WFChatUIKit/WFChatUIKit.h>
  11. #import "WFCPrivacyFindMeViewController.h"
  12. #define BLACK_LIST_CELL_TAG 1
  13. #define MOMENTS_CELL_TAG 2
  14. #define FIND_ME_TAG 3
  15. @interface WFCPrivacyTableViewController () <UITableViewDataSource, UITableViewDelegate>
  16. @property (nonatomic, strong)UITableView *tableView;
  17. @property (nonatomic, strong)NSMutableArray<NSMutableArray<UITableViewCell *> *> *cells;
  18. @end
  19. @implementation WFCPrivacyTableViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.view.backgroundColor = [UIColor whiteColor];
  23. [self createCells];
  24. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
  25. if (@available(iOS 15, *)) {
  26. self.tableView.sectionHeaderTopPadding = 0;
  27. }
  28. self.tableView.delegate = self;
  29. self.tableView.dataSource = self;
  30. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  31. [self.tableView reloadData];
  32. [self.view addSubview:self.tableView];
  33. }
  34. - (void)createCells {
  35. self.cells = [[NSMutableArray alloc] init];
  36. //Section 0
  37. {
  38. NSMutableArray *section0 = [[NSMutableArray alloc] init];
  39. [self.cells addObject:section0];
  40. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"find_me"];
  41. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  42. cell.accessoryView = nil;
  43. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  44. cell.textLabel.text = @"找到我的方式";
  45. cell.tag = FIND_ME_TAG;
  46. [section0 addObject:cell];
  47. }
  48. //Section 1
  49. {
  50. NSMutableArray *section1 = [[NSMutableArray alloc] init];
  51. [self.cells addObject:section1];
  52. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell_black_list"];
  53. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  54. cell.accessoryView = nil;
  55. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  56. cell.textLabel.text = LocalizedString(@"Blacklist");
  57. cell.tag = BLACK_LIST_CELL_TAG;
  58. [section1 addObject:cell];
  59. }
  60. if([[WFCCIMService sharedWFCIMService] isEnableSecretChat] || [[WFCCIMService sharedWFCIMService] isReceiptEnabled]) {
  61. NSMutableArray *section2 = [[NSMutableArray alloc] init];
  62. [self.cells addObject:section2];
  63. if ([[WFCCIMService sharedWFCIMService] isReceiptEnabled]) {
  64. WFCUGeneralSwitchTableViewCell *switchCell = [[WFCUGeneralSwitchTableViewCell alloc] init];
  65. switchCell.textLabel.text = LocalizedString(@"MsgReceipt");
  66. if ([[WFCCIMService sharedWFCIMService] isUserEnableReceipt]) {
  67. switchCell.on = YES;
  68. } else {
  69. switchCell.on = NO;
  70. }
  71. __weak typeof(self)ws = self;
  72. [switchCell setOnSwitch:^(BOOL value, int type, void (^result)(BOOL success)) {
  73. [[WFCCIMService sharedWFCIMService] setUserEnableReceipt:value success:^{
  74. result(YES);
  75. } error:^(int error_code) {
  76. [ws.view makeToast:@"网络错误"];
  77. result(NO);
  78. }];
  79. }];
  80. [section2 addObject:switchCell];
  81. }
  82. if ([[WFCCIMService sharedWFCIMService] isEnableSecretChat]) {
  83. WFCUGeneralSwitchTableViewCell *switchCell = [[WFCUGeneralSwitchTableViewCell alloc] init];
  84. switchCell.textLabel.text = @"密聊";
  85. if ([[WFCCIMService sharedWFCIMService] isUserEnableSecretChat]) {
  86. switchCell.on = YES;
  87. } else {
  88. switchCell.on = NO;
  89. }
  90. __weak typeof(self)ws = self;
  91. [switchCell setOnSwitch:^(BOOL value, int type, void (^result)(BOOL success)) {
  92. [[WFCCIMService sharedWFCIMService] setUserEnableSecretChat:value success:^{
  93. result(YES);
  94. } error:^(int error_code) {
  95. [ws.view makeToast:@"网络错误"];
  96. result(NO);
  97. }];
  98. }];
  99. [section2 addObject:switchCell];
  100. }
  101. }
  102. //sections3
  103. if (NSClassFromString(@"MomentSettingsTableViewController")) {
  104. NSMutableArray *section3 = [[NSMutableArray alloc] init];
  105. [self.cells addObject:section3];
  106. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"moments_cell"];
  107. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  108. cell.accessoryView = nil;
  109. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  110. cell.textLabel.text = LocalizedString(@"Moments");
  111. cell.tag = MOMENTS_CELL_TAG;
  112. [section3 addObject:cell];
  113. }
  114. {
  115. NSMutableArray *section4 = [[NSMutableArray alloc] init];
  116. [self.cells addObject:section4];
  117. WFCUGeneralSwitchTableViewCell *switchCell = [[WFCUGeneralSwitchTableViewCell alloc] init];
  118. switchCell.textLabel.text = @"加我为好友时需要验证";
  119. if ([[WFCCIMService sharedWFCIMService] isAddFriendNeedVerify]) {
  120. switchCell.on = YES;
  121. } else {
  122. switchCell.on = NO;
  123. }
  124. __weak typeof(self)ws = self;
  125. [switchCell setOnSwitch:^(BOOL value, int type, void (^result)(BOOL success)) {
  126. [[WFCCIMService sharedWFCIMService] setAddFriendNeedVerify:value success:^{
  127. result(YES);
  128. } error:^(int error_code) {
  129. [ws.view makeToast:@"网络错误"];
  130. result(NO);
  131. }];
  132. }];
  133. [section4 addObject:switchCell];
  134. }
  135. }
  136. - (void)didReceiveMemoryWarning {
  137. [super didReceiveMemoryWarning];
  138. // Dispose of any resources that can be recreated.
  139. }
  140. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  141. return 48;
  142. }
  143. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  144. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  145. if (cell.tag == BLACK_LIST_CELL_TAG) {
  146. WFCUBlackListViewController *vc = [[WFCUBlackListViewController alloc] init];
  147. [self.navigationController pushViewController:vc animated:YES];
  148. } else if(cell.tag == MOMENTS_CELL_TAG) {
  149. UIViewController *vc = [[NSClassFromString(@"MomentSettingsTableViewController") alloc] init];
  150. [self.navigationController pushViewController:vc animated:YES];
  151. } else if(cell.tag == FIND_ME_TAG) {
  152. UIViewController *vc = [[WFCPrivacyFindMeViewController alloc] init];
  153. [self.navigationController pushViewController:vc animated:YES];
  154. }
  155. }
  156. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  157. return [[UIView alloc] initWithFrame:CGRectZero];
  158. }
  159. //#pragma mark - Table view data source
  160. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  161. return self.cells.count;
  162. }
  163. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  164. return self.cells[section].count;
  165. }
  166. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  167. return self.cells[indexPath.section][indexPath.row];
  168. }
  169. @end