Sketch out the backup restore view.

pull/1/head
Matthew Chen 7 years ago
parent 5010b027b1
commit 332f202a52

@ -421,11 +421,15 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
- (void)updateProfileCompleted - (void)updateProfileCompleted
{ {
OWSLogVerbose(@"");
[self profileCompletedOrSkipped]; [self profileCompletedOrSkipped];
} }
- (void)profileCompletedOrSkipped - (void)profileCompletedOrSkipped
{ {
OWSLogVerbose(@"");
// Dismiss this view. // Dismiss this view.
switch (self.profileViewMode) { switch (self.profileViewMode) {
case ProfileViewMode_AppSettings: case ProfileViewMode_AppSettings:
@ -446,11 +450,15 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
- (void)showHomeView - (void)showHomeView
{ {
OWSLogVerbose(@"");
[SignalApp.sharedApp showHomeView]; [SignalApp.sharedApp showHomeView];
} }
- (void)showBackupRestoreView - (void)showBackupRestoreView
{ {
OWSLogVerbose(@"");
BackupRestoreViewController *restoreView = [BackupRestoreViewController new]; BackupRestoreViewController *restoreView = [BackupRestoreViewController new];
[self.navigationController setViewControllers:@[ [self.navigationController setViewControllers:@[
restoreView, restoreView,
@ -460,39 +468,48 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
- (void)checkCanImportBackup - (void)checkCanImportBackup
{ {
OWSLogVerbose(@"");
[OWSBackup.sharedManager [OWSBackup.sharedManager
checkCanImportBackup:^(BOOL value) { checkCanImportBackup:^(BOOL value) {
OWSLogInfo(@"has backup available for import? %d", value); OWSLogInfo(@"has backup available for import? %d", value);
if (value) { if (value) {
[OWSBackup.sharedManager setHasPendingRestoreDecision:YES];
[self showBackupRestoreView]; [self showBackupRestoreView];
} else { } else {
[self showHomeView]; [self showHomeView];
} }
} }
failure:^(NSError *error) { failure:^(NSError *error) {
UIAlertController *controller = [UIAlertController [self showBackupCheckFailedAlert];
alertControllerWithTitle: }];
NSLocalizedString(@"CHECK_FOR_BACKUP_FAILED_TITLE", }
@"Title for alert shown when the app failed to check for an existing backup.")
message:NSLocalizedString(@"CHECK_FOR_BACKUP_FAILED_MESSAGE", - (void)showBackupCheckFailedAlert
@"Message for alert shown when the app failed to check for an existing " {
@"backup.") OWSLogVerbose(@"");
preferredStyle:UIAlertControllerStyleAlert];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"REGISTER_FAILED_TRY_AGAIN", nil) UIAlertController *controller = [UIAlertController
style:UIAlertActionStyleDefault alertControllerWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_FAILED_TITLE",
handler:^(UIAlertAction *action) { @"Title for alert shown when the app failed to check for an existing backup.")
[self checkCanImportBackup]; message:NSLocalizedString(@"CHECK_FOR_BACKUP_FAILED_MESSAGE",
}]]; @"Message for alert shown when the app failed to check for an existing "
[controller @"backup.")
addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_DO_NOT_RESTORE", preferredStyle:UIAlertControllerStyleAlert];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"REGISTER_FAILED_TRY_AGAIN", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self checkCanImportBackup];
}]];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_DO_NOT_RESTORE",
@"The label for the 'do not restore backup' button.") @"The label for the 'do not restore backup' button.")
style:UIAlertActionStyleDestructive style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[self showHomeView]; [self showHomeView];
}]]; }]];
[self presentViewController:controller animated:YES completion:nil]; [self presentViewController:controller animated:YES completion:nil];
}];
} }
#pragma mark - UITextFieldDelegate #pragma mark - UITextFieldDelegate

