Merge branch 'charlesmchen/appSettingsButton'

pull/1/head
Matthew Chen 7 years ago
commit c1fea2e7fa

@ -227,30 +227,42 @@
}]]; }]];
#endif #endif
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ 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]]];
}
[contents addSection:section];
self.contents = contents;
}
- (OWSTableItem *)destructiveButtonItemWithTitle:(NSString *)title selector:(SEL)selector color:(UIColor *)color
{
return [OWSTableItem
itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new]; UITableViewCell *cell = [UITableViewCell new];
cell.preservesSuperviewLayoutMargins = YES; cell.preservesSuperviewLayoutMargins = YES;
cell.contentView.preservesSuperviewLayoutMargins = YES; cell.contentView.preservesSuperviewLayoutMargins = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
const CGFloat kButtonHeight = 40.f; const CGFloat kButtonHeight = 40.f;
OWSFlatButton *button; OWSFlatButton *button = [OWSFlatButton buttonWithTitle:title
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] font:[OWSFlatButton fontForHeight:kButtonHeight]
titleColor:[UIColor whiteColor] titleColor:[UIColor whiteColor]
backgroundColor:[UIColor ows_destructiveRedColor] backgroundColor:color
target:self target:self
selector:@selector(unregisterUser)]; selector:selector];
}
[cell.contentView addSubview:button]; [cell.contentView addSubview:button];
[button autoSetDimension:ALDimensionHeight toSize:kButtonHeight]; [button autoSetDimension:ALDimensionHeight toSize:kButtonHeight];
[button autoVCenterInSuperview]; [button autoVCenterInSuperview];
@ -259,11 +271,7 @@
return cell; return cell;
} }
customRowHeight:90.f customRowHeight:90.f
actionBlock:nil]]; actionBlock:nil];
[contents addSection:section];
self.contents = contents;
} }
- (UITableViewCell *)profileHeaderCell - (UITableViewCell *)profileHeaderCell
@ -411,6 +419,16 @@
#pragma mark - Unregister & Re-register #pragma mark - Unregister & Re-register
- (void)unregisterUser - (void)unregisterUser
{
[self showDeleteAccountUI:YES];
}
- (void)deleteUnregisterUserData
{
[self showDeleteAccountUI:NO];
}
- (void)showDeleteAccountUI:(BOOL)isRegistered
{ {
UIAlertController *alertController = UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TITLE", @"") [UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TITLE", @"")
@ -419,30 +437,36 @@
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"PROCEED_BUTTON", @"") [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"PROCEED_BUTTON", @"")
style:UIAlertActionStyleDestructive style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[self proceedToUnregistration]; [self deleteAccount:isRegistered];
}]]; }]];
[alertController addAction:[OWSAlerts cancelAction]]; [alertController addAction:[OWSAlerts cancelAction]];
[self presentViewController:alertController animated:YES completion:nil]; [self presentViewController:alertController animated:YES completion:nil];
} }
- (void)proceedToUnregistration - (void)deleteAccount:(BOOL)isRegistered
{ {
if (isRegistered) {
[ModalActivityIndicatorViewController [ModalActivityIndicatorViewController
presentFromViewController:self presentFromViewController:self
canCancel:NO canCancel:NO
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) { backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
[TSAccountManager unregisterTextSecureWithSuccess:^{ [TSAccountManager
unregisterTextSecureWithSuccess:^{
[SignalApp resetAppData]; [SignalApp resetAppData];
} }
failure:^(NSError *error) { failure:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[modalActivityIndicator dismissWithCompletion:^{ [modalActivityIndicator dismissWithCompletion:^{
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")]; [OWSAlerts
showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")];
}]; }];
}); });
}]; }];
}]; }];
} else {
[SignalApp resetAppData];
}
} }
- (void)reregisterUser - (void)reregisterUser

@ -1933,6 +1933,9 @@
/* No comment provided by engineer. */ /* No comment provided by engineer. */
"SETTINGS_DELETE_ACCOUNT_BUTTON" = "Delete Account"; "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 */ /* 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."; "SETTINGS_DELETE_HISTORYLOG_CONFIRMATION" = "Are you sure you want to delete all your history (messages, attachments, call history …) ? This action cannot be reverted.";

Loading…
Cancel
Save