session-ios/Signal/src/view controllers/PrivacySettingsTableViewCon...

167 lines
5.6 KiB
Objective-C

//
// PrivacySettingsTableViewController.m
// Signal
//
// Created by Dylan Bourgeois on 05/01/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
//
#import "PrivacySettingsTableViewController.h"
#import "DJWActionSheet+OWS.h"
#import "Environment.h"
#import "PropertyListPreferences.h"
#import "UIUtil.h"
#import <25519/Curve25519.h>
@interface PrivacySettingsTableViewController ()
@property (nonatomic, strong) UITableViewCell *enableScreenSecurityCell;
@property (nonatomic, strong) UISwitch *enableScreenSecuritySwitch;
@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", @"");
// 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;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) {
case 0:
return 1;
case 1:
return 1;
// TODO: optionally non-blocking
// case 2:
// return 1;
default:
return 0;
}
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
switch (section) {
case 0:
return NSLocalizedString(@"SETTINGS_SCREEN_SECURITY_DETAIL", nil);
default:
return nil;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case 0:
return self.enableScreenSecurityCell;
case 1:
return self.clearHistoryLogCell;
// TODO - safetynumber settings
// case 2:
// return [UITableViewCell new];
}
return nil;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case 0:
return NSLocalizedString(@"SETTINGS_SECURITY_TITLE", @"Section header");
case 1:
return NSLocalizedString(@"SETTINGS_HISTORYLOG_TITLE", @"Section header");
case 2:
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 1: {
[DJWActionSheet showInView:self.parentViewController.view
withTitle:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION", @"")
cancelButtonTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"")
destructiveButtonTitle:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION_BUTTON", @"")
otherButtonTitles:@[]
tapBlock:^(DJWActionSheet *actionSheet, NSInteger tappedButtonIndex) {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
if (tappedButtonIndex == actionSheet.cancelButtonIndex) {
DDLogDebug(@"User Cancelled");
} else if (tappedButtonIndex == actionSheet.destructiveButtonIndex) {
[[TSStorageManager sharedManager] deleteThreadsAndMessages];
} else {
DDLogDebug(@"The user tapped button at index: %li", (long)tappedButtonIndex);
}
}];
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];
}
#pragma mark - Log util
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end