Merge branch 'charlesmchen/moreOWSTables'

pull/1/head
Matthew Chen 8 years ago
commit 5552649553

@ -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;
cell.selectionStyle = UITableViewCellSelectionStyleNone; if ([PropertyListPreferences loggingIsEnabled]) {
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,12 +147,6 @@ 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];
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 : // Do enable if :
// //
@ -185,23 +159,24 @@ NS_ASSUME_NONNULL_BEGIN
// * ...The internet is not reachable, since we don't want to let users to activate // * ...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 // censorship circumvention unnecessarily, e.g. if they just don't have a valid
// internet connection. // internet connection.
BOOL shouldEnable = (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated BOOL isManualCensorshipCircumventionOnEnabled
= (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:^{

@ -1,13 +1,9 @@
// //
// NotificationSettingsOptionsViewController.h // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Signal
//
// Created by Frederic Jacobs on 24/04/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
// //
#import <UIKit/UIKit.h> #import "OWSTableViewController.h"
@interface NotificationSettingsOptionsViewController : UITableViewController @interface NotificationSettingsOptionsViewController : OWSTableViewController
@end @end

@ -6,53 +6,49 @@
#import "Environment.h" #import "Environment.h"
#import "PropertyListPreferences.h" #import "PropertyListPreferences.h"
@interface NotificationSettingsOptionsViewController ()
@property NSArray *options;
@end
@implementation NotificationSettingsOptionsViewController @implementation NotificationSettingsOptionsViewController
- (void)viewDidLoad { - (void)viewDidLoad {
self.options = @[ @(NotificationNamePreview), @(NotificationNameNoPreview), @(NotificationNoNameNoPreview) ]; [self updateTableContents];
[super viewDidLoad];
} }
#pragma mark - Table view data source #pragma mark - Table Contents
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - (void)updateTableContents
return 1; {
} OWSTableContents *contents = [OWSTableContents new];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { __weak NotificationSettingsOptionsViewController *weakSelf = self;
return (NSInteger)[self.options count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { OWSTableSection *section = [OWSTableSection new];
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 section.footerTitle = NSLocalizedString(@"NOTIFICATIONS_FOOTER_WARNING", nil);
reuseIdentifier:@"NotificationSettingsOption"];
PropertyListPreferences *prefs = [Environment preferences];
NSUInteger notifType = [[self.options objectAtIndex:(NSUInteger)indexPath.row] unsignedIntegerValue];
[[cell textLabel] setText:[prefs nameForNotificationPreviewType:notifType]];
PropertyListPreferences *prefs = [Environment preferences];
NotificationType selectedNotifType = [prefs notificationPreviewType]; NotificationType selectedNotifType = [prefs notificationPreviewType];
for (NSNumber *option in
if (selectedNotifType == notifType) { @[ @(NotificationNamePreview), @(NotificationNameNoPreview), @(NotificationNoNameNoPreview) ]) {
NotificationType notificationType = (NotificationType)option.intValue;
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new];
[[cell textLabel] setText:[prefs nameForNotificationPreviewType:notificationType]];
if (selectedNotifType == notificationType) {
cell.accessoryType = UITableViewCellAccessoryCheckmark; cell.accessoryType = UITableViewCellAccessoryCheckmark;
} }
return cell; return cell;
} }
actionBlock:^{
[weakSelf setNotificationType:notificationType];
}]];
}
[contents addSection:section];
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { self.contents = contents;
return NSLocalizedString(@"NOTIFICATIONS_FOOTER_WARNING", nil);
} }
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - (void)setNotificationType:(NotificationType)notificationType
[Environment.preferences {
setNotificationPreviewType:[[self.options objectAtIndex:(NSUInteger)indexPath.row] unsignedIntegerValue]]; [Environment.preferences setNotificationPreviewType:notificationType];
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }

@ -1,13 +1,9 @@
// //
// NotificationPreviewViewController.h // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Signal
//
// Created by Dylan Bourgeois on 09/12/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
// //
#import <UIKit/UIKit.h> #import "OWSTableViewController.h"
@interface NotificationSettingsViewController : UITableViewController @interface NotificationSettingsViewController : OWSTableViewController
@end @end

