Apply OWSTableViewController to more views.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent dc3f07cb54
commit 81a4ebdaf5

@ -19,10 +19,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface AdvancedSettingsTableViewController () @interface AdvancedSettingsTableViewController ()
@property (nonatomic) UISwitch *enableLogSwitch;
@property (nonatomic) UISwitch *enableCensorshipCircumventionSwitch;
@property (nonatomic) Reachability *reachability; @property (nonatomic) Reachability *reachability;
@end @end
@ -37,17 +33,6 @@ NS_ASSUME_NONNULL_BEGIN
self.title = NSLocalizedString(@"SETTINGS_ADVANCED_TITLE", @""); self.title = NSLocalizedString(@"SETTINGS_ADVANCED_TITLE", @"");
self.enableLogSwitch = [UISwitch new];
[self.enableLogSwitch setOn:[PropertyListPreferences loggingIsEnabled]];
[self.enableLogSwitch addTarget:self
action:@selector(didToggleEnableLogSwitch:)
forControlEvents:UIControlEventValueChanged];
self.enableCensorshipCircumventionSwitch = [UISwitch new];
[self.enableCensorshipCircumventionSwitch addTarget:self
action:@selector(didToggleEnableCensorshipCircumventionSwitch:)
forControlEvents:UIControlEventValueChanged];
self.reachability = [Reachability reachabilityForInternetConnection]; self.reachability = [Reachability reachabilityForInternetConnection];
[self observeNotifications]; [self observeNotifications];
@ -103,18 +88,13 @@ NS_ASSUME_NONNULL_BEGIN
OWSTableSection *loggingSection = [OWSTableSection new]; OWSTableSection *loggingSection = [OWSTableSection new];
loggingSection.headerTitle = NSLocalizedString(@"LOGGING_SECTION", nil); loggingSection.headerTitle = NSLocalizedString(@"LOGGING_SECTION", nil);
[loggingSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ [loggingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"")
UITableViewCell *cell = [UITableViewCell new]; isOn:[PropertyListPreferences loggingIsEnabled]
cell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @""); target:weakSelf
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; selector:@selector(didToggleEnableLogSwitch:)]];
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryView = self.enableLogSwitch; if ([PropertyListPreferences loggingIsEnabled]) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
actionBlock:nil]];
if (self.enableLogSwitch.isOn) {
[loggingSection [loggingSection
addItem:[OWSTableItem actionItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"") addItem:[OWSTableItem actionItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"")
actionBlock:^{ actionBlock:^{
@ -167,41 +147,36 @@ NS_ASSUME_NONNULL_BEGIN
@"Table footer for the 'censorship circumvention' section when censorship circumvention can be manually " @"Table footer for the 'censorship circumvention' section when censorship circumvention can be manually "
@"enabled."); @"enabled.");
} }
[censorshipSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new]; // Do enable if :
cell.textLabel.text = NSLocalizedString( //
@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION", @"Label for the 'manual censorship circumvention' switch."); // * ...Censorship circumvention is already manually enabled (to allow users to disable it).
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; //
cell.textLabel.textColor = [UIColor blackColor]; // Otherwise, don't enable if:
//
// Do enable if : // * ...Censorship circumvention is already enabled based on the local phone number.
// // * ...The websocket is connected, since that demonstrates that no censorship is in effect.
// * ...Censorship circumvention is already manually enabled (to allow users to disable it). // * ...The internet is not reachable, since we don't want to let users to activate
// // censorship circumvention unnecessarily, e.g. if they just don't have a valid
// Otherwise, don't enable if: // internet connection.
// BOOL isManualCensorshipCircumventionOnEnabled
// * ...Censorship circumvention is already enabled based on the local phone number. = (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated
// * ...The websocket is connected, since that demonstrates that no censorship is in effect.
// * ...The internet is not reachable, since we don't want to let users to activate
// censorship circumvention unnecessarily, e.g. if they just don't have a valid
// internet connection.
BOOL shouldEnable = (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated
|| (!OWSSignalService.sharedInstance.hasCensoredPhoneNumber && || (!OWSSignalService.sharedInstance.hasCensoredPhoneNumber &&
[TSSocketManager sharedManager].state != SocketManagerStateOpen [TSSocketManager sharedManager].state != SocketManagerStateOpen
&& weakSelf.reachability.isReachable)); && weakSelf.reachability.isReachable));
weakSelf.enableCensorshipCircumventionSwitch.enabled = shouldEnable; BOOL isCensorshipCircumventionOn = NO;
if (OWSSignalService.sharedInstance.hasCensoredPhoneNumber) { if (OWSSignalService.sharedInstance.hasCensoredPhoneNumber) {
[weakSelf.enableCensorshipCircumventionSwitch setOn:YES]; isCensorshipCircumventionOn = YES;
} else { } else {
[weakSelf.enableCensorshipCircumventionSwitch isCensorshipCircumventionOn = OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated;
setOn:OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated];
}
cell.accessoryView = weakSelf.enableCensorshipCircumventionSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
} }
actionBlock:nil]]; [censorshipSection
addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION",
@"Label for the 'manual censorship circumvention' switch.")
isOn:isCensorshipCircumventionOn
isEnabled:isManualCensorshipCircumventionOnEnabled
target:weakSelf
selector:@selector(didToggleEnableCensorshipCircumventionSwitch:)]];
if (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated) { if (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated) {
[censorshipSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ [censorshipSection addItem:[OWSTableItem itemWithCustomCellBlock:^{

@ -55,23 +55,10 @@
OWSTableSection *inAppSection = [OWSTableSection new]; OWSTableSection *inAppSection = [OWSTableSection new];
inAppSection.headerTitle = NSLocalizedString(@"NOTIFICATIONS_SECTION_INAPP", nil); inAppSection.headerTitle = NSLocalizedString(@"NOTIFICATIONS_SECTION_INAPP", nil);
[inAppSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ [inAppSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"NOTIFICATIONS_SOUND", nil)
UITableViewCell *cell = [UITableViewCell new]; isOn:[prefs soundInForeground]
target:weakSelf
BOOL soundEnabled = [prefs soundInForeground]; selector:@selector(didToggleSoundNotificationsSwitch:)]];
[[cell textLabel] setText:NSLocalizedString(@"NOTIFICATIONS_SOUND", nil)];
UISwitch *soundSwitch = [UISwitch new];
soundSwitch.on = soundEnabled;
[soundSwitch addTarget:self
action:@selector(didToggleSoundNotificationsSwitch:)
forControlEvents:UIControlEventValueChanged];
cell.accessoryView = soundSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
actionBlock:nil]];
[contents addSection:inAppSection]; [contents addSection:inAppSection];
self.contents = contents; self.contents = contents;

@ -501,7 +501,10 @@ NS_ASSUME_NONNULL_BEGIN
if (!self.isGroupThread) { if (!self.isGroupThread) {
BOOL isBlocked = [[_blockingManager blockedPhoneNumbers] containsObject:self.thread.contactIdentifier]; BOOL isBlocked = [[_blockingManager blockedPhoneNumbers] containsObject:self.thread.contactIdentifier];
OWSTableItem *item = [OWSTableItem itemWithCustomCellBlock:^{ OWSTableSection *section = [OWSTableSection new];
section.footerTitle = NSLocalizedString(
@"BLOCK_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking another user.");
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = UITableViewCell *cell =
[weakSelf disclosureCellWithName:NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_USER", [weakSelf disclosureCellWithName:NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_USER",
@"table cell label in conversation settings") @"table cell label in conversation settings")
@ -516,13 +519,7 @@ NS_ASSUME_NONNULL_BEGIN
cell.accessoryView = blockUserSwitch; cell.accessoryView = blockUserSwitch;
return cell; return cell;
} }
actionBlock:nil]; actionBlock:nil]];
OWSTableSection *section = [OWSTableSection sectionWithTitle:nil
items:@[
item,
]];
section.footerTitle = NSLocalizedString(
@"BLOCK_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking another user.");
[contents addSection:section]; [contents addSection:section];
} }

