Handle account deactivation from settings

This commit is contained in:
SBiOSoftWhare
2018-05-30 17:05:42 +02:00
parent ff199a99f9
commit d9ed6c4a84
+83 -1
View File
@@ -34,6 +34,7 @@
#import "CountryPickerViewController.h"
#import "LanguagePickerViewController.h"
#import "DeactivateAccountViewController.h"
#import "NBPhoneNumberUtil.h"
#import "RageShakeManager.h"
@@ -62,6 +63,7 @@ enum
SETTINGS_SECTION_CRYPTOGRAPHY_INDEX,
SETTINGS_SECTION_FLAIR_INDEX,
SETTINGS_SECTION_DEVICES_INDEX,
SETTINGS_SECTION_DEACTIVATE_ACCOUNT_INDEX,
SETTINGS_SECTION_COUNT
};
@@ -130,7 +132,7 @@ enum {
typedef void (^blockSettingsViewController_onReadyToDestroy)();
@interface SettingsViewController ()
@interface SettingsViewController () <DeactivateAccountViewControllerDelegate>
{
// Current alert (if any).
UIAlertController *currentAlert;
@@ -234,6 +236,10 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
*/
@property (nonatomic) BOOL newPhoneEditingEnabled;
@property (weak, nonatomic) DeactivateAccountViewController *deactivateAccountViewController;
//@property (strong, nonatomic) ErrorPresenter *errorPresenter;
@end
@implementation SettingsViewController
@@ -258,6 +264,9 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
self.navigationItem.title = NSLocalizedStringFromTable(@"settings_title", @"Vector", nil);
// Remove back bar button title when pushing a view controller
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.tableView registerClass:MXKTableViewCellWithLabelAndTextField.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndTextField defaultReuseIdentifier]];
[self.tableView registerClass:MXKTableViewCellWithLabelAndSwitch.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier]];
[self.tableView registerClass:MXKTableViewCellWithLabelAndMXKImageView.class forCellReuseIdentifier:[MXKTableViewCellWithLabelAndMXKImageView defaultReuseIdentifier]];
@@ -310,6 +319,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(onSave:)];
self.navigationItem.rightBarButtonItem.accessibilityIdentifier=@"SettingsVCNavBarSaveButton";
// Observe user interface theme change.
kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
@@ -1268,6 +1278,10 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
count = CRYPTOGRAPHY_COUNT;
}
}
else if (section == SETTINGS_SECTION_DEACTIVATE_ACCOUNT_INDEX)
{
count = 1;
}
return count;
}
@@ -2151,6 +2165,32 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
cell = exportKeysBtnCell;
}
}
else if (section == SETTINGS_SECTION_DEACTIVATE_ACCOUNT_INDEX)
{
MXKTableViewCellWithButton *deactivateAccountBtnCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithButton defaultReuseIdentifier]];
if (!deactivateAccountBtnCell)
{
deactivateAccountBtnCell = [[MXKTableViewCellWithButton alloc] init];
}
else
{
// Fix https://github.com/vector-im/riot-ios/issues/1354
deactivateAccountBtnCell.mxkButton.titleLabel.text = nil;
}
NSString *btnTitle = NSLocalizedStringFromTable(@"settings_deactivate_my_account", @"Vector", nil);
[deactivateAccountBtnCell.mxkButton setTitle:btnTitle forState:UIControlStateNormal];
[deactivateAccountBtnCell.mxkButton setTitle:btnTitle forState:UIControlStateHighlighted];
[deactivateAccountBtnCell.mxkButton setTintColor:kRiotColorRed];
deactivateAccountBtnCell.mxkButton.titleLabel.font = [UIFont systemFontOfSize:17];
[deactivateAccountBtnCell.mxkButton removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[deactivateAccountBtnCell.mxkButton addTarget:self action:@selector(deactivateAccountAction) forControlEvents:UIControlEventTouchUpInside];
deactivateAccountBtnCell.mxkButton.accessibilityIdentifier = nil;
cell = deactivateAccountBtnCell;
}
return cell;
}
@@ -2228,6 +2268,18 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
return NSLocalizedStringFromTable(@"settings_cryptography", @"Vector", nil);
}
}
else if (section == SETTINGS_SECTION_CRYPTOGRAPHY_INDEX)
{
// Check whether this section is visible
if (self.mainSession.crypto)
{
return NSLocalizedStringFromTable(@"settings_cryptography", @"Vector", nil);
}
}
else if (section == SETTINGS_SECTION_DEACTIVATE_ACCOUNT_INDEX)
{
return NSLocalizedStringFromTable(@"settings_deactivate_my_account", @"Vector", nil);
}
return nil;
}
@@ -3673,6 +3725,20 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
[self presentViewController:themePicker animated:YES completion:nil];
}
- (void)deactivateAccountAction
{
DeactivateAccountViewController *deactivateAccountViewController = [DeactivateAccountViewController instantiateWithMatrixSession:self.mainSession];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:deactivateAccountViewController];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil];
deactivateAccountViewController.delegate = self;
self.deactivateAccountViewController = deactivateAccountViewController;
}
#pragma mark - MediaPickerViewController Delegate
- (void)dismissMediaPicker
@@ -4033,4 +4099,20 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
[self refreshSettings];
}
#pragma mark - DeactivateAccountViewControllerDelegate
- (void)deactivateAccountViewControllerDidDeactivateWithSuccess:(DeactivateAccountViewController *)deactivateAccountViewController
{
NSLog(@"[SettingsViewController] Deactivate account with success");
[[AppDelegate theDelegate] logoutWithCompletion:^(BOOL isLoggedOut) {
NSLog(@"[SettingsViewController] Complete clear user data after account deactivation");
}];
}
- (void)deactivateAccountViewControllerDidCancel:(DeactivateAccountViewController *)deactivateAccountViewController
{
[deactivateAccountViewController dismissViewControllerAnimated:YES completion:nil];
}
@end