mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Sketch out the backup restore view.
This commit is contained in:
parent
5010b027b1
commit
332f202a52
|
@ -421,11 +421,15 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
|||
|
||||
- (void)updateProfileCompleted
|
||||
{
|
||||
OWSLogVerbose(@"");
|
||||
|
||||
[self profileCompletedOrSkipped];
|
||||
}
|
||||
|
||||
- (void)profileCompletedOrSkipped
|
||||
{
|
||||
OWSLogVerbose(@"");
|
||||
|
||||
// Dismiss this view.
|
||||
switch (self.profileViewMode) {
|
||||
case ProfileViewMode_AppSettings:
|
||||
|
@ -446,11 +450,15 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
|||
|
||||
- (void)showHomeView
|
||||
{
|
||||
OWSLogVerbose(@"");
|
||||
|
||||
[SignalApp.sharedApp showHomeView];
|
||||
}
|
||||
|
||||
- (void)showBackupRestoreView
|
||||
{
|
||||
OWSLogVerbose(@"");
|
||||
|
||||
BackupRestoreViewController *restoreView = [BackupRestoreViewController new];
|
||||
[self.navigationController setViewControllers:@[
|
||||
restoreView,
|
||||
|
@ -460,39 +468,48 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
|||
|
||||
- (void)checkCanImportBackup
|
||||
{
|
||||
OWSLogVerbose(@"");
|
||||
|
||||
[OWSBackup.sharedManager
|
||||
checkCanImportBackup:^(BOOL value) {
|
||||
OWSLogInfo(@"has backup available for import? %d", value);
|
||||
|
||||
if (value) {
|
||||
[OWSBackup.sharedManager setHasPendingRestoreDecision:YES];
|
||||
|
||||
[self showBackupRestoreView];
|
||||
} else {
|
||||
[self showHomeView];
|
||||
}
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
UIAlertController *controller = [UIAlertController
|
||||
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",
|
||||
@"Message for alert shown when the app failed to check for an existing "
|
||||
@"backup.")
|
||||
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",
|
||||
[self showBackupCheckFailedAlert];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)showBackupCheckFailedAlert
|
||||
{
|
||||
OWSLogVerbose(@"");
|
||||
|
||||
UIAlertController *controller = [UIAlertController
|
||||
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",
|
||||
@"Message for alert shown when the app failed to check for an existing "
|
||||
@"backup.")
|
||||
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.")
|
||||
style:UIAlertActionStyleDestructive
|
||||
handler:^(UIAlertAction *action) {
|
||||
[self showHomeView];
|
||||
}]];
|
||||
[self presentViewController:controller animated:YES completion:nil];
|
||||
}];
|
||||
[self presentViewController:controller animated:YES completion:nil];
|
||||
}
|
||||
|
||||
#pragma mark - UITextFieldDelegate
|
||||
|
|
|
@ -7,12 +7,14 @@ import UIKit
|
|||
@objc
|
||||
public class BackupRestoreViewController: OWSTableViewController {
|
||||
|
||||
private var hasBegunImport = false
|
||||
|
||||
private var backup: OWSBackup {
|
||||
return AppEnvironment.shared.backup
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
@ -25,12 +27,44 @@ public class BackupRestoreViewController: OWSTableViewController {
|
|||
name: NSNotification.Name(NSNotificationNameBackupStateDidChange),
|
||||
object: nil)
|
||||
|
||||
backup.tryToImport()
|
||||
|
||||
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 section = OWSTableSection()
|
||||
|
@ -70,9 +104,25 @@ public class BackupRestoreViewController: OWSTableViewController {
|
|||
|
||||
// TODO: Cancel import.
|
||||
|
||||
cancelAndDismiss()
|
||||
}
|
||||
|
||||
@objc
|
||||
private func cancelAndDismiss() {
|
||||
Logger.info("")
|
||||
|
||||
backup.setHasPendingRestoreDecision(false)
|
||||
|
||||
self.dismiss(animated: true)
|
||||
}
|
||||
|
||||
@objc
|
||||
private func startImport() {
|
||||
Logger.info("")
|
||||
|
||||
backup.tryToImport()
|
||||
}
|
||||
|
||||
private func showHomeView() {
|
||||
SignalApp.shared().showHomeView()
|
||||
}
|
||||
|
|
|
@ -48,6 +48,9 @@ NSString *NSStringForBackupImportState(OWSBackupState state);
|
|||
- (BOOL)isBackupEnabled;
|
||||
- (void)setIsBackupEnabled:(BOOL)value;
|
||||
|
||||
- (BOOL)hasPendingRestoreDecision;
|
||||
- (void)setHasPendingRestoreDecision:(BOOL)value;
|
||||
|
||||
- (void)tryToExportBackup;
|
||||
- (void)cancelExportBackup;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ NSString *const OWSPrimaryStorage_OWSBackupCollection = @"OWSPrimaryStorage_OWSB
|
|||
NSString *const OWSBackup_IsBackupEnabledKey = @"OWSBackup_IsBackupEnabledKey";
|
||||
NSString *const OWSBackup_LastExportSuccessDateKey = @"OWSBackup_LastExportSuccessDateKey";
|
||||
NSString *const OWSBackup_LastExportFailureDateKey = @"OWSBackup_LastExportFailureDateKey";
|
||||
NSString *const OWSBackup_HasPendingRestoreDecisionKey = @"OWSBackup_HasPendingRestoreDecisionKey";
|
||||
|
||||
NSString *NSStringForBackupExportState(OWSBackupState state)
|
||||
{
|
||||
|
@ -237,6 +238,22 @@ NSString *NSStringForBackupImportState(OWSBackupState state)
|
|||
[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
|
||||
{
|
||||
if (!self.isBackupEnabled) {
|
||||
|
|
Loading…
Reference in a new issue