123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- //
- // WFCPrivacyTableViewController.h
- // WFChat UIKit
- //
- // Created by WF Chat on 2017/10/6.
- // Copyright © 2017年 WildFireChat. All rights reserved.
- //
- #import "WFCPrivacyTableViewController.h"
- #import <WFChatClient/WFCChatClient.h>
- #import <WFChatUIKit/WFChatUIKit.h>
- #import "WFCPrivacyFindMeViewController.h"
- #define BLACK_LIST_CELL_TAG 1
- #define MOMENTS_CELL_TAG 2
- #define FIND_ME_TAG 3
- @interface WFCPrivacyTableViewController () <UITableViewDataSource, UITableViewDelegate>
- @property (nonatomic, strong)UITableView *tableView;
- @property (nonatomic, strong)NSMutableArray<NSMutableArray<UITableViewCell *> *> *cells;
- @end
- @implementation WFCPrivacyTableViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- [self createCells];
-
- self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
- if (@available(iOS 15, *)) {
- self.tableView.sectionHeaderTopPadding = 0;
- }
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
-
- self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- [self.tableView reloadData];
-
- [self.view addSubview:self.tableView];
-
- }
- - (void)createCells {
- self.cells = [[NSMutableArray alloc] init];
-
- //Section 0
- {
- NSMutableArray *section0 = [[NSMutableArray alloc] init];
- [self.cells addObject:section0];
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"find_me"];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.accessoryView = nil;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.textLabel.text = @"找到我的方式";
- cell.tag = FIND_ME_TAG;
- [section0 addObject:cell];
- }
-
- //Section 1
- {
- NSMutableArray *section1 = [[NSMutableArray alloc] init];
- [self.cells addObject:section1];
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell_black_list"];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.accessoryView = nil;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.textLabel.text = LocalizedString(@"Blacklist");
- cell.tag = BLACK_LIST_CELL_TAG;
- [section1 addObject:cell];
- }
-
- if([[WFCCIMService sharedWFCIMService] isEnableSecretChat] || [[WFCCIMService sharedWFCIMService] isReceiptEnabled]) {
- NSMutableArray *section2 = [[NSMutableArray alloc] init];
- [self.cells addObject:section2];
- if ([[WFCCIMService sharedWFCIMService] isReceiptEnabled]) {
- WFCUGeneralSwitchTableViewCell *switchCell = [[WFCUGeneralSwitchTableViewCell alloc] init];
- switchCell.textLabel.text = LocalizedString(@"MsgReceipt");
- if ([[WFCCIMService sharedWFCIMService] isUserEnableReceipt]) {
- switchCell.on = YES;
- } else {
- switchCell.on = NO;
- }
- __weak typeof(self)ws = self;
- [switchCell setOnSwitch:^(BOOL value, int type, void (^result)(BOOL success)) {
- [[WFCCIMService sharedWFCIMService] setUserEnableReceipt:value success:^{
- result(YES);
- } error:^(int error_code) {
- [ws.view makeToast:@"网络错误"];
- result(NO);
- }];
- }];
- [section2 addObject:switchCell];
- }
-
- if ([[WFCCIMService sharedWFCIMService] isEnableSecretChat]) {
- WFCUGeneralSwitchTableViewCell *switchCell = [[WFCUGeneralSwitchTableViewCell alloc] init];
- switchCell.textLabel.text = @"密聊";
- if ([[WFCCIMService sharedWFCIMService] isUserEnableSecretChat]) {
- switchCell.on = YES;
- } else {
- switchCell.on = NO;
- }
- __weak typeof(self)ws = self;
- [switchCell setOnSwitch:^(BOOL value, int type, void (^result)(BOOL success)) {
- [[WFCCIMService sharedWFCIMService] setUserEnableSecretChat:value success:^{
- result(YES);
- } error:^(int error_code) {
- [ws.view makeToast:@"网络错误"];
- result(NO);
- }];
- }];
- [section2 addObject:switchCell];
- }
- }
- //sections3
- if (NSClassFromString(@"MomentSettingsTableViewController")) {
- NSMutableArray *section3 = [[NSMutableArray alloc] init];
- [self.cells addObject:section3];
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"moments_cell"];
-
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.accessoryView = nil;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.textLabel.text = LocalizedString(@"Moments");
- cell.tag = MOMENTS_CELL_TAG;
- [section3 addObject:cell];
- }
-
- {
- NSMutableArray *section4 = [[NSMutableArray alloc] init];
- [self.cells addObject:section4];
-
- WFCUGeneralSwitchTableViewCell *switchCell = [[WFCUGeneralSwitchTableViewCell alloc] init];
- switchCell.textLabel.text = @"加我为好友时需要验证";
- if ([[WFCCIMService sharedWFCIMService] isAddFriendNeedVerify]) {
- switchCell.on = YES;
- } else {
- switchCell.on = NO;
- }
- __weak typeof(self)ws = self;
- [switchCell setOnSwitch:^(BOOL value, int type, void (^result)(BOOL success)) {
- [[WFCCIMService sharedWFCIMService] setAddFriendNeedVerify:value success:^{
- result(YES);
- } error:^(int error_code) {
- [ws.view makeToast:@"网络错误"];
- result(NO);
- }];
- }];
- [section4 addObject:switchCell];
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 48;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- if (cell.tag == BLACK_LIST_CELL_TAG) {
- WFCUBlackListViewController *vc = [[WFCUBlackListViewController alloc] init];
- [self.navigationController pushViewController:vc animated:YES];
- } else if(cell.tag == MOMENTS_CELL_TAG) {
- UIViewController *vc = [[NSClassFromString(@"MomentSettingsTableViewController") alloc] init];
- [self.navigationController pushViewController:vc animated:YES];
- } else if(cell.tag == FIND_ME_TAG) {
- UIViewController *vc = [[WFCPrivacyFindMeViewController alloc] init];
- [self.navigationController pushViewController:vc animated:YES];
- }
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- return [[UIView alloc] initWithFrame:CGRectZero];
- }
- //#pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return self.cells.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.cells[section].count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- return self.cells[indexPath.section][indexPath.row];
- }
- @end
|