@ -7,12 +7,14 @@ import UIKit
@objc @objc
public class BackupRestoreViewController: OWSTableViewController { public class BackupRestoreViewController: OWSTableViewController {
private var hasBegunImport = false
private var backup: OWSBackup { private var backup: OWSBackup {
return AppEnvironment.shared.backup return AppEnvironment.shared.backup
} }
override public func loadView() { override public func loadView() {
navigationItem.title = NSLocalizedString("REMINDER_2FA_NAV_TITLE", comment: "Navbar title for when user is periodically prompted to enter their registration lock PIN") navigationItem.title = NSLocalizedString("SETTINGS_BACKUP", comment: "Label for the backup view in app settings.")
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didPressCancelButton)) navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didPressCancelButton))
} }
@ -25,12 +27,44 @@ public class BackupRestoreViewController: OWSTableViewController {
name: NSNotification.Name(NSNotificationNameBackupStateDidChange), name: NSNotification.Name(NSNotificationNameBackupStateDidChange),
object: nil) object: nil)
backup.tryToImport()
updateTableContents() updateTableContents()
} }
private func updateTableContents() { private func updateTableContents() {
if hasBegunImport {
updateProgressContents()
} else {
updateDecisionContents()
}
}
private func updateDecisionContents() {
let contents = OWSTableContents()
let section = OWSTableSection()
section.headerTitle = NSLocalizedString("BACKUP_RESTORE_DECISION_TITLE", comment: "Label for the backup restore decision section.")
section.add(OWSTableItem.actionItem(withText: NSLocalizedString("CHECK_FOR_BACKUP_DO_NOT_RESTORE",
comment: "The label for the 'do not restore backup' button."), actionBlock: { [weak self] in
guard let strongSelf = self else {
return
}
strongSelf.cancelAndDismiss()
}))
section.add(OWSTableItem.actionItem(withText: NSLocalizedString("CHECK_FOR_BACKUP_RESTORE",
comment: "The label for the 'restore backup' button."), actionBlock: { [weak self] in
guard let strongSelf = self else {
return
}
strongSelf.startImport()
}))
contents.addSection(section)
self.contents = contents
}
private func updateProgressContents() {
let contents = OWSTableContents() let contents = OWSTableContents()
let section = OWSTableSection() let section = OWSTableSection()
@ -70,9 +104,25 @@ public class BackupRestoreViewController: OWSTableViewController {
// TODO: Cancel import. // TODO: Cancel import.
cancelAndDismiss()
}
@objc
private func cancelAndDismiss() {
Logger.info("")
backup.setHasPendingRestoreDecision(false)
self.dismiss(animated: true) self.dismiss(animated: true)
} }
@objc
private func startImport() {
Logger.info("")
backup.tryToImport()
}
private func showHomeView() { private func showHomeView() {
SignalApp.shared().showHomeView() SignalApp.shared().showHomeView()
} }

@ -48,6 +48,9 @@ NSString *NSStringForBackupImportState(OWSBackupState state);
- (BOOL)isBackupEnabled; - (BOOL)isBackupEnabled;
- (void)setIsBackupEnabled:(BOOL)value; - (void)setIsBackupEnabled:(BOOL)value;
- (BOOL)hasPendingRestoreDecision;
- (void)setHasPendingRestoreDecision:(BOOL)value;
- (void)tryToExportBackup; - (void)tryToExportBackup;
- (void)cancelExportBackup; - (void)cancelExportBackup;

@ -18,6 +18,7 @@ NSString *const OWSPrimaryStorage_OWSBackupCollection = @"OWSPrimaryStorage_OWSB
NSString *const OWSBackup_IsBackupEnabledKey = @"OWSBackup_IsBackupEnabledKey"; NSString *const OWSBackup_IsBackupEnabledKey = @"OWSBackup_IsBackupEnabledKey";
NSString *const OWSBackup_LastExportSuccessDateKey = @"OWSBackup_LastExportSuccessDateKey"; NSString *const OWSBackup_LastExportSuccessDateKey = @"OWSBackup_LastExportSuccessDateKey";
NSString *const OWSBackup_LastExportFailureDateKey = @"OWSBackup_LastExportFailureDateKey"; NSString *const OWSBackup_LastExportFailureDateKey = @"OWSBackup_LastExportFailureDateKey";
NSString *const OWSBackup_HasPendingRestoreDecisionKey = @"OWSBackup_HasPendingRestoreDecisionKey";
NSString *NSStringForBackupExportState(OWSBackupState state) NSString *NSStringForBackupExportState(OWSBackupState state)
{ {
@ -237,6 +238,22 @@ NSString *NSStringForBackupImportState(OWSBackupState state)
[self ensureBackupExportState]; [self ensureBackupExportState];
} }
- (BOOL)hasPendingRestoreDecision
{
return [self.dbConnection boolForKey:OWSBackup_HasPendingRestoreDecisionKey
inCollection:OWSPrimaryStorage_OWSBackupCollection
defaultValue:NO];
}
- (void)setHasPendingRestoreDecision:(BOOL)value
{
OWSLogInfo(@"%d", value);
[self.dbConnection setBool:value
forKey:OWSBackup_HasPendingRestoreDecisionKey
inCollection:OWSPrimaryStorage_OWSBackupCollection];
}
- (BOOL)canBackupExport - (BOOL)canBackupExport
{ {
if (!self.isBackupEnabled) { if (!self.isBackupEnabled) {

Loading…
Cancel
Save