From 27af2fc328e2b2c462c858ca38a10b47dbae8451 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 21 Jun 2018 16:09:59 -0400 Subject: [PATCH] Improve app settings buttons. --- .../AppSettings/AppSettingsViewController.m | 122 +++++++++++------- .../translations/en.lproj/Localizable.strings | 3 + 2 files changed, 76 insertions(+), 49 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m index bf2b0fadf..59da6c037 100644 --- a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m @@ -227,45 +227,53 @@ }]]; #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; - if (TSAccountManager.sharedInstance.isDeregistered) { - button = [OWSFlatButton - buttonWithTitle:NSLocalizedString(@"SETTINGS_REREGISTER_BUTTON", @"Label for re-registration button.") - font:[OWSFlatButton fontForHeight:kButtonHeight] - titleColor:[UIColor whiteColor] - backgroundColor:[UIColor ows_destructiveRedColor] - target:self - selector:@selector(reregisterUser)]; - } else { - 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 autoPinLeadingAndTrailingToSuperviewMargin]; - - return cell; + if (TSAccountManager.sharedInstance.isDeregistered) { + [section addItem:[self destructiveButtonItemWithTitle:NSLocalizedString(@"SETTINGS_REREGISTER_BUTTON", + @"Label for re-registration button.") + selector:@selector(reregisterUser) + color:[UIColor ows_materialBlueColor]]]; + [section addItem:[self destructiveButtonItemWithTitle:NSLocalizedString(@"SETTINGS_DELETE_DATA_BUTTON", + @"Label for 'delete data' button.") + selector:@selector(deleteUnregisterUserData) + color:[UIColor ows_destructiveRedColor]]]; + } else { + [section addItem:[self destructiveButtonItemWithTitle:NSLocalizedString(@"SETTINGS_DELETE_ACCOUNT_BUTTON", @"") + selector:@selector(unregisterUser) + color:[UIColor ows_destructiveRedColor]]]; } - customRowHeight:90.f - actionBlock:nil]]; [contents addSection:section]; self.contents = contents; } +- (OWSTableItem *)destructiveButtonItemWithTitle:(NSString *)title selector:(SEL)selector color:(UIColor *)color +{ + return [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:title + font:[OWSFlatButton fontForHeight:kButtonHeight] + titleColor:[UIColor whiteColor] + backgroundColor:color + target:self + selector:selector]; + [cell.contentView addSubview:button]; + [button autoSetDimension:ALDimensionHeight toSize:kButtonHeight]; + [button autoVCenterInSuperview]; + [button autoPinLeadingAndTrailingToSuperviewMargin]; + + return cell; + } + customRowHeight:90.f + actionBlock:nil]; +} + - (UITableViewCell *)profileHeaderCell { UITableViewCell *cell = [UITableViewCell new]; @@ -411,6 +419,16 @@ #pragma mark - Unregister & Re-register - (void)unregisterUser +{ + [self showDeleteAccountUI:YES]; +} + +- (void)deleteUnregisterUserData +{ + [self showDeleteAccountUI:NO]; +} + +- (void)showDeleteAccountUI:(BOOL)isRegistered { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TITLE", @"") @@ -419,30 +437,36 @@ [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"PROCEED_BUTTON", @"") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { - [self proceedToUnregistration]; + [self deleteAccount:isRegistered]; }]]; [alertController addAction:[OWSAlerts cancelAction]]; [self presentViewController:alertController animated:YES completion:nil]; } -- (void)proceedToUnregistration +- (void)deleteAccount:(BOOL)isRegistered { - [ModalActivityIndicatorViewController - presentFromViewController:self - canCancel:NO - backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) { - [TSAccountManager unregisterTextSecureWithSuccess:^{ - [SignalApp resetAppData]; - } - failure:^(NSError *error) { - dispatch_async(dispatch_get_main_queue(), ^{ - [modalActivityIndicator dismissWithCompletion:^{ - [OWSAlerts showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")]; - }]; - }); - }]; - }]; + if (isRegistered) { + [ModalActivityIndicatorViewController + presentFromViewController:self + canCancel:NO + backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) { + [TSAccountManager + unregisterTextSecureWithSuccess:^{ + [SignalApp resetAppData]; + } + failure:^(NSError *error) { + dispatch_async(dispatch_get_main_queue(), ^{ + [modalActivityIndicator dismissWithCompletion:^{ + [OWSAlerts + showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")]; + }]; + }); + }]; + }]; + } else { + [SignalApp resetAppData]; + } } - (void)reregisterUser diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index fe7067ea7..20d1ace60 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1933,6 +1933,9 @@ /* No comment provided by engineer. */ "SETTINGS_DELETE_ACCOUNT_BUTTON" = "Delete Account"; +/* Label for 'delete data' button. */ +"SETTINGS_DELETE_DATA_BUTTON" = "Delete All Data"; + /* Alert message before user confirms clearing history */ "SETTINGS_DELETE_HISTORYLOG_CONFIRMATION" = "Are you sure you want to delete all your history (messages, attachments, call history …) ? This action cannot be reverted.";