session-ios/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m

436 lines
18 KiB
Mathematica
Raw Normal View History

2014-10-29 21:58:58 +01:00
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
2014-10-29 21:58:58 +01:00
//
#import "AppSettingsViewController.h"
#import "AboutTableViewController.h"
#import "AdvancedSettingsTableViewController.h"
#import "DebugUITableViewController.h"
#import "NotificationSettingsViewController.h"
#import "OWSBackupSettingsViewController.h"
#import "OWSLinkedDevicesTableViewController.h"
#import "OWSNavigationController.h"
#import "PrivacySettingsTableViewController.h"
#import "ProfileViewController.h"
#import "PushManager.h"
#import "Signal-Swift.h"
2017-12-19 03:50:51 +01:00
#import <SignalMessaging/Environment.h>
#import <SignalMessaging/OWSContactsManager.h>
2017-12-08 17:50:35 +01:00
#import <SignalMessaging/UIUtil.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSSocketManager.h>
2014-10-29 21:58:58 +01:00
@interface AppSettingsViewController ()
2014-10-29 21:58:58 +01:00
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
2014-10-29 21:58:58 +01:00
@end
#pragma mark -
@implementation AppSettingsViewController
2014-10-29 21:58:58 +01:00
/**
* We always present the settings controller modally, from within an OWSNavigationController
*/
+ (OWSNavigationController *)inModalNavigationController
{
AppSettingsViewController *viewController = [AppSettingsViewController new];
OWSNavigationController *navController =
[[OWSNavigationController alloc] initWithRootViewController:viewController];
return navController;
}
- (instancetype)init
{
self = [super init];
if (!self) {
return self;
}
_contactsManager = [Environment current].contactsManager;
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (!self) {
return self;
}
_contactsManager = [Environment current].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];
OWSAssert([self.navigationController isKindOfClass:[OWSNavigationController class]]);
[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)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateTableContents];
}
- (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];
__weak AppSettingsViewController *weakSelf = self;
2018-01-26 23:31:45 +01:00
#ifdef INTERNAL
OWSTableSection *internalSection = [OWSTableSection new];
[section addItem:[OWSTableItem softCenterLabelItemWithText:@"Internal Build"]];
[contents addSection:internalSection];
#endif
OWSTableSection *section = [OWSTableSection new];
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
return [weakSelf profileHeaderCell];
}
customRowHeight:100.f
actionBlock:^{
[weakSelf showProfile];
}]];
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];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
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:nil]];
}
[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];
}]];
#ifdef DEBUG
[section addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"SETTINGS_BACKUP",
@"Label for the backup view in app settings.")
actionBlock:^{
[weakSelf showBackup];
}]];
#endif
[section addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"SETTINGS_ABOUT", @"")
actionBlock:^{
[weakSelf showAbout];
}]];
2017-09-01 20:30:39 +02:00
#ifdef USE_DEBUG_UI
[section addItem:[OWSTableItem disclosureItemWithText:@"Debug UI"
actionBlock:^{
[weakSelf showDebugUI];
}]];
#endif
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new];
cell.preservesSuperviewLayoutMargins = YES;
cell.contentView.preservesSuperviewLayoutMargins = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
const CGFloat kButtonHeight = 40.f;
OWSFlatButton *button = [OWSFlatButton buttonWithTitle:NSLocalizedString(@"SETTINGS_DELETE_ACCOUNT_BUTTON", @"")
font:[OWSFlatButton fontForHeight:kButtonHeight]
titleColor:[UIColor whiteColor]
backgroundColor:[UIColor ows_destructiveRedColor]
target:self
selector:@selector(unregisterUser)];
[cell.contentView addSubview:button];
[button autoSetDimension:ALDimensionHeight toSize:kButtonHeight];
[button autoVCenterInSuperview];
[button autoPinLeadingAndTrailingToSuperview];
return cell;
}
customRowHeight:90.f
actionBlock:nil]];
[contents addSection:section];
self.contents = contents;
}
- (UITableViewCell *)profileHeaderCell
{
UITableViewCell *cell = [UITableViewCell new];
cell.preservesSuperviewLayoutMargins = YES;
cell.contentView.preservesSuperviewLayoutMargins = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
const NSUInteger kAvatarSize = 68;
// TODO: Replace this icon.
UIImage *_Nullable localProfileAvatarImage = [OWSProfileManager.sharedManager localProfileAvatarImage];
UIImage *avatarImage = (localProfileAvatarImage
?: [[UIImage imageNamed:@"profile_avatar_default"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]);
OWSAssert(avatarImage);
AvatarImageView *avatarView = [[AvatarImageView alloc] initWithImage:avatarImage];
if (!localProfileAvatarImage) {
avatarView.tintColor = [UIColor colorWithRGBHex:0x888888];
}
[cell.contentView addSubview:avatarView];
[avatarView autoVCenterInSuperview];
2017-10-02 20:26:03 +02:00
[avatarView autoPinLeadingToSuperview];
[avatarView autoSetDimension:ALDimensionWidth toSize:kAvatarSize];
[avatarView autoSetDimension:ALDimensionHeight toSize:kAvatarSize];
if (!localProfileAvatarImage) {
UIImage *cameraImage = [UIImage imageNamed:@"settings-avatar-camera"];
UIImageView *cameraImageView = [[UIImageView alloc] initWithImage:cameraImage];
[cell.contentView addSubview:cameraImageView];
[cameraImageView autoPinTrailingToView:avatarView];
[cameraImageView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:avatarView];
}
2017-08-15 23:02:07 +02:00
UIView *nameView = [UIView containerView];
[cell.contentView addSubview:nameView];
[nameView autoVCenterInSuperview];
[nameView autoPinLeadingToTrailingOfView:avatarView margin:16.f];
2017-08-15 23:02:07 +02:00
UILabel *titleLabel = [UILabel new];
NSString *_Nullable localProfileName = [OWSProfileManager.sharedManager localProfileName];
if (localProfileName.length > 0) {
2017-08-15 23:02:07 +02:00
titleLabel.text = localProfileName;
titleLabel.textColor = [UIColor blackColor];
titleLabel.font = [UIFont ows_dynamicTypeTitle2Font];
} else {
2017-08-15 23:02:07 +02:00
titleLabel.text = NSLocalizedString(
@"APP_SETTINGS_EDIT_PROFILE_NAME_PROMPT", @"Text prompting user to edit their profile name.");
2017-08-15 23:02:07 +02:00
titleLabel.textColor = [UIColor ows_materialBlueColor];
titleLabel.font = [UIFont ows_dynamicTypeHeadlineFont];
}
2017-08-15 23:02:07 +02:00
titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[nameView addSubview:titleLabel];
[titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop];
[titleLabel autoPinWidthToSuperview];
const CGFloat kSubtitlePointSize = 12.f;
2017-08-15 23:02:07 +02:00
UILabel *subtitleLabel = [UILabel new];
subtitleLabel.textColor = [UIColor ows_darkGrayColor];
subtitleLabel.font = [UIFont ows_regularFontWithSize:kSubtitlePointSize];
subtitleLabel.attributedText = [[NSAttributedString alloc]
initWithString:[PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:[TSAccountManager
localNumber]]];
2017-08-15 23:02:07 +02:00
subtitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[nameView addSubview:subtitleLabel];
[subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:titleLabel];
2017-10-02 20:26:03 +02:00
[subtitleLabel autoPinLeadingToSuperview];
2017-08-15 23:02:07 +02:00
[subtitleLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom];
UIImage *disclosureImage = [UIImage imageNamed:(self.view.isRTL ? @"NavBarBack" : @"NavBarBackRTL")];
OWSAssert(disclosureImage);
UIImageView *disclosureButton =
[[UIImageView alloc] initWithImage:[disclosureImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
disclosureButton.tintColor = [UIColor colorWithRGBHex:0xcccccc];
[cell.contentView addSubview:disclosureButton];
[disclosureButton autoVCenterInSuperview];
2017-10-02 20:26:03 +02:00
[disclosureButton autoPinTrailingToSuperview];
2017-08-15 23:02:07 +02:00
[disclosureButton autoPinLeadingToTrailingOfView:nameView margin:16.f];
[disclosureButton setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh + 1)
forAxis:UILayoutConstraintAxisHorizontal];
return cell;
}
- (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];
[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)showProfile
{
[ProfileViewController presentForAppSettings:self.navigationController];
}
- (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];
}
- (void)showBackup
{
OWSBackupSettingsViewController *vc = [OWSBackupSettingsViewController new];
[self.navigationController pushViewController:vc animated:YES];
}]];
}
- (void)showDebugUI
{
[DebugUITableViewController presentDebugUIFromViewController:self];
}
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:[OWSAlerts cancelAction]];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)proceedToUnregistration
{
[ModalActivityIndicatorViewController
presentFromViewController:self
canCancel:NO
2017-09-18 21:35:14 +02:00
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
[TSAccountManager unregisterTextSecureWithSuccess:^{
[SignalApp resetAppData];
2017-09-18 21:35:14 +02:00
}
failure:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[modalActivityIndicator dismissWithCompletion:^{
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")];
}];
});
}];
}];
}
#pragma mark - Socket Status Notifications
- (void)observeNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(socketStateDidChange)
name:kNSNotification_SocketManagerStateDidChange
object:nil];
}
- (void)socketStateDidChange
{
2017-12-19 17:38:25 +01:00
OWSAssertIsOnMainThread();
[self updateTableContents];
}
2014-10-29 21:58:58 +01:00
@end