From 81a4ebdaf57a16f1a88078fb4880ea447b53f4a6 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 14 Jul 2017 10:55:49 -0400 Subject: [PATCH] Apply OWSTableViewController to more views. // FREEBIE --- .../AdvancedSettingsTableViewController.m | 91 ++---- .../NotificationSettingsViewController.m | 21 +- ...SConversationSettingsTableViewController.m | 13 +- .../ViewControllers/OWSTableViewController.h | 8 + .../ViewControllers/OWSTableViewController.m | 35 ++ .../PrivacySettingsTableViewController.h | 10 +- .../PrivacySettingsTableViewController.m | 302 ++++++------------ 7 files changed, 190 insertions(+), 290 deletions(-) diff --git a/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m b/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m index a120ebe06..8fdb8f2bf 100644 --- a/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m +++ b/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m @@ -19,10 +19,6 @@ NS_ASSUME_NONNULL_BEGIN @interface AdvancedSettingsTableViewController () -@property (nonatomic) UISwitch *enableLogSwitch; - -@property (nonatomic) UISwitch *enableCensorshipCircumventionSwitch; - @property (nonatomic) Reachability *reachability; @end @@ -37,17 +33,6 @@ NS_ASSUME_NONNULL_BEGIN 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 observeNotifications]; @@ -103,18 +88,13 @@ NS_ASSUME_NONNULL_BEGIN OWSTableSection *loggingSection = [OWSTableSection new]; loggingSection.headerTitle = NSLocalizedString(@"LOGGING_SECTION", nil); - [loggingSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ - UITableViewCell *cell = [UITableViewCell new]; - cell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @""); - cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; - cell.textLabel.textColor = [UIColor blackColor]; - - cell.accessoryView = self.enableLogSwitch; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - return cell; - } - actionBlock:nil]]; - if (self.enableLogSwitch.isOn) { + [loggingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"") + isOn:[PropertyListPreferences loggingIsEnabled] + target:weakSelf + selector:@selector(didToggleEnableLogSwitch:)]]; + + + if ([PropertyListPreferences loggingIsEnabled]) { [loggingSection addItem:[OWSTableItem actionItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"") actionBlock:^{ @@ -167,41 +147,36 @@ NS_ASSUME_NONNULL_BEGIN @"Table footer for the 'censorship circumvention' section when censorship circumvention can be manually " @"enabled."); } - [censorshipSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ - UITableViewCell *cell = [UITableViewCell new]; - cell.textLabel.text = NSLocalizedString( - @"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION", @"Label for the 'manual censorship circumvention' switch."); - cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; - cell.textLabel.textColor = [UIColor blackColor]; - - // Do enable if : - // - // * ...Censorship circumvention is already manually enabled (to allow users to disable it). - // - // Otherwise, don't 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. - // * ...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 + + // Do enable if : + // + // * ...Censorship circumvention is already manually enabled (to allow users to disable it). + // + // Otherwise, don't 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. + // * ...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 isManualCensorshipCircumventionOnEnabled + = (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated || (!OWSSignalService.sharedInstance.hasCensoredPhoneNumber && [TSSocketManager sharedManager].state != SocketManagerStateOpen && weakSelf.reachability.isReachable)); - weakSelf.enableCensorshipCircumventionSwitch.enabled = shouldEnable; - if (OWSSignalService.sharedInstance.hasCensoredPhoneNumber) { - [weakSelf.enableCensorshipCircumventionSwitch setOn:YES]; - } else { - [weakSelf.enableCensorshipCircumventionSwitch - setOn:OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated]; - } - - cell.accessoryView = weakSelf.enableCensorshipCircumventionSwitch; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - return cell; + BOOL isCensorshipCircumventionOn = NO; + if (OWSSignalService.sharedInstance.hasCensoredPhoneNumber) { + isCensorshipCircumventionOn = YES; + } else { + isCensorshipCircumventionOn = OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated; } - 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) { [censorshipSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ diff --git a/Signal/src/ViewControllers/NotificationSettingsViewController.m b/Signal/src/ViewControllers/NotificationSettingsViewController.m index 00b7746f9..3435e89a2 100644 --- a/Signal/src/ViewControllers/NotificationSettingsViewController.m +++ b/Signal/src/ViewControllers/NotificationSettingsViewController.m @@ -55,23 +55,10 @@ OWSTableSection *inAppSection = [OWSTableSection new]; inAppSection.headerTitle = NSLocalizedString(@"NOTIFICATIONS_SECTION_INAPP", nil); - [inAppSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ - UITableViewCell *cell = [UITableViewCell new]; - - BOOL soundEnabled = [prefs soundInForeground]; - - [[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]]; + [inAppSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"NOTIFICATIONS_SOUND", nil) + isOn:[prefs soundInForeground] + target:weakSelf + selector:@selector(didToggleSoundNotificationsSwitch:)]]; [contents addSection:inAppSection]; self.contents = contents; diff --git a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m index b5bbcab80..a5c100836 100644 --- a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m +++ b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m @@ -501,7 +501,10 @@ NS_ASSUME_NONNULL_BEGIN if (!self.isGroupThread) { 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 = [weakSelf disclosureCellWithName:NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_USER", @"table cell label in conversation settings") @@ -516,13 +519,7 @@ NS_ASSUME_NONNULL_BEGIN cell.accessoryView = blockUserSwitch; return cell; } - actionBlock:nil]; - OWSTableSection *section = [OWSTableSection sectionWithTitle:nil - items:@[ - item, - ]]; - section.footerTitle = NSLocalizedString( - @"BLOCK_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking another user."); + actionBlock:nil]]; [contents addSection:section]; } diff --git a/Signal/src/ViewControllers/OWSTableViewController.h b/Signal/src/ViewControllers/OWSTableViewController.h index 645d73545..eb4d63dc6 100644 --- a/Signal/src/ViewControllers/OWSTableViewController.h +++ b/Signal/src/ViewControllers/OWSTableViewController.h @@ -76,6 +76,14 @@ typedef UITableViewCell *_Nonnull (^OWSTableCustomCellBlock)(); + (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; - (NSNumber *)customRowHeight; diff --git a/Signal/src/ViewControllers/OWSTableViewController.m b/Signal/src/ViewControllers/OWSTableViewController.m index 4bd6e546d..f9f3eab75 100644 --- a/Signal/src/ViewControllers/OWSTableViewController.m +++ b/Signal/src/ViewControllers/OWSTableViewController.m @@ -240,6 +240,41 @@ const CGFloat kOWSTable_DefaultCellHeight = 45.f; 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 { if (_customCell) { diff --git a/Signal/src/ViewControllers/PrivacySettingsTableViewController.h b/Signal/src/ViewControllers/PrivacySettingsTableViewController.h index 7cd519e33..7912c0d89 100644 --- a/Signal/src/ViewControllers/PrivacySettingsTableViewController.h +++ b/Signal/src/ViewControllers/PrivacySettingsTableViewController.h @@ -1,13 +1,9 @@ // -// PrivacySettingsTableViewController.h -// Signal -// -// Created by Dylan Bourgeois on 05/01/15. -// Copyright (c) 2015 Open Whisper Systems. All rights reserved. +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import +#import "OWSTableViewController.h" -@interface PrivacySettingsTableViewController : UITableViewController +@interface PrivacySettingsTableViewController : OWSTableViewController @end diff --git a/Signal/src/ViewControllers/PrivacySettingsTableViewController.m b/Signal/src/ViewControllers/PrivacySettingsTableViewController.m index d7f6c2c7b..8f272c0f3 100644 --- a/Signal/src/ViewControllers/PrivacySettingsTableViewController.m +++ b/Signal/src/ViewControllers/PrivacySettingsTableViewController.m @@ -7,234 +7,136 @@ #import "Environment.h" #import "PropertyListPreferences.h" #import "Signal-Swift.h" -#import "UIUtil.h" -#import <25519/Curve25519.h> 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 - (void)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", @""); - // Block List - 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; + [self updateTableContents]; } -#pragma mark - Table view data source - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return PrivacySettingsTableViewControllerSectionIndex_Count; +- (void)viewDidAppear:(BOOL)animated +{ + [self updateTableContents]; } -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - 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; - } -} +#pragma mark - Table Contents -- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section +- (void)updateTableContents { - switch (section) { - case PrivacySettingsTableViewControllerSectionIndexScreenSecurity: - return NSLocalizedString(@"SETTINGS_SCREEN_SECURITY_DETAIL", nil); - case PrivacySettingsTableViewControllerSectionIndexCalling: - return NSLocalizedString(@"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE_DETAIL", - @"User settings section footer, a detailed explanation"); - case PrivacySettingsTableViewControllerSectionIndexCallKit: - return ([UIDevice currentDevice].supportsCallKit - ? NSLocalizedString(@"SETTINGS_SECTION_CALL_KIT_DESCRIPTION", @"Settings table section footer.") - : nil); - default: - return nil; - } -} + OWSTableContents *contents = [OWSTableContents new]; + + __weak PrivacySettingsTableViewController *weakSelf = self; + + [contents + addSection:[OWSTableSection + sectionWithTitle:nil + items:@[ + [OWSTableItem disclosureItemWithText: + NSLocalizedString(@"SETTINGS_BLOCK_LIST_TITLE", + @"Label for the block list section of the settings view") + 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 { - switch (indexPath.section) { - case PrivacySettingsTableViewControllerSectionIndexBlockList: - return self.blocklistCell; - case PrivacySettingsTableViewControllerSectionIndexScreenSecurity: - return self.enableScreenSecurityCell; - case PrivacySettingsTableViewControllerSectionIndexCalling: - return self.callsHideIPAddressCell; - case PrivacySettingsTableViewControllerSectionIndexCallKit: - switch (indexPath.row) { - case 0: - return self.enableCallKitCell; - case 1: - return self.enableCallKitPrivacyCell; - } - case PrivacySettingsTableViewControllerSectionIndexHistoryLog: - return self.clearHistoryLogCell; - default: { - DDLogError(@"%@ Requested unknown table view cell for row at indexPath: %@", self.tag, indexPath); - return [UITableViewCell new]; + // Allow calls to connect directly vs. using TURN exclusively + OWSTableSection *callingSection = [OWSTableSection new]; + callingSection.headerTitle + = NSLocalizedString(@"SETTINGS_SECTION_TITLE_CALLING", @"settings topic header for table section"); + callingSection.footerTitle = NSLocalizedString(@"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE_DETAIL", + @"User settings section footer, a detailed explanation"); + [callingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString( + @"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE", + @"Table cell label") + isOn:[Environment.preferences doCallsHideIPAddress] + target:weakSelf + selector:@selector(didToggleCallsHideIPAddressSwitch:)]]; + [contents addSection:callingSection]; + + if ([UIDevice currentDevice].supportsCallKit) { + OWSTableSection *callKitSection = [OWSTableSection new]; + callKitSection.footerTitle + = NSLocalizedString(@"SETTINGS_SECTION_CALL_KIT_DESCRIPTION", @"Settings table section footer."); + [callKitSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_TITLE", + @"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) { - case PrivacySettingsTableViewControllerSectionIndexScreenSecurity: - 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; - } + BlockListViewController *vc = [BlockListViewController new]; + [self.navigationController pushViewController:vc animated:YES]; } -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - [tableView deselectRowAtIndexPath:indexPath animated:YES]; - switch (indexPath.section) { - case PrivacySettingsTableViewControllerSectionIndexBlockList: { - BlockListViewController *vc = [[BlockListViewController alloc] init]; - NSAssert(self.navigationController != nil, @"Navigation controller must not be nil"); - NSAssert(vc != nil, @"About View Controller must not be nil"); - [self.navigationController pushViewController:vc animated:YES]; - break; - } - case PrivacySettingsTableViewControllerSectionIndexHistoryLog: { - UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil - message:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION", @"Alert message before user confirms clearing history") - preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"") - style:UIAlertActionStyleCancel - handler:nil]; - [alertController addAction:dismissAction]; - - UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION_BUTTON", @"") - style:UIAlertActionStyleDestructive - handler:^(UIAlertAction * _Nonnull action) { - [[TSStorageManager sharedManager] deleteThreadsAndMessages]; - }]; - [alertController addAction:deleteAction]; - - [self presentViewController:alertController animated:true completion:nil]; - break; - } - default: - break; - } +- (void)clearHistoryLogs +{ + UIAlertController *alertController = + [UIAlertController alertControllerWithTitle:nil + message:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION", + @"Alert message before user confirms clearing history") + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"") + style:UIAlertActionStyleCancel + handler:nil]; + [alertController addAction:dismissAction]; + + UIAlertAction *deleteAction = + [UIAlertAction actionWithTitle:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION_BUTTON", @"") + style:UIAlertActionStyleDestructive + handler:^(UIAlertAction *_Nonnull action) { + [[TSStorageManager sharedManager] deleteThreadsAndMessages]; + }]; + [alertController addAction:deleteAction]; + + [self presentViewController:alertController animated:true completion:nil]; } -#pragma mark - Toggle - - (void)didToggleScreenSecuritySwitch:(UISwitch *)sender { - BOOL enabled = self.enableScreenSecuritySwitch.isOn; + BOOL enabled = sender.isOn; DDLogInfo(@"%@ toggled screen security: %@", self.tag, enabled ? @"ON" : @"OFF"); [Environment.preferences setScreenSecurity:enabled]; } @@ -251,7 +153,7 @@ typedef NS_ENUM(NSInteger, PrivacySettingsTableViewControllerSectionIndex) { [[Environment getCurrent].preferences setIsCallKitEnabled:sender.isOn]; // rebuild callUIAdapter since CallKit vs not changed. [[Environment getCurrent].callService createCallUIAdapter]; - [self.tableView reloadData]; + [self updateTableContents]; } - (void)didToggleEnableCallKitPrivacySwitch:(UISwitch *)sender {