@ -76,6 +76,14 @@ typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)();
+ (OWSTableItem *)labelItemWithText:(NSString *)text accessoryText:(NSString *)accessoryText; + (OWSTableItem *)labelItemWithText:(NSString *)text accessoryText:(NSString *)accessoryText;
+ (OWSTableItem *)switchItemWithText:(NSString *)text isOn:(BOOL)isOn target:(id)target selector:(SEL)selector;
+ (OWSTableItem *)switchItemWithText:(NSString *)text
isOn:(BOOL)isOn
isEnabled:(BOOL)isEnabled
target:(id)target
selector:(SEL)selector;
- (nullable UITableViewCell *)customCell; - (nullable UITableViewCell *)customCell;
- (NSNumber *)customRowHeight; - (NSNumber *)customRowHeight;

@ -240,6 +240,41 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f;
return item; return item;
} }
+ (OWSTableItem *)switchItemWithText:(NSString *)text isOn:(BOOL)isOn target:(id)target selector:(SEL)selector
{
return [self switchItemWithText:text isOn:isOn isEnabled:YES target:target selector:selector];
}
+ (OWSTableItem *)switchItemWithText:(NSString *)text
isOn:(BOOL)isOn
isEnabled:(BOOL)isEnabled
target:(id)target
selector:(SEL)selector
{
OWSAssert(text.length > 0);
OWSAssert(selector);
OWSTableItem *item = [OWSTableItem new];
item.itemType = OWSTableItemTypeAction;
item.customCellBlock = ^{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = text;
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
UISwitch *cellSwitch = [UISwitch new];
cell.accessoryView = cellSwitch;
[cellSwitch setOn:isOn];
[cellSwitch addTarget:target action:selector forControlEvents:UIControlEventValueChanged];
cellSwitch.enabled = isEnabled;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
};
return item;
}
- (nullable UITableViewCell *)customCell - (nullable UITableViewCell *)customCell
{ {
if (_customCell) { if (_customCell) {

@ -1,13 +1,9 @@
// //
// PrivacySettingsTableViewController.h // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Signal
//
// Created by Dylan Bourgeois on 05/01/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
// //
#import <UIKit/UIKit.h> #import "OWSTableViewController.h"
@interface PrivacySettingsTableViewController : UITableViewController @interface PrivacySettingsTableViewController : OWSTableViewController
@end @end

@ -7,234 +7,136 @@
#import "Environment.h" #import "Environment.h"
#import "PropertyListPreferences.h" #import "PropertyListPreferences.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "UIUtil.h"
#import <25519/Curve25519.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, PrivacySettingsTableViewControllerSectionIndex) {
PrivacySettingsTableViewControllerSectionIndexBlockList,
PrivacySettingsTableViewControllerSectionIndexScreenSecurity,
PrivacySettingsTableViewControllerSectionIndexCalling,
PrivacySettingsTableViewControllerSectionIndexCallKit,
PrivacySettingsTableViewControllerSectionIndexHistoryLog,
PrivacySettingsTableViewControllerSectionIndex_Count // meta section to track how many sections
};
@interface PrivacySettingsTableViewController ()
@property (nonatomic) UITableViewCell *blocklistCell;
@property (nonatomic) UITableViewCell *enableCallKitCell;
@property (nonatomic) UISwitch *enableCallKitSwitch;
@property (nonatomic) UITableViewCell *enableCallKitPrivacyCell;
@property (nonatomic) UISwitch *enableCallKitPrivacySwitch;
@property (nonatomic, strong) UITableViewCell *enableScreenSecurityCell;
@property (nonatomic, strong) UISwitch *enableScreenSecuritySwitch;
@property (nonatomic) UITableViewCell *callsHideIPAddressCell;
@property (nonatomic) UISwitch *callsHideIPAddressSwitch;
@property (nonatomic, strong) UITableViewCell *clearHistoryLogCell;
@end
@implementation PrivacySettingsTableViewController @implementation PrivacySettingsTableViewController
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[self.navigationController.navigationBar setTranslucent:NO];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
- (instancetype)init {
return [super initWithStyle:UITableViewStyleGrouped];
}
- (void)loadView {
[super loadView];
self.title = NSLocalizedString(@"SETTINGS_PRIVACY_TITLE", @""); self.title = NSLocalizedString(@"SETTINGS_PRIVACY_TITLE", @"");
// Block List [self updateTableContents];
self.blocklistCell = [UITableViewCell new];
self.blocklistCell.textLabel.text
= NSLocalizedString(@"SETTINGS_BLOCK_LIST_TITLE", @"Label for the block list section of the settings view");
self.blocklistCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// CallKit opt-out
self.enableCallKitCell = [UITableViewCell new];
self.enableCallKitCell.textLabel.text = NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_TITLE", @"Short table cell label");
self.enableCallKitSwitch = [UISwitch new];
[self.enableCallKitSwitch setOn:[[Environment getCurrent].preferences isCallKitEnabled]];
[self.enableCallKitSwitch addTarget:self
action:@selector(didToggleEnableCallKitSwitch:)
forControlEvents:UIControlEventValueChanged];
self.enableCallKitCell.accessoryView = self.enableCallKitSwitch;
// CallKit privacy
self.enableCallKitPrivacyCell = [UITableViewCell new];
self.enableCallKitPrivacyCell.textLabel.text = NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_PRIVACY_TITLE", @"Label for 'CallKit privacy' preference");
self.enableCallKitPrivacySwitch = [UISwitch new];
[self.enableCallKitPrivacySwitch setOn:![[Environment getCurrent].preferences isCallKitPrivacyEnabled]];
[self.enableCallKitPrivacySwitch addTarget:self
action:@selector(didToggleEnableCallKitPrivacySwitch:)
forControlEvents:UIControlEventValueChanged];
self.enableCallKitPrivacyCell.accessoryView = self.enableCallKitPrivacySwitch;
// Enable Screen Security Cell
self.enableScreenSecurityCell = [[UITableViewCell alloc] init];
self.enableScreenSecurityCell.textLabel.text = NSLocalizedString(@"SETTINGS_SCREEN_SECURITY", @"");
self.enableScreenSecuritySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
self.enableScreenSecurityCell.accessoryView = self.enableScreenSecuritySwitch;
self.enableScreenSecurityCell.userInteractionEnabled = YES;
[self.enableScreenSecuritySwitch setOn:[Environment.preferences screenSecurityIsEnabled]];
[self.enableScreenSecuritySwitch addTarget:self
action:@selector(didToggleScreenSecuritySwitch:)
forControlEvents:UIControlEventValueChanged];
// Allow calls to connect directly vs. using TURN exclusively
self.callsHideIPAddressCell = [UITableViewCell new];
self.callsHideIPAddressCell.textLabel.text
= NSLocalizedString(@"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE", @"Table cell label");
self.callsHideIPAddressSwitch = [UISwitch new];
self.callsHideIPAddressCell.accessoryView = self.callsHideIPAddressSwitch;
[self.callsHideIPAddressSwitch setOn:[Environment.preferences doCallsHideIPAddress]];
[self.callsHideIPAddressSwitch addTarget:self
action:@selector(didToggleCallsHideIPAddressSwitch:)
forControlEvents:UIControlEventValueChanged];
// Clear History Log Cell
self.clearHistoryLogCell = [[UITableViewCell alloc] init];
self.clearHistoryLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_CLEAR_HISTORY", @"");
self.clearHistoryLogCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} }
#pragma mark - Table view data source - (void)viewDidAppear:(BOOL)animated
{
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { [self updateTableContents];
return PrivacySettingsTableViewControllerSectionIndex_Count;
} }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { #pragma mark - Table Contents
switch (section) {
case PrivacySettingsTableViewControllerSectionIndexBlockList:
return 1;
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity:
return 1;
case PrivacySettingsTableViewControllerSectionIndexCalling:
return 1;
case PrivacySettingsTableViewControllerSectionIndexCallKit:
if (![UIDevice currentDevice].supportsCallKit) {
return 0;
}
return [Environment getCurrent].preferences.isCallKitEnabled ? 2 : 1;
case PrivacySettingsTableViewControllerSectionIndexHistoryLog:
return 1;
default:
return 0;
}
}
- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section - (void)updateTableContents
{ {
switch (section) { OWSTableContents *contents = [OWSTableContents new];
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity:
return NSLocalizedString(@"SETTINGS_SCREEN_SECURITY_DETAIL", nil); __weak PrivacySettingsTableViewController *weakSelf = self;
case PrivacySettingsTableViewControllerSectionIndexCalling:
return NSLocalizedString(@"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE_DETAIL", [contents
@"User settings section footer, a detailed explanation"); addSection:[OWSTableSection
case PrivacySettingsTableViewControllerSectionIndexCallKit: sectionWithTitle:nil
return ([UIDevice currentDevice].supportsCallKit items:@[
? NSLocalizedString(@"SETTINGS_SECTION_CALL_KIT_DESCRIPTION", @"Settings table section footer.") [OWSTableItem disclosureItemWithText:
: nil); NSLocalizedString(@"SETTINGS_BLOCK_LIST_TITLE",
default: @"Label for the block list section of the settings view")
return nil; actionBlock:^{
} [weakSelf showBlocklist];
} }],
]]];
OWSTableSection *screenSecuritySection = [OWSTableSection new];
screenSecuritySection.headerTitle = NSLocalizedString(@"SETTINGS_SECURITY_TITLE", @"Section header");
screenSecuritySection.footerTitle = NSLocalizedString(@"SETTINGS_SCREEN_SECURITY_DETAIL", nil);
// TODO: Apply switchItemWithText.
[screenSecuritySection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_SCREEN_SECURITY", @"")
isOn:[Environment.preferences screenSecurityIsEnabled]
target:weakSelf
selector:@selector(didToggleScreenSecuritySwitch:)]];
[contents addSection:screenSecuritySection];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Allow calls to connect directly vs. using TURN exclusively
switch (indexPath.section) { OWSTableSection *callingSection = [OWSTableSection new];
case PrivacySettingsTableViewControllerSectionIndexBlockList: callingSection.headerTitle
return self.blocklistCell; = NSLocalizedString(@"SETTINGS_SECTION_TITLE_CALLING", @"settings topic header for table section");
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity: callingSection.footerTitle = NSLocalizedString(@"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE_DETAIL",
return self.enableScreenSecurityCell; @"User settings section footer, a detailed explanation");
case PrivacySettingsTableViewControllerSectionIndexCalling: [callingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(
return self.callsHideIPAddressCell; @"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE",
case PrivacySettingsTableViewControllerSectionIndexCallKit: @"Table cell label")
switch (indexPath.row) { isOn:[Environment.preferences doCallsHideIPAddress]
case 0: target:weakSelf
return self.enableCallKitCell; selector:@selector(didToggleCallsHideIPAddressSwitch:)]];
case 1: [contents addSection:callingSection];
return self.enableCallKitPrivacyCell;
} if ([UIDevice currentDevice].supportsCallKit) {
case PrivacySettingsTableViewControllerSectionIndexHistoryLog: OWSTableSection *callKitSection = [OWSTableSection new];
return self.clearHistoryLogCell; callKitSection.footerTitle
default: { = NSLocalizedString(@"SETTINGS_SECTION_CALL_KIT_DESCRIPTION", @"Settings table section footer.");
DDLogError(@"%@ Requested unknown table view cell for row at indexPath: %@", self.tag, indexPath); [callKitSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_TITLE",
return [UITableViewCell new]; @"Short table cell label")
isOn:[Environment.preferences isCallKitEnabled]
target:weakSelf
selector:@selector(didToggleEnableCallKitSwitch:)]];
if (Environment.preferences.isCallKitEnabled) {
[callKitSection
addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_PRIVACY_TITLE",
@"Label for 'CallKit privacy' preference")
isOn:[Environment.preferences isCallKitPrivacyEnabled]
target:weakSelf
selector:@selector(didToggleEnableCallKitPrivacySwitch:)]];
} }
[contents addSection:callKitSection];
} }
OWSTableSection *historyLogsSection = [OWSTableSection new];
historyLogsSection.headerTitle = NSLocalizedString(@"SETTINGS_HISTORYLOG_TITLE", @"Section header");
[historyLogsSection addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"SETTINGS_CLEAR_HISTORY", @"")
actionBlock:^{
[weakSelf clearHistoryLogs];
}]];
[contents addSection:historyLogsSection];
self.contents = contents;
} }
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section #pragma mark - Events
- (void)showBlocklist
{ {
switch (section) { BlockListViewController *vc = [BlockListViewController new];
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity: [self.navigationController pushViewController:vc animated:YES];
return NSLocalizedString(@"SETTINGS_SECURITY_TITLE", @"Section header");
case PrivacySettingsTableViewControllerSectionIndexCalling:
return NSLocalizedString(@"SETTINGS_SECTION_TITLE_CALLING", @"settings topic header for table section");
case PrivacySettingsTableViewControllerSectionIndexHistoryLog:
return NSLocalizedString(@"SETTINGS_HISTORYLOG_TITLE", @"Section header");
default:
return nil;
}
} }
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.section) { - (void)clearHistoryLogs
case PrivacySettingsTableViewControllerSectionIndexBlockList: { {
BlockListViewController *vc = [[BlockListViewController alloc] init]; UIAlertController *alertController =
NSAssert(self.navigationController != nil, @"Navigation controller must not be nil"); [UIAlertController alertControllerWithTitle:nil
NSAssert(vc != nil, @"About View Controller must not be nil"); message:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION",
[self.navigationController pushViewController:vc animated:YES]; @"Alert message before user confirms clearing history")
break; preferredStyle:UIAlertControllerStyleAlert];
}
case PrivacySettingsTableViewControllerSectionIndexHistoryLog: { UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"")
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil style:UIAlertActionStyleCancel
message:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION", @"Alert message before user confirms clearing history") handler:nil];
preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:dismissAction];
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"") UIAlertAction *deleteAction =
style:UIAlertActionStyleCancel [UIAlertAction actionWithTitle:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION_BUTTON", @"")
handler:nil]; style:UIAlertActionStyleDestructive
[alertController addAction:dismissAction]; handler:^(UIAlertAction *_Nonnull action) {
[[TSStorageManager sharedManager] deleteThreadsAndMessages];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION_BUTTON", @"") }];
style:UIAlertActionStyleDestructive [alertController addAction:deleteAction];
handler:^(UIAlertAction * _Nonnull action) {
[[TSStorageManager sharedManager] deleteThreadsAndMessages]; [self presentViewController:alertController animated:true completion:nil];
}];
[alertController addAction:deleteAction];
[self presentViewController:alertController animated:true completion:nil];
break;
}
default:
break;
}
} }
#pragma mark - Toggle
- (void)didToggleScreenSecuritySwitch:(UISwitch *)sender - (void)didToggleScreenSecuritySwitch:(UISwitch *)sender
{ {
BOOL enabled = self.enableScreenSecuritySwitch.isOn; BOOL enabled = sender.isOn;
DDLogInfo(@"%@ toggled screen security: %@", self.tag, enabled ? @"ON" : @"OFF"); DDLogInfo(@"%@ toggled screen security: %@", self.tag, enabled ? @"ON" : @"OFF");
[Environment.preferences setScreenSecurity:enabled]; [Environment.preferences setScreenSecurity:enabled];
} }
@ -251,7 +153,7 @@ typedef NS_ENUM(NSInteger, PrivacySettingsTableViewControllerSectionIndex) {
[[Environment getCurrent].preferences setIsCallKitEnabled:sender.isOn]; [[Environment getCurrent].preferences setIsCallKitEnabled:sender.isOn];
// rebuild callUIAdapter since CallKit vs not changed. // rebuild callUIAdapter since CallKit vs not changed.
[[Environment getCurrent].callService createCallUIAdapter]; [[Environment getCurrent].callService createCallUIAdapter];
[self.tableView reloadData]; [self updateTableContents];
} }
- (void)didToggleEnableCallKitPrivacySwitch:(UISwitch *)sender { - (void)didToggleEnableCallKitPrivacySwitch:(UISwitch *)sender {

Loading…
Cancel
Save