2014-10-29 21:58:58 +01:00
|
|
|
//
|
|
|
|
// SettingsTableViewController.m
|
|
|
|
// Signal
|
|
|
|
//
|
|
|
|
// Created by Dylan Bourgeois on 03/11/14.
|
|
|
|
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "SettingsTableViewController.h"
|
|
|
|
|
2014-12-26 21:17:43 +01:00
|
|
|
#import "Environment.h"
|
|
|
|
#import "PreferencesUtil.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
#import "TSAccountManager.h"
|
2015-01-16 15:28:41 +01:00
|
|
|
#import "UIUtil.h"
|
2014-12-04 15:54:43 +01:00
|
|
|
|
2014-11-26 16:00:10 +01:00
|
|
|
#import "RPServerRequestsManager.h"
|
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
#import "TSSocketManager.h"
|
|
|
|
|
2016-06-27 23:32:35 +02:00
|
|
|
#import "OWSContactsManager.h"
|
2014-12-04 15:54:43 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
#import "AboutTableViewController.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
#import "AdvancedSettingsTableViewController.h"
|
2015-04-14 21:49:00 +02:00
|
|
|
#import "NotificationSettingsViewController.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
#import "PrivacySettingsTableViewController.h"
|
|
|
|
#import "PushManager.h"
|
2015-01-16 15:28:41 +01:00
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
#define kProfileCellHeight 87.0f
|
|
|
|
#define kStandardCellHeight 44.0f
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
#define kNumberOfSections 4
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
#define kRegisteredNumberRow 0
|
2015-12-22 12:45:09 +01:00
|
|
|
#define kPrivacyRow 0
|
|
|
|
#define kNotificationRow 1
|
|
|
|
#define kAdvancedRow 2
|
|
|
|
#define kAboutRow 3
|
|
|
|
#define kNetworkRow 0
|
|
|
|
#define kUnregisterRow 0
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
|
|
typedef enum {
|
2015-01-16 15:28:41 +01:00
|
|
|
kRegisteredRows = 1,
|
2015-04-14 21:49:00 +02:00
|
|
|
kGeneralRows = 4,
|
2015-01-16 15:28:41 +01:00
|
|
|
kNetworkStatusRows = 1,
|
|
|
|
kUnregisterRows = 1,
|
2014-10-29 21:58:58 +01:00
|
|
|
} kRowsForSection;
|
|
|
|
|
|
|
|
typedef enum {
|
2015-12-22 12:45:09 +01:00
|
|
|
kRegisteredNumberSection = 0,
|
|
|
|
kNetworkStatusSection = 1,
|
|
|
|
kGeneralSection = 2,
|
|
|
|
kUnregisterSection = 3,
|
2014-10-29 21:58:58 +01:00
|
|
|
} kSection;
|
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
@interface SettingsTableViewController () <UIAlertViewDelegate>
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SettingsTableViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[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];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
|
self.registeredNumber.text =
|
|
|
|
[PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:[TSAccountManager localNumber]];
|
2015-01-14 22:30:01 +01:00
|
|
|
[self findAndSetRegisteredName];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
[self initializeObserver];
|
|
|
|
[TSSocketManager sendNotification];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
self.title = NSLocalizedString(@"SETTINGS_NAV_BAR_TITLE", @"");
|
|
|
|
_networkStatusHeader.text = NSLocalizedString(@"NETWORK_STATUS_HEADER", @"");
|
|
|
|
_settingsPrivacyTitle.text = NSLocalizedString(@"SETTINGS_PRIVACY_TITLE", @"");
|
|
|
|
_settingsAdvancedTitle.text = NSLocalizedString(@"SETTINGS_ADVANCED_TITLE", @"");
|
|
|
|
_settingsAboutTitle.text = NSLocalizedString(@"SETTINGS_ABOUT", @"");
|
2015-04-14 21:49:00 +02:00
|
|
|
_settingsNotifications.text = NSLocalizedString(@"SETTINGS_NOTIFICATIONS", nil);
|
2015-12-22 12:45:09 +01:00
|
|
|
[_destroyAccountButton setTitle:NSLocalizedString(@"SETTINGS_DELETE_ACCOUNT_BUTTON", @"")
|
|
|
|
forState:UIControlStateNormal];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)dealloc {
|
2015-01-16 15:28:41 +01:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:SocketOpenedNotification object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:SocketClosedNotification object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:SocketConnectingNotification object:nil];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)findAndSetRegisteredName {
|
|
|
|
NSString *name = NSLocalizedString(@"REGISTERED_NUMBER_TEXT", @"");
|
|
|
|
PhoneNumber *myNumber = [PhoneNumber phoneNumberFromE164:[TSAccountManager localNumber]];
|
|
|
|
Contact *me = [[Environment.getCurrent contactsManager] latestContactForPhoneNumber:myNumber];
|
2015-01-14 22:30:01 +01:00
|
|
|
self.registeredName.text = [me fullName] ? [me fullName] : name;
|
|
|
|
}
|
2014-10-29 21:58:58 +01:00
|
|
|
#pragma mark - Table view data source
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
|
|
return kNumberOfSections;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
switch (section) {
|
2015-01-16 15:28:41 +01:00
|
|
|
case kRegisteredNumberSection:
|
|
|
|
return kRegisteredRows;
|
|
|
|
case kGeneralSection:
|
|
|
|
return kGeneralRows;
|
|
|
|
case kNetworkStatusSection:
|
|
|
|
return kNetworkStatusRows;
|
|
|
|
case kUnregisterSection:
|
|
|
|
return kUnregisterRows;
|
2014-10-29 21:58:58 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
2015-01-16 15:28:41 +01:00
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
switch (indexPath.section) {
|
2015-12-22 12:45:09 +01:00
|
|
|
case kGeneralSection: {
|
2015-01-16 15:28:41 +01:00
|
|
|
switch (indexPath.row) {
|
2015-12-22 12:45:09 +01:00
|
|
|
case kPrivacyRow: {
|
|
|
|
PrivacySettingsTableViewController *vc = [[PrivacySettingsTableViewController alloc] init];
|
2015-01-16 15:28:41 +01:00
|
|
|
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];
|
|
|
|
break;
|
2014-12-04 15:54:43 +01:00
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
case kNotificationRow: {
|
2015-04-14 21:49:00 +02:00
|
|
|
NotificationSettingsViewController *vc = [[NotificationSettingsViewController alloc] init];
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
break;
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
case kAdvancedRow: {
|
|
|
|
AdvancedSettingsTableViewController *vc = [[AdvancedSettingsTableViewController alloc] init];
|
2015-01-16 15:28:41 +01:00
|
|
|
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];
|
|
|
|
break;
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
case kAboutRow: {
|
|
|
|
AboutTableViewController *vc = [[AboutTableViewController alloc] init];
|
2015-01-16 15:28:41 +01:00
|
|
|
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];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2014-12-04 15:54:43 +01:00
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
break;
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
case kNetworkStatusSection: {
|
2015-01-16 15:28:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
case kUnregisterSection: {
|
2015-02-16 19:48:31 +01:00
|
|
|
[self unregisterUser:nil];
|
2015-01-16 15:28:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
|
2015-12-30 13:48:25 +01:00
|
|
|
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
switch (indexPath.section) {
|
|
|
|
case kNetworkStatusSection: {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
case kUnregisterSection: {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (IBAction)unregisterUser:(id)sender {
|
|
|
|
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]];
|
2015-02-16 19:48:31 +01:00
|
|
|
|
|
|
|
[self presentViewController:alertController animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)proceedToUnregistration {
|
2015-01-14 22:30:01 +01:00
|
|
|
[TSAccountManager unregisterTextSecureWithSuccess:^{
|
2015-12-22 12:45:09 +01:00
|
|
|
[Environment resetAppData];
|
|
|
|
}
|
|
|
|
failure:^(NSError *error) {
|
|
|
|
SignalAlertView(NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @""), @"");
|
2015-01-25 23:38:52 +01:00
|
|
|
}];
|
2015-01-14 22:30:01 +01:00
|
|
|
}
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
|
2015-01-16 15:28:41 +01:00
|
|
|
if (indexPath.section == kNetworkStatusSection) {
|
2015-12-22 12:45:09 +01:00
|
|
|
UIAlertView *info = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"NETWORK_STATUS_HEADER", @"")
|
|
|
|
message:NSLocalizedString(@"NETWORK_STATUS_TEXT", @"")
|
|
|
|
delegate:self
|
|
|
|
cancelButtonTitle:NSLocalizedString(@"OK", @"")
|
|
|
|
otherButtonTitles:nil];
|
2015-01-16 15:28:41 +01:00
|
|
|
[info show];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
#pragma mark - Socket Status Notifications
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)initializeObserver {
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(socketDidOpen)
|
|
|
|
name:SocketOpenedNotification
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(socketDidClose)
|
|
|
|
name:SocketClosedNotification
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(socketIsConnecting)
|
|
|
|
name:SocketConnectingNotification
|
|
|
|
object:nil];
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)socketDidOpen {
|
|
|
|
self.networkStatusLabel.text = NSLocalizedString(@"NETWORK_STATUS_CONNECTED", @"");
|
2015-01-16 15:28:41 +01:00
|
|
|
self.networkStatusLabel.textColor = [UIColor ows_greenColor];
|
|
|
|
}
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)socketDidClose {
|
|
|
|
self.networkStatusLabel.text = NSLocalizedString(@"NETWORK_STATUS_OFFLINE", @"");
|
2015-01-16 15:28:41 +01:00
|
|
|
self.networkStatusLabel.textColor = [UIColor ows_redColor];
|
|
|
|
}
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)socketIsConnecting {
|
|
|
|
self.networkStatusLabel.text = NSLocalizedString(@"NETWORK_STATUS_CONNECTING", @"");
|
2015-01-16 15:28:41 +01:00
|
|
|
self.networkStatusLabel.textColor = [UIColor ows_yellowColor];
|
|
|
|
}
|
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
- (IBAction)unwindToUserCancelledChangeNumber:(UIStoryboardSegue *)segue {
|
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
@end
|