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-11-25 21:33:29 +01:00
|
|
|
#import "TSAccountManager.h"
|
2014-12-26 21:17:43 +01:00
|
|
|
#import "Environment.h"
|
|
|
|
#import "PreferencesUtil.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"
|
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
#import "ContactsManager.h"
|
2014-12-04 15:54:43 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
#import "PrivacySettingsTableViewController.h"
|
|
|
|
#import "AdvancedSettingsTableViewController.h"
|
|
|
|
#import "AboutTableViewController.h"
|
2015-01-25 23:38:52 +01:00
|
|
|
#import "PushManager.h"
|
2015-04-14 21:49:00 +02:00
|
|
|
#import "NotificationSettingsViewController.h"
|
2015-01-16 15:28:41 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
#define kProfileCellHeight 87.0f
|
2015-01-16 15:28:41 +01:00
|
|
|
#define kStandardCellHeight 44.0f
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
#define kNumberOfSections 4
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
#define kRegisteredNumberRow 0
|
|
|
|
#define kPrivacyRow 0
|
2015-04-14 21:49:00 +02:00
|
|
|
#define kNotificationRow 1
|
|
|
|
#define kAdvancedRow 2
|
|
|
|
#define kAboutRow 3
|
2015-01-16 15:28:41 +01:00
|
|
|
#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-01-14 22:30:01 +01:00
|
|
|
kRegisteredNumberSection=0,
|
|
|
|
kNetworkStatusSection=1,
|
2015-04-14 21:49:00 +02:00
|
|
|
kGeneralSection=2,
|
2015-01-14 22:30:01 +01:00
|
|
|
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-01-14 22:30:01 +01:00
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
2015-02-16 19:48:31 +01:00
|
|
|
|
2014-11-26 16:00:10 +01:00
|
|
|
self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
|
2015-01-14 22:30:01 +01:00
|
|
|
self.registeredNumber.text = [PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:[TSAccountManager registeredNumber]];
|
|
|
|
[self findAndSetRegisteredName];
|
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
[self initializeObserver];
|
|
|
|
[TSSocketManager sendNotification];
|
2015-02-18 23:21:03 +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-03-16 11:35:25 +01:00
|
|
|
[_destroyAccountButton setTitle:NSLocalizedString(@"SETTINGS_DELETE_ACCOUNT_BUTTON", @"") forState:UIControlStateNormal];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
-(void)dealloc {
|
|
|
|
[[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-01-14 22:30:01 +01:00
|
|
|
-(void) findAndSetRegisteredName {
|
2015-02-18 23:21:03 +01:00
|
|
|
NSString *name = NSLocalizedString(@"REGISTERED_NUMBER_TEXT", @"");
|
2015-01-14 22:30:01 +01:00
|
|
|
PhoneNumber* myNumber = [PhoneNumber phoneNumberFromE164:[TSAccountManager registeredNumber]];
|
|
|
|
Contact *me = [[Environment.getCurrent contactsManager] latestContactForPhoneNumber:myNumber];
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2015-01-16 15:28:41 +01:00
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
2015-01-14 22:30:01 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
switch (indexPath.section) {
|
|
|
|
case kGeneralSection:
|
|
|
|
{
|
|
|
|
switch (indexPath.row) {
|
|
|
|
case kPrivacyRow:
|
2014-12-04 15:54:43 +01:00
|
|
|
{
|
2015-04-14 21:49:00 +02:00
|
|
|
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-04-14 21:49:00 +02:00
|
|
|
case kNotificationRow:
|
|
|
|
{
|
|
|
|
NotificationSettingsViewController *vc = [[NotificationSettingsViewController alloc] init];
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
break;
|
|
|
|
}
|
2015-01-16 15:28:41 +01:00
|
|
|
case kAdvancedRow:
|
|
|
|
{
|
2015-04-14 21:49:00 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
case kAboutRow:
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2014-12-04 15:54:43 +01:00
|
|
|
}
|
2015-01-16 15:28:41 +01:00
|
|
|
|
|
|
|
break;
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
2015-01-16 15:28:41 +01:00
|
|
|
|
|
|
|
case kNetworkStatusSection:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case kUnregisterSection:
|
|
|
|
{
|
2015-02-16 19:48:31 +01:00
|
|
|
[self unregisterUser:nil];
|
2015-01-16 15:28:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-01-14 22:30:01 +01:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
|
|
|
|
-(IBAction)unregisterUser:(id)sender {
|
2015-02-16 19:48:31 +01:00
|
|
|
|
2015-02-18 23:21:03 +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) {
|
2015-02-17 00:14:50 +01:00
|
|
|
[self proceedToUnregistration];
|
2015-02-16 19:48:31 +01:00
|
|
|
}]];
|
2015-02-18 23:21:03 +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];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)proceedToUnregistration{
|
2015-01-14 22:30:01 +01:00
|
|
|
[TSAccountManager unregisterTextSecureWithSuccess:^{
|
2015-04-14 21:49:00 +02:00
|
|
|
[PushManager.sharedManager requestPushTokenWithSuccess:^(NSData* pushToken, NSData *voipToken){
|
2015-01-25 23:38:52 +01:00
|
|
|
[[RPServerRequestsManager sharedInstance]performRequest:[RPAPICall unregisterWithPushToken:pushToken] success:^(NSURLSessionDataTask *task, id responseObject) {
|
2015-02-20 17:02:31 +01:00
|
|
|
[Environment resetAppData];
|
2015-01-25 23:38:52 +01:00
|
|
|
exit(0);
|
|
|
|
} failure:^(NSURLSessionDataTask *task, NSError *error) {
|
2015-02-18 23:21:03 +01:00
|
|
|
SignalAlertView(NSLocalizedString(@"UNREGISTER_REDPHONE_FAIL", @""), @"");
|
2015-01-25 23:38:52 +01:00
|
|
|
}];
|
2015-02-20 17:02:31 +01:00
|
|
|
} failure:^(NSError *error) {
|
2015-02-18 23:21:03 +01:00
|
|
|
SignalAlertView(NSLocalizedString(@"UNREGISTER_REDPHONE_FAIL", @""), @"");
|
2015-01-25 23:38:52 +01:00
|
|
|
}];
|
2015-01-14 22:30:01 +01:00
|
|
|
} failure:^(NSError *error) {
|
2015-02-18 23:21:03 +01:00
|
|
|
SignalAlertView(NSLocalizedString(@"UNREGISTER_TEXTSECURE_FAIL", @""), @"");
|
2015-01-14 22:30:01 +01:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
if (indexPath.section == kNetworkStatusSection) {
|
2015-02-18 23:21:03 +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
|
|
|
|
|
|
|
|
-(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];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)socketDidOpen {
|
2015-02-18 23:21:03 +01:00
|
|
|
self.networkStatusLabel.text = NSLocalizedString(@"NETWORK_STATUS_CONNECTED", @"");
|
2015-01-16 15:28:41 +01:00
|
|
|
self.networkStatusLabel.textColor = [UIColor ows_greenColor];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)socketDidClose {
|
2015-02-18 23:21:03 +01:00
|
|
|
self.networkStatusLabel.text = NSLocalizedString(@"NETWORK_STATUS_OFFLINE", @"");
|
2015-01-16 15:28:41 +01:00
|
|
|
self.networkStatusLabel.textColor = [UIColor ows_redColor];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)socketIsConnecting {
|
2015-02-18 23:21:03 +01:00
|
|
|
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
|