session-ios/Signal/src/view controllers/PrivacySettingsTableViewController.m

200 lines
8.2 KiB
Mathematica
Raw Normal View History

//
2017-02-17 23:30:49 +01:00
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "PrivacySettingsTableViewController.h"
#import "Environment.h"
#import "PropertyListPreferences.h"
#import "UIUtil.h"
2017-02-17 23:30:49 +01:00
#import "UIViewController+OWS.h"
#import <25519/Curve25519.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, PrivacySettingsTableViewControllerSectionIndex) {
PrivacySettingsTableViewControllerSectionIndexScreenSecurity,
PrivacySettingsTableViewControllerSectionIndexHistoryLog,
PrivacySettingsTableViewControllerSectionIndexBlockOnIdentityChange
};
@interface PrivacySettingsTableViewController ()
@property (nonatomic, strong) UITableViewCell *enableScreenSecurityCell;
@property (nonatomic, strong) UISwitch *enableScreenSecuritySwitch;
@property (nonatomic, strong) UITableViewCell *blockOnIdentityChangeCell;
@property (nonatomic, strong) UISwitch *blockOnIdentityChangeSwitch;
@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", @"");
2017-02-17 23:30:49 +01:00
[self useOWSBackButton];
// 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:UIControlEventTouchUpInside];
// Clear History Log Cell
self.clearHistoryLogCell = [[UITableViewCell alloc] init];
self.clearHistoryLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_CLEAR_HISTORY", @"");
self.clearHistoryLogCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Block Identity on KeyChange
self.blockOnIdentityChangeCell = [UITableViewCell new];
self.blockOnIdentityChangeCell.textLabel.text
= NSLocalizedString(@"SETTINGS_BLOCK_ON_IDENTITY_CHANGE_TITLE", @"Table cell label");
self.blockOnIdentityChangeSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
self.blockOnIdentityChangeCell.accessoryView = self.blockOnIdentityChangeSwitch;
[self.blockOnIdentityChangeSwitch setOn:[Environment.preferences shouldBlockOnIdentityChange]];
[self.blockOnIdentityChangeSwitch addTarget:self
action:@selector(didToggleBlockOnIdentityChangeSwitch:)
forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) {
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity:
return 1;
case PrivacySettingsTableViewControllerSectionIndexHistoryLog:
return 1;
case PrivacySettingsTableViewControllerSectionIndexBlockOnIdentityChange:
return 1;
default:
return 0;
}
}
- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
switch (section) {
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity:
return NSLocalizedString(@"SETTINGS_SCREEN_SECURITY_DETAIL", nil);
case PrivacySettingsTableViewControllerSectionIndexBlockOnIdentityChange:
return NSLocalizedString(
@"SETTINGS_BLOCK_ON_IDENITY_CHANGE_DETAIL", @"User settings section footer, a detailed explanation");
default:
return nil;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity:
return self.enableScreenSecurityCell;
case PrivacySettingsTableViewControllerSectionIndexHistoryLog:
return self.clearHistoryLogCell;
case PrivacySettingsTableViewControllerSectionIndexBlockOnIdentityChange:
return self.blockOnIdentityChangeCell;
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
{
switch (section) {
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity:
return NSLocalizedString(@"SETTINGS_SECURITY_TITLE", @"Section header");
case PrivacySettingsTableViewControllerSectionIndexHistoryLog:
return NSLocalizedString(@"SETTINGS_HISTORYLOG_TITLE", @"Section header");
case PrivacySettingsTableViewControllerSectionIndexBlockOnIdentityChange:
return NSLocalizedString(@"SETTINGS_PRIVACY_VERIFICATION_TITLE", @"Section header");
default:
return nil;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.section) {
case PrivacySettingsTableViewControllerSectionIndexHistoryLog: {
2016-11-26 00:12:00 +01:00
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;
}
}
#pragma mark - Toggle
- (void)didToggleScreenSecuritySwitch:(UISwitch *)sender
{
BOOL enabled = self.enableScreenSecuritySwitch.isOn;
DDLogInfo(@"%@ toggled screen security: %@", self.tag, enabled ? @"ON" : @"OFF");
[Environment.preferences setScreenSecurity:enabled];
}
- (void)didToggleBlockOnIdentityChangeSwitch:(UISwitch *)sender
{
BOOL enabled = self.blockOnIdentityChangeSwitch.isOn;
DDLogInfo(@"%@ toggled blockOnIdentityChange: %@", self.tag, enabled ? @"ON" : @"OFF");
[Environment.preferences setShouldBlockOnIdentityChange:enabled];
}
#pragma mark - Log util
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END