@ -7,110 +7,67 @@
#import "NotificationSettingsOptionsViewController.h" #import "NotificationSettingsOptionsViewController.h"
#import "PropertyListPreferences.h" #import "PropertyListPreferences.h"
#define kNotificationOptionSection 0
@interface NotificationSettingsViewController ()
@property NSArray *notificationsSections;
@end
@implementation NotificationSettingsViewController @implementation NotificationSettingsViewController
- (instancetype)init {
return [super initWithStyle:UITableViewStyleGrouped];
}
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[self setTitle:NSLocalizedString(@"SETTINGS_NOTIFICATIONS", nil)]; [self setTitle:NSLocalizedString(@"SETTINGS_NOTIFICATIONS", nil)];
self.notificationsSections = @[ [self updateTableContents];
NSLocalizedString(@"NOTIFICATIONS_SECTION_BACKGROUND", nil),
NSLocalizedString(@"NOTIFICATIONS_SECTION_INAPP", nil)
];
} }
- (void)viewDidAppear:(BOOL)animated { - (void)viewDidAppear:(BOOL)animated {
[self.tableView reloadData]; [self updateTableContents];
} }
#pragma mark - Table view data source #pragma mark - Table Contents
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - (void)updateTableContents
return [self.notificationsSections objectAtIndex:(NSUInteger)section]; {
} OWSTableContents *contents = [OWSTableContents new];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { __weak NotificationSettingsViewController *weakSelf = self;
return (NSInteger)self.notificationsSections.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { PropertyListPreferences *prefs = [Environment preferences];
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { OWSTableSection *backgroundSection = [OWSTableSection new];
NSString *cellIdentifier = @"SignalTableViewCellIdentifier"; backgroundSection.headerTitle = NSLocalizedString(@"NOTIFICATIONS_SECTION_BACKGROUND", nil);
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; [backgroundSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:@"UITableViewCellStyleValue1"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}
PropertyListPreferences *prefs = Environment.preferences;
if (indexPath.section == kNotificationOptionSection) {
NotificationType notifType = [prefs notificationPreviewType]; NotificationType notifType = [prefs notificationPreviewType];
NSString *detailString = [prefs nameForNotificationPreviewType:notifType]; NSString *detailString = [prefs nameForNotificationPreviewType:notifType];
[[cell textLabel] setText:NSLocalizedString(@"NOTIFICATIONS_SHOW", nil)]; [[cell textLabel] setText:NSLocalizedString(@"NOTIFICATIONS_SHOW", nil)];
[[cell detailTextLabel] setText:detailString]; [[cell detailTextLabel] setText:detailString];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
} else {
BOOL soundEnabled = [prefs soundInForeground];
[[cell textLabel] setText:NSLocalizedString(@"NOTIFICATIONS_SOUND", nil)];
[[cell detailTextLabel] setText:nil];
UISwitch *switchv = [[UISwitch alloc] initWithFrame:CGRectZero];
switchv.on = soundEnabled;
[switchv addTarget:self
action:@selector(didToggleSoundNotificationsSwitch:)
forControlEvents:UIControlEventValueChanged];
cell.accessoryView = switchv;
}
return cell; return cell;
} }
actionBlock:^{
NotificationSettingsOptionsViewController *vc =
[NotificationSettingsOptionsViewController new];
[weakSelf.navigationController pushViewController:vc animated:YES];
}]];
[contents addSection:backgroundSection];
- (void)didToggleSoundNotificationsSwitch:(UISwitch *)sender { OWSTableSection *inAppSection = [OWSTableSection new];
[Environment.preferences setSoundInForeground:sender.on]; inAppSection.headerTitle = NSLocalizedString(@"NOTIFICATIONS_SECTION_INAPP", nil);
} [inAppSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"NOTIFICATIONS_SOUND", nil)
isOn:[prefs soundInForeground]
target:weakSelf
selector:@selector(didToggleSoundNotificationsSwitch:)]];
[contents addSection:inAppSection];
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { self.contents = contents;
switch (indexPath.section) {
case kNotificationOptionSection: {
return indexPath;
}
default: {
return nil;
}
}
} }
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { #pragma mark - Events
switch (indexPath.section) {
case kNotificationOptionSection: {
NotificationSettingsOptionsViewController *vc =
[[NotificationSettingsOptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:vc animated:YES];
break;
}
}
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { - (void)didToggleSoundNotificationsSwitch:(UISwitch *)sender {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; [Environment.preferences setSoundInForeground:sender.on];
cell.accessoryType = UITableViewCellAccessoryNone;
} }
@end @end

@ -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,207 +7,114 @@
#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];
} }],
]]];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) { OWSTableSection *screenSecuritySection = [OWSTableSection new];
case PrivacySettingsTableViewControllerSectionIndexBlockList: screenSecuritySection.headerTitle = NSLocalizedString(@"SETTINGS_SECURITY_TITLE", @"Section header");
return self.blocklistCell; screenSecuritySection.footerTitle = NSLocalizedString(@"SETTINGS_SCREEN_SECURITY_DETAIL", nil);
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity: [screenSecuritySection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_SCREEN_SECURITY", @"")
return self.enableScreenSecurityCell; isOn:[Environment.preferences screenSecurityIsEnabled]
case PrivacySettingsTableViewControllerSectionIndexCalling: target:weakSelf
return self.callsHideIPAddressCell; selector:@selector(didToggleScreenSecuritySwitch:)]];
case PrivacySettingsTableViewControllerSectionIndexCallKit: [contents addSection:screenSecuritySection];
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];
}
}
}
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section // 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;
}
#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;
}
case PrivacySettingsTableViewControllerSectionIndexHistoryLog: {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
message:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION", @"Alert message before user confirms clearing history")
preferredStyle:UIAlertControllerStyleAlert]; preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"") UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"")
@ -215,7 +122,8 @@ typedef NS_ENUM(NSInteger, PrivacySettingsTableViewControllerSectionIndex) {
handler:nil]; handler:nil];
[alertController addAction:dismissAction]; [alertController addAction:dismissAction];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION_BUTTON", @"") UIAlertAction *deleteAction =
[UIAlertAction actionWithTitle:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION_BUTTON", @"")
style:UIAlertActionStyleDestructive style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *_Nonnull action) { handler:^(UIAlertAction *_Nonnull action) {
[[TSStorageManager sharedManager] deleteThreadsAndMessages]; [[TSStorageManager sharedManager] deleteThreadsAndMessages];
@ -223,18 +131,11 @@ typedef NS_ENUM(NSInteger, PrivacySettingsTableViewControllerSectionIndex) {
[alertController addAction:deleteAction]; [alertController addAction:deleteAction];
[self presentViewController:alertController animated:true completion:nil]; [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 +152,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