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
|
|
|
//
|
|
|
|
|
2017-07-31 22:45:06 +02:00
|
|
|
#import "AppSettingsViewController.h"
|
2015-01-16 15:28:41 +01:00
|
|
|
#import "AboutTableViewController.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
#import "AdvancedSettingsTableViewController.h"
|
2017-06-22 18:58:59 +02:00
|
|
|
#import "DebugUITableViewController.h"
|
2017-05-10 23:27:53 +02:00
|
|
|
#import "Environment.h"
|
2015-04-14 21:49:00 +02:00
|
|
|
#import "NotificationSettingsViewController.h"
|
2016-11-18 23:11:56 +01:00
|
|
|
#import "OWSContactsManager.h"
|
2017-05-10 23:27:53 +02:00
|
|
|
#import "OWSLinkedDevicesTableViewController.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
#import "PrivacySettingsTableViewController.h"
|
2017-07-31 22:45:06 +02:00
|
|
|
#import "ProfileViewController.h"
|
2017-05-10 23:27:53 +02:00
|
|
|
#import "PropertyListPreferences.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
#import "PushManager.h"
|
2016-11-18 23:11:56 +01:00
|
|
|
#import "Signal-Swift.h"
|
2017-05-10 23:27:53 +02:00
|
|
|
#import "UIUtil.h"
|
2017-05-27 02:41:27 +02:00
|
|
|
#import <SignalServiceKit/TSAccountManager.h>
|
|
|
|
#import <SignalServiceKit/TSSocketManager.h>
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2017-07-31 22:45:06 +02:00
|
|
|
@interface AppSettingsViewController ()
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2016-11-23 17:07:38 +01:00
|
|
|
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
@end
|
|
|
|
|
2017-05-10 22:40:35 +02:00
|
|
|
#pragma mark -
|
|
|
|
|
2017-07-31 22:45:06 +02:00
|
|
|
@implementation AppSettingsViewController
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2016-11-23 17:07:38 +01:00
|
|
|
- (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;
|
|
|
|
}
|
|
|
|
|
2017-05-10 23:27:53 +02:00
|
|
|
- (void)loadView
|
|
|
|
{
|
|
|
|
self.tableViewStyle = UITableViewStylePlain;
|
|
|
|
[super loadView];
|
|
|
|
}
|
|
|
|
|
2016-08-22 23:41:11 +02:00
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
2014-10-29 21:58:58 +01:00
|
|
|
[super viewDidLoad];
|
2015-09-01 19:22:08 +02:00
|
|
|
[self.navigationItem setHidesBackButton:YES];
|
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
[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:)];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-05-11 15:30:19 +02:00
|
|
|
[self observeNotifications];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2016-10-15 21:58:59 +02:00
|
|
|
self.title = NSLocalizedString(@"SETTINGS_NAV_BAR_TITLE", @"Title for settings activity");
|
2017-07-31 22:45:06 +02:00
|
|
|
|
2017-05-10 22:40:35 +02:00
|
|
|
[self updateTableContents];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 16:40:25 +02:00
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
[self updateTableContents];
|
|
|
|
}
|
|
|
|
|
2017-07-31 22:45:06 +02:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
2017-05-10 22:40:35 +02:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2017-05-10 22:40:35 +02:00
|
|
|
#pragma mark - Table Contents
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2017-05-10 22:40:35 +02:00
|
|
|
- (void)updateTableContents
|
|
|
|
{
|
|
|
|
OWSTableContents *contents = [OWSTableContents new];
|
|
|
|
OWSTableSection *section = [OWSTableSection new];
|
2017-05-10 23:27:53 +02:00
|
|
|
|
2017-07-31 22:45:06 +02:00
|
|
|
__weak AppSettingsViewController *weakSelf = self;
|
2017-05-10 23:27:53 +02:00
|
|
|
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
|
|
|
UITableViewCell *cell = [UITableViewCell new];
|
2017-07-11 22:00:32 +02:00
|
|
|
cell.preservesSuperviewLayoutMargins = YES;
|
|
|
|
cell.contentView.preservesSuperviewLayoutMargins = YES;
|
2017-05-10 23:27:53 +02:00
|
|
|
|
|
|
|
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];
|
2017-07-11 22:00:32 +02:00
|
|
|
[cell.contentView addSubview:stack];
|
2017-05-10 23:27:53 +02:00
|
|
|
[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]];
|
2017-06-06 16:40:25 +02:00
|
|
|
|
|
|
|
if (OWSSignalService.sharedInstance.isCensorshipCircumventionActive) {
|
|
|
|
[section
|
|
|
|
addItem:[OWSTableItem disclosureItemWithText:
|
|
|
|
NSLocalizedString(@"NETWORK_STATUS_CENSORSHIP_CIRCUMVENTION_ACTIVE",
|
|
|
|
@"Indicates to the user that censorship circumvention has been activated.")
|
|
|
|
actionBlock:^{
|
|
|
|
[weakSelf showAdvanced];
|
|
|
|
}]];
|
|
|
|
} else {
|
|
|
|
[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];
|
2017-07-03 23:04:23 +02:00
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
2017-06-06 16:40:25 +02:00
|
|
|
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;
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
2017-06-20 17:26:24 +02:00
|
|
|
actionBlock:nil]];
|
2017-05-10 23:27:53 +02:00
|
|
|
}
|
2017-07-31 22:45:06 +02:00
|
|
|
|
|
|
|
[section addItem:[OWSTableItem
|
|
|
|
disclosureItemWithText:NSLocalizedString(@"PROFILE_VIEW_TITLE", @"Title for the profile view.")
|
|
|
|
actionBlock:^{
|
|
|
|
[weakSelf showProfile];
|
|
|
|
}]];
|
|
|
|
|
2017-05-10 23:27:53 +02:00
|
|
|
[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];
|
|
|
|
}]];
|
|
|
|
|
2017-06-15 19:43:18 +02:00
|
|
|
#ifdef DEBUG
|
2017-06-22 18:58:59 +02:00
|
|
|
[section addItem:[OWSTableItem disclosureItemWithText:@"Debug UI"
|
2017-06-15 19:43:18 +02:00
|
|
|
actionBlock:^{
|
2017-06-22 18:58:59 +02:00
|
|
|
[weakSelf showDebugUI];
|
2017-06-15 19:43:18 +02:00
|
|
|
}]];
|
|
|
|
#endif
|
|
|
|
|
2017-05-10 23:27:53 +02:00
|
|
|
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
|
|
|
UITableViewCell *cell = [UITableViewCell new];
|
2017-07-11 19:32:03 +02:00
|
|
|
cell.preservesSuperviewLayoutMargins = YES;
|
|
|
|
cell.contentView.preservesSuperviewLayoutMargins = YES;
|
2017-05-10 23:27:53 +02:00
|
|
|
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];
|
2017-07-11 22:00:32 +02:00
|
|
|
[button autoPinLeadingAndTrailingToSuperview];
|
2017-05-10 23:27:53 +02:00
|
|
|
[button addTarget:self action:@selector(unregisterUser) forControlEvents:UIControlEventTouchUpInside];
|
2017-05-10 22:40:35 +02:00
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
return cell;
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
2017-05-10 23:27:53 +02:00
|
|
|
customRowHeight:100.f
|
2017-05-10 22:40:35 +02:00
|
|
|
actionBlock:nil]];
|
2017-05-10 23:27:53 +02:00
|
|
|
|
2017-05-10 22:40:35 +02:00
|
|
|
[contents addSection:section];
|
2017-07-31 22:45:06 +02:00
|
|
|
|
2017-05-10 22:40:35 +02:00
|
|
|
self.contents = contents;
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
|
2017-05-10 23:27:53 +02:00
|
|
|
- (void)showInviteFlow
|
|
|
|
{
|
|
|
|
OWSInviteFlow *inviteFlow =
|
|
|
|
[[OWSInviteFlow alloc] initWithPresentingViewController:self contactsManager:self.contactsManager];
|
|
|
|
[self presentViewController:inviteFlow.actionSheetController animated:YES completion:nil];
|
|
|
|
}
|
2015-01-14 22:30:01 +01:00
|
|
|
|
2017-05-10 23:27:53 +02:00
|
|
|
- (void)showPrivacy
|
|
|
|
{
|
|
|
|
PrivacySettingsTableViewController *vc = [[PrivacySettingsTableViewController alloc] init];
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
}
|
2015-12-30 13:48:25 +01:00
|
|
|
|
2017-05-10 23:27:53 +02:00
|
|
|
- (void)showNotifications
|
|
|
|
{
|
|
|
|
NotificationSettingsViewController *vc = [[NotificationSettingsViewController alloc] init];
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
}
|
2015-12-30 13:48:25 +01:00
|
|
|
|
2017-05-10 23:27:53 +02:00
|
|
|
- (void)showLinkedDevices
|
|
|
|
{
|
|
|
|
OWSLinkedDevicesTableViewController *vc =
|
|
|
|
[[UIStoryboard main] instantiateViewControllerWithIdentifier:@"OWSLinkedDevicesTableViewController"];
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
}
|
|
|
|
|
2017-07-31 22:45:06 +02:00
|
|
|
- (void)showProfile
|
|
|
|
{
|
|
|
|
ProfileViewController *vc = [[ProfileViewController alloc] init];
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
}
|
|
|
|
|
2017-05-10 23:27:53 +02:00
|
|
|
- (void)showAdvanced
|
|
|
|
{
|
|
|
|
AdvancedSettingsTableViewController *vc = [[AdvancedSettingsTableViewController alloc] init];
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showAbout
|
|
|
|
{
|
|
|
|
AboutTableViewController *vc = [[AboutTableViewController alloc] init];
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
}
|
|
|
|
|
2017-06-22 18:58:59 +02:00
|
|
|
- (void)showDebugUI
|
2017-06-15 19:43:18 +02:00
|
|
|
{
|
2017-06-22 18:58:59 +02:00
|
|
|
[DebugUITableViewController presentDebugUIFromViewController:self];
|
2017-06-15 19:43:18 +02:00
|
|
|
}
|
|
|
|
|
2017-05-23 16:25:47 +02:00
|
|
|
- (void)dismissWasPressed:(id)sender
|
|
|
|
{
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
2017-05-10 23:27:53 +02:00
|
|
|
#pragma mark - Table view data source
|
|
|
|
|
|
|
|
- (void)unregisterUser
|
|
|
|
{
|
2015-12-22 12:45:09 +01:00
|
|
|
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) {
|
2017-07-31 22:45:06 +02:00
|
|
|
[self proceedToUnregistration];
|
2015-12-22 12:45:09 +01:00
|
|
|
}]];
|
|
|
|
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"")
|
|
|
|
style:UIAlertActionStyleCancel
|
|
|
|
handler:nil]];
|
2015-02-16 19:48:31 +01:00
|
|
|
|
|
|
|
[self presentViewController:alertController animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
2017-07-31 22:45:06 +02:00
|
|
|
- (void)proceedToUnregistration
|
|
|
|
{
|
2015-01-14 22:30:01 +01:00
|
|
|
[TSAccountManager unregisterTextSecureWithSuccess:^{
|
2017-05-09 16:04:48 +02:00
|
|
|
[Environment resetAppData];
|
2015-12-22 12:45:09 +01:00
|
|
|
}
|
|
|
|
failure:^(NSError *error) {
|
2017-05-09 16:04:48 +02:00
|
|
|
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")];
|
2015-01-25 23:38:52 +01:00
|
|
|
}];
|
2015-01-14 22:30:01 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
#pragma mark - Socket Status Notifications
|
|
|
|
|
2017-05-11 15:30:19 +02:00
|
|
|
- (void)observeNotifications
|
|
|
|
{
|
2015-12-22 12:45:09 +01:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
2017-05-10 22:40:35 +02:00
|
|
|
selector:@selector(socketStateDidChange)
|
|
|
|
name:kNSNotification_SocketManagerStateDidChange
|
2015-12-22 12:45:09 +01:00
|
|
|
object:nil];
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
|
2017-07-31 22:45:06 +02:00
|
|
|
- (void)socketStateDidChange
|
|
|
|
{
|
2017-05-10 22:40:35 +02:00
|
|
|
OWSAssert([NSThread isMainThread]);
|
2017-07-31 22:45:06 +02:00
|
|
|
|
2017-05-10 22:40:35 +02:00
|
|
|
[self updateTableContents];
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
|
2016-11-18 23:11:56 +01:00
|
|
|
#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
|