From 5c0d98b83a61f5b390d1de7ed645ac68f07e9ba7 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 19 Nov 2018 16:17:40 -0500 Subject: [PATCH] Show 'restore backup' view after registration. --- .../ViewControllers/ProfileViewController.m | 51 +++++++++++++++++++ .../translations/en.lproj/Localizable.strings | 13 ++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 5925a1472..f8a5cf315 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -432,6 +432,10 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat [self.navigationController popViewControllerAnimated:YES]; break; case ProfileViewMode_Registration: + if (![TSAccountManager sharedInstance].isReregistering) { + [self checkCanImportBackup]; + return; + } [self showHomeView]; break; case ProfileViewMode_UpgradeOrNag: @@ -450,6 +454,53 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat OWSAssertDebug([navigationController.topViewController isKindOfClass:[HomeViewController class]]); } +- (void)showBackupRestoreView +{ + HomeViewController *homeView = [HomeViewController new]; + SignalsNavigationController *navigationController = + [[SignalsNavigationController alloc] initWithRootViewController:homeView]; + AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; + appDelegate.window.rootViewController = navigationController; + OWSAssertDebug([navigationController.topViewController isKindOfClass:[HomeViewController class]]); +} + +- (void)checkCanImportBackup +{ + [OWSBackup.sharedManager + checkCanImportBackup:^(BOOL value) { + OWSLogInfo(@"has backup available for import? %d", value); + + if (value) { + [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", + @"The label for the 'do not restore backup' button.") + style:UIAlertActionStyleDestructive + handler:^(UIAlertAction *action) { + [self showHomeView]; + }]]; + [self presentViewController:controller animated:YES completion:nil]; + }]; +} + #pragma mark - UITextFieldDelegate - (BOOL)textField:(UITextField *)textField diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 7c0197027..4aec8f915 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -383,6 +383,15 @@ /* Title for the 'censorship circumvention country' view. */ "CENSORSHIP_CIRCUMVENTION_COUNTRY_VIEW_TITLE" = "Select Country"; +/* The label for the 'do not restore backup' button. */ +"CHECK_FOR_BACKUP_DO_NOT_RESTORE" = "Do Not Restore"; + +/* Message for alert shown when the app failed to check for an existing backup. */ +"CHECK_FOR_BACKUP_FAILED_MESSAGE" = "Could not determine whether there is a backup that can be restored."; + +/* Title for alert shown when the app failed to check for an existing backup. */ +"CHECK_FOR_BACKUP_FAILED_TITLE" = "Error"; + /* Error indicating that the app could not determine that user's CloudKit account status */ "CLOUDKIT_STATUS_COULD_NOT_DETERMINE" = "There was an error communicating with iCloud for backups."; @@ -1511,8 +1520,8 @@ /* Label for 'Work FAX' phone numbers. */ "PHONE_NUMBER_TYPE_WORK_FAX" = "Work Fax"; -/* navbar title when viewing the default photo album, which includes all photos */ -"PHOTO_PICKER_DEFAULT_ALBUM" = "All Photos"; +/* label for system photo collections which have no name. */ +"PHOTO_PICKER_UNNAMED_COLLECTION" = "PHOTO_PICKER_UNNAMED_COLLECTION"; /* Accessibility label for button to start media playback */ "PLAY_BUTTON_ACCESSABILITY_LABEL" = "Play Media";