Sketch out backup export UI.

pull/1/head
Matthew Chen 6 years ago
parent 669a3610ab
commit 91bf0bdb9f

@ -70,9 +70,87 @@ NS_ASSUME_NONNULL_BEGIN
selector:@selector(isBackupEnabledDidChange:)]];
[contents addSection:enableSection];
if (isBackupEnabled) {
// TODO: This UI is temporary.
// Enabling backup will involve entering and registering a PIN.
OWSTableSection *progressSection = [OWSTableSection new];
[progressSection
addItem:[OWSTableItem labelItemWithText:NSLocalizedString(@"SETTINGS_BACKUP_STATUS",
@"Label for status row in the in the backup settings view.")
accessoryText:[self backupExportStateLocalizedDescription]]];
if (OWSBackup.sharedManager.backupExportState == OWSBackupState_InProgress) {
if (OWSBackup.sharedManager.backupExportDescription) {
[progressSection
addItem:[OWSTableItem
labelItemWithText:NSLocalizedString(@"SETTINGS_BACKUP_PHASE",
@"Label for phase row in the in the backup settings view.")
accessoryText:OWSBackup.sharedManager.backupExportDescription]];
if (OWSBackup.sharedManager.backupExportProgress) {
NSUInteger progressPercent
= (NSUInteger)round(OWSBackup.sharedManager.backupExportProgress.floatValue * 100);
DDLogVerbose(@"%@ '%@', '%@'",
self.logTag,
@(progressPercent).stringValue,
[NSString
stringWithFormat:NSLocalizedString(@"PERCENTAGE_FORMAT",
@"Format for percentages, e.g. 65%. Embeds {{percentage}}, e.g. 65."),
@(progressPercent).stringValue]);
[progressSection
addItem:[OWSTableItem
labelItemWithText:NSLocalizedString(@"SETTINGS_BACKUP_PROGRESS",
@"Label for phase row in the in the backup settings view.")
accessoryText:[NSString
stringWithFormat:NSLocalizedString(@"PERCENTAGE_FORMAT",
@"Format for percentages, e.g. 65%. "
@"Embeds {{percentage}}, e.g. 65."),
@(progressPercent).stringValue]]];
}
}
}
switch (OWSBackup.sharedManager.backupExportState) {
case OWSBackupState_Idle:
case OWSBackupState_Failed:
case OWSBackupState_Succeeded:
[progressSection
addItem:[OWSTableItem disclosureItemWithText:
NSLocalizedString(@"SETTINGS_BACKUP_BACKUP_NOW",
@"Label for 'backup now' button in the backup settings view.")
actionBlock:^{
[OWSBackup.sharedManager tryToExportBackup];
}]];
break;
case OWSBackupState_InProgress:
[progressSection
addItem:[OWSTableItem disclosureItemWithText:
NSLocalizedString(@"SETTINGS_BACKUP_CANCEL_BACKUP",
@"Label for 'cancel backup' button in the backup settings view.")
actionBlock:^{
[OWSBackup.sharedManager cancelExportBackup];
}]];
break;
}
[contents addSection:progressSection];
}
self.contents = contents;
}
- (NSString *)backupExportStateLocalizedDescription
{
switch (OWSBackup.sharedManager.backupExportState) {
case OWSBackupState_Idle:
return NSLocalizedString(@"SETTINGS_BACKUP_STATUS_IDLE", @"Indicates that app is not backing up.");
case OWSBackupState_InProgress:
return NSLocalizedString(@"SETTINGS_BACKUP_STATUS_IN_PROGRESS", @"Indicates that app is backing up.");
case OWSBackupState_Failed:
return NSLocalizedString(@"SETTINGS_BACKUP_STATUS_FAILED", @"Indicates that the last backup failed.");
case OWSBackupState_Succeeded:
return NSLocalizedString(@"SETTINGS_BACKUP_STATUS_SUCCEEDED", @"Indicates that the last backup succeeded.");
}
}
- (void)isBackupEnabledDidChange:(UISwitch *)sender
{
[OWSBackup.sharedManager setIsBackupEnabled:sender.isOn];

@ -33,6 +33,7 @@ typedef NS_ENUM(NSUInteger, OWSBackupState) {
#pragma mark - Backup Export
@property (nonatomic, readonly) OWSBackupState backupExportState;
// If a "backup export" is in progress (see backupExportState),
// backupExportDescription _might_ contain a string that describes
// the current phase and backupExportProgress _might_ contain a
@ -44,9 +45,13 @@ typedef NS_ENUM(NSUInteger, OWSBackupState) {
- (BOOL)isBackupEnabled;
- (void)setIsBackupEnabled:(BOOL)value;
- (void)tryToExportBackup;
- (void)cancelExportBackup;
#pragma mark - Backup Import
@property (nonatomic, readonly) OWSBackupState backupImportState;
// If a "backup import" is in progress (see backupImportState),
// backupImportDescription _might_ contain a string that describes
// the current phase and backupImportProgress _might_ contain a

@ -134,6 +134,41 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Backup Export
- (void)tryToExportBackup
{
OWSAssertIsOnMainThread();
OWSAssert(!self.backupExportJob);
if (!self.canBackupExport) {
// TODO: Offer a reason in the UI.
return;
}
// In development, make sure there's no export or import in progress.
[self.backupExportJob cancel];
self.backupExportJob = nil;
[self.backupImportJob cancel];
self.backupImportJob = nil;
_backupExportState = OWSBackupState_InProgress;
self.backupExportJob =
[[OWSBackupExportJob alloc] initWithDelegate:self primaryStorage:[OWSPrimaryStorage sharedManager]];
[self.backupExportJob startAsync];
[self postDidChangeNotification];
}
- (void)cancelExportBackup
{
[self.backupExportJob cancel];
self.backupExportJob = nil;
_backupExportState = OWSBackupState_Idle;
[self postDidChangeNotification];
}
- (void)setLastExportSuccessDate:(NSDate *)value
{
OWSAssert(value);
@ -190,7 +225,7 @@ NS_ASSUME_NONNULL_BEGIN
[self ensureBackupExportState];
}
- (BOOL)shouldHaveBackupExport
- (BOOL)canBackupExport
{
if (!self.isBackupEnabled) {
return NO;
@ -202,6 +237,18 @@ NS_ASSUME_NONNULL_BEGIN
if (![TSAccountManager isRegistered]) {
return NO;
}
return YES;
}
- (BOOL)shouldHaveBackupExport
{
if (!self.canBackupExport) {
return NO;
}
if (self.backupExportJob) {
// If there's already a job in progress, let it complete.
return YES;
}
NSDate *_Nullable lastExportSuccessDate = self.lastExportSuccessDate;
NSDate *_Nullable lastExportFailureDate = self.lastExportFailureDate;
// Wait N hours before retrying after a success.

@ -1213,6 +1213,9 @@
/* A display format for oversize text messages. */
"OVERSIZE_TEXT_DISPLAY_FORMAT" = "%@…";
/* Format for percentages, e.g. 65%. Embeds {{percentage}}, e.g. 65. */
"PERCENTAGE_FORMAT" = "%@%%";
/* A format for a label showing an example phone number. Embeds {{the example phone number}}. */
"PHONE_NUMBER_EXAMPLE_FORMAT" = "Example: %@";
@ -1585,9 +1588,36 @@
/* Label for the backup view in app settings. */
"SETTINGS_BACKUP" = "Backup";
/* Label for 'backup now' button in the backup settings view. */
"SETTINGS_BACKUP_BACKUP_NOW" = "Backup Now";
/* Label for 'cancel backup' button in the backup settings view. */
"SETTINGS_BACKUP_CANCEL_BACKUP" = "Cancel Backup";
/* Label for switch in settings that controls whether or not backup is enabled. */
"SETTINGS_BACKUP_ENABLING_SWITCH" = "Backup Enabled";
/* Label for phase row in the in the backup settings view. */
"SETTINGS_BACKUP_PHASE" = "Phase";
/* Label for phase row in the in the backup settings view. */
"SETTINGS_BACKUP_PROGRESS" = "Progress";
/* Label for status row in the in the backup settings view. */
"SETTINGS_BACKUP_STATUS" = "Status";
/* Indicates that the last backup failed. */
"SETTINGS_BACKUP_STATUS_FAILED" = "Backup Failed";
/* Indicates that app is not backing up. */
"SETTINGS_BACKUP_STATUS_IDLE" = "Waiting";
/* Indicates that app is backing up. */
"SETTINGS_BACKUP_STATUS_IN_PROGRESS" = "Backing Up";
/* Indicates that the last backup succeeded. */
"SETTINGS_BACKUP_STATUS_SUCCEEDED" = "Backup Successful";
/* A label for the 'add phone number' button in the block list table. */
"SETTINGS_BLOCK_LIST_ADD_BUTTON" = "Add…";

Loading…
Cancel
Save