session-ios/Signal/src/ViewControllers/SettingsTableViewController.m

316 lines
13 KiB
Mathematica
Raw Normal View History

2014-10-29 21:58:58 +01:00
//
2017-01-12 21:37:37 +01:00
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
2014-10-29 21:58:58 +01:00
//
#import "SettingsTableViewController.h"
#import "AboutTableViewController.h"
#import "AdvancedSettingsTableViewController.h"
#import "Environment.h"
#import "NotificationSettingsViewController.h"
#import "OWSContactsManager.h"
#import "OWSLinkedDevicesTableViewController.h"
#import "PrivacySettingsTableViewController.h"
#import "PropertyListPreferences.h"
#import "PushManager.h"
#import "Signal-Swift.h"
#import "TSAccountManager.h"
#import "TSSocketManager.h"
#import "UIUtil.h"
2014-10-29 21:58:58 +01:00
@interface SettingsTableViewController ()
2014-10-29 21:58:58 +01:00
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
2014-10-29 21:58:58 +01:00
@end
#pragma mark -
2014-10-29 21:58:58 +01:00
@implementation SettingsTableViewController
- (instancetype)init
{
self = [super init];
if (!self) {
return self;
}
_contactsManager = [Environment getCurrent].contactsManager;
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (!self) {
return self;
}
_contactsManager = [Environment getCurrent].contactsManager;
return self;
}
- (void)loadView
{
self.tableViewStyle = UITableViewStylePlain;
[super loadView];
}
- (void)viewDidLoad
{
2014-10-29 21:58:58 +01:00
[super viewDidLoad];
iOS 9 Support - Fixing size classes rendering bugs. - Supporting native iOS San Francisco font. - Quick Reply - Settings now slide to the left as suggested in original designed opposed to modal. - Simplification of restraints on many screens. - Full-API compatiblity with iOS 9 and iOS 8 legacy support. - Customized AddressBook Permission prompt when restrictions are enabled. If user installed Signal previously and already approved access to Contacts, don't bugg him again. - Fixes crash in migration for users who installed Signal <2.1.3 but hadn't signed up yet. - Xcode 7 / iOS 9 Travis Support - Bitcode Support is disabled until it is better understood how exactly optimizations are performed. In a first time, we will split out the crypto code into a separate binary to make it easier to optimize the non-sensitive code. Blog post with more details coming. - Partial ATS support. We are running our own Certificate Authority at Open Whisper Systems. Signal is doing certificate pinning to verify that certificates were signed by our own CA. Unfortunately Apple's App Transport Security requires to hand over chain verification to their framework with no control over the trust store. We have filed a radar to get ATS features with pinned certificates. In the meanwhile, ATS is disabled on our domain. We also followed Amazon's recommendations for our S3 domain we use to upload/download attachments. (#891) - Implement a unified `AFSecurityOWSPolicy` pinning strategy accross libraries (AFNetworking RedPhone/TextSecure & SocketRocket).
2015-09-01 19:22:08 +02:00
[self.navigationItem setHidesBackButton:YES];
[self.navigationController.navigationBar setTranslucent:NO];
2017-05-23 16:25:47 +02:00
self.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self
action:@selector(dismissWasPressed:)];
[self observeNotifications];
self.title = NSLocalizedString(@"SETTINGS_NAV_BAR_TITLE", @"Title for settings activity");
[self updateTableContents];
2014-10-29 21:58:58 +01:00
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
2014-10-29 21:58:58 +01:00
}
#pragma mark - Table Contents
2014-10-29 21:58:58 +01:00
- (void)updateTableContents
{
OWSTableContents *contents = [OWSTableContents new];
OWSTableSection *section = [OWSTableSection new];
__weak SettingsTableViewController *weakSelf = self;
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new];
UILabel *titleLabel = [UILabel new];
titleLabel.font = [UIFont ows_mediumFontWithSize:20.f];
titleLabel.textColor = [UIColor blackColor];
titleLabel.text = NSLocalizedString(@"REGISTERED_NUMBER_TEXT", @"");
titleLabel.textAlignment = NSTextAlignmentCenter;
UILabel *subtitleLabel = [UILabel new];
subtitleLabel.font = [UIFont ows_mediumFontWithSize:15.f];
subtitleLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f];
subtitleLabel.text =
[PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:[TSAccountManager localNumber]];
subtitleLabel.textAlignment = NSTextAlignmentCenter;
UIView *stack = [UIView new];
[cell addSubview:stack];
[stack autoCenterInSuperview];
[stack addSubview:titleLabel];
[stack addSubview:subtitleLabel];
[titleLabel autoPinWidthToSuperview];
[subtitleLabel autoPinWidthToSuperview];
[titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop];
[subtitleLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom];
[subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:titleLabel];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
customRowHeight:96.f
actionBlock:nil]];
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = NSLocalizedString(
@"NETWORK_STATUS_HEADER", @"");
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
UILabel *accessoryLabel = [UILabel new];
accessoryLabel.font = [UIFont ows_regularFontWithSize:18.f];
switch ([TSSocketManager sharedManager].state) {
case SocketManagerStateClosed:
accessoryLabel.text = NSLocalizedString(@"NETWORK_STATUS_OFFLINE", @"");
accessoryLabel.textColor = [UIColor ows_redColor];
break;
case SocketManagerStateConnecting:
accessoryLabel.text = NSLocalizedString(@"NETWORK_STATUS_CONNECTING", @"");
accessoryLabel.textColor = [UIColor ows_yellowColor];
break;
case SocketManagerStateOpen:
accessoryLabel.text = NSLocalizedString(@"NETWORK_STATUS_CONNECTED", @"");
accessoryLabel.textColor = [UIColor ows_greenColor];
break;
}
[accessoryLabel sizeToFit];
cell.accessoryView = accessoryLabel;
return cell;
}
actionBlock:^{
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"NETWORK_STATUS_HEADER", @"")
message:NSLocalizedString(@"NETWORK_STATUS_TEXT", @"")];
}]];
[section addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"SETTINGS_INVITE_TITLE",
@"Settings table view cell label")
actionBlock:^{
[weakSelf showInviteFlow];
}]];
[section addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"SETTINGS_PRIVACY_TITLE",
@"Settings table view cell label")
actionBlock:^{
[weakSelf showPrivacy];
}]];
[section addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"SETTINGS_NOTIFICATIONS", nil)
actionBlock:^{
[weakSelf showNotifications];
}]];
[section addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"LINKED_DEVICES_TITLE",
@"Menu item and navbar title for the device manager")
actionBlock:^{
[weakSelf showLinkedDevices];
}]];
[section addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_TITLE", @"")
actionBlock:^{
[weakSelf showAdvanced];
}]];
[section addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"SETTINGS_ABOUT", @"")
actionBlock:^{
[weakSelf showAbout];
}]];
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor ows_destructiveRedColor];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitle:NSLocalizedString(@"SETTINGS_DELETE_ACCOUNT_BUTTON", @"") forState:UIControlStateNormal];
button.titleLabel.font = [UIFont ows_mediumFontWithSize:18.f];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
[cell.contentView addSubview:button];
[button autoSetDimension:ALDimensionHeight toSize:50.f];
[button autoVCenterInSuperview];
[button autoPinEdgeToSuperviewEdge:ALEdgeLeft
withInset:cell.layoutMargins.left + cell.contentView.layoutMargins.left];
[button autoPinEdgeToSuperviewEdge:ALEdgeRight
withInset:cell.layoutMargins.right + cell.contentView.layoutMargins.right];
[button addTarget:self action:@selector(unregisterUser) forControlEvents:UIControlEventTouchUpInside];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
customRowHeight:100.f
actionBlock:nil]];
[contents addSection:section];
self.contents = contents;
}
- (void)showInviteFlow
{
OWSInviteFlow *inviteFlow =
[[OWSInviteFlow alloc] initWithPresentingViewController:self contactsManager:self.contactsManager];
[self presentViewController:inviteFlow.actionSheetController animated:YES completion:nil];
}
- (void)showPrivacy
{
PrivacySettingsTableViewController *vc = [[PrivacySettingsTableViewController alloc] init];
NSAssert(self.navigationController != nil, @"Navigation controller must not be nil");
NSAssert(vc != nil, @"Privacy Settings View Controller must not be nil");
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showNotifications
{
NotificationSettingsViewController *vc = [[NotificationSettingsViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showLinkedDevices
{
OWSLinkedDevicesTableViewController *vc =
[[UIStoryboard main] instantiateViewControllerWithIdentifier:@"OWSLinkedDevicesTableViewController"];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showAdvanced
{
AdvancedSettingsTableViewController *vc = [[AdvancedSettingsTableViewController alloc] init];
NSAssert(self.navigationController != nil, @"Navigation controller must not be nil");
NSAssert(vc != nil, @"Advanced Settings View Controller must not be nil");
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showAbout
{
AboutTableViewController *vc = [[AboutTableViewController 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];
}
2017-05-23 16:25:47 +02:00
- (void)dismissWasPressed:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Table view data source
- (void)unregisterUser
{
UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TITLE", @"")
message:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TEXT", @"")
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"PROCEED_BUTTON", @"")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
[self proceedToUnregistration];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"")
style:UIAlertActionStyleCancel
handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)proceedToUnregistration {
[TSAccountManager unregisterTextSecureWithSuccess:^{
[Environment resetAppData];
}
failure:^(NSError *error) {
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")];
2015-01-25 23:38:52 +01:00
}];
}
#pragma mark - Socket Status Notifications
- (void)observeNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(socketStateDidChange)
name:kNSNotification_SocketManagerStateDidChange
object:nil];
}
- (void)socketStateDidChange {
OWSAssert([NSThread isMainThread]);
[self updateTableContents];
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
2014-10-29 21:58:58 +01:00
@end