mirror of https://github.com/oxen-io/session-ios
Add import back up UI. Begin work on import backup logic.
parent
857ca56ab6
commit
272a90d269
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <SignalMessaging/OWSViewController.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class TSThread;
|
||||
|
||||
@interface OWSBackupImportViewController : OWSViewController
|
||||
|
||||
- (void)importBackup:(NSString *)backupZipPath password:(NSString *_Nullable)password;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,242 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSBackupImportViewController.h"
|
||||
#import "OWSBackup.h"
|
||||
#import "OWSProgressView.h"
|
||||
#import "Signal-Swift.h"
|
||||
#import "ThreadUtil.h"
|
||||
#import <SignalMessaging/AttachmentSharing.h>
|
||||
#import <SignalMessaging/Environment.h>
|
||||
#import <SignalMessaging/SignalMessaging-Swift.h>
|
||||
#import <SignalMessaging/UIColor+OWS.h>
|
||||
#import <SignalMessaging/UIFont+OWS.h>
|
||||
#import <SignalMessaging/UIView+OWS.h>
|
||||
#import <SignalServiceKit/MIMETypeUtil.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSBackupImportViewController () <OWSBackupDelegate>
|
||||
|
||||
@property (nonatomic) OWSBackup *backup;
|
||||
|
||||
@property (nonatomic, nullable) OWSProgressView *progressView;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSBackupImportViewController
|
||||
|
||||
- (void)loadView
|
||||
{
|
||||
[super loadView];
|
||||
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
self.navigationItem.title = NSLocalizedString(@"BACKUP_IMPORT_VIEW_TITLE", @"Title for the 'backup import' view.");
|
||||
self.navigationItem.leftBarButtonItem =
|
||||
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
|
||||
target:self
|
||||
action:@selector(dismissWasPressed:)];
|
||||
|
||||
self.backup.delegate = self;
|
||||
|
||||
[self updateUI];
|
||||
}
|
||||
|
||||
- (void)importBackup:(NSString *)backupZipPath password:(NSString *_Nullable)password
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
OWSAssert(backupZipPath.length > 0);
|
||||
|
||||
// We set ourselves as the delegate of the backup later,
|
||||
// after we've loaded our view.
|
||||
self.backup = [OWSBackup new];
|
||||
[self.backup importBackup:backupZipPath password:password];
|
||||
}
|
||||
|
||||
- (void)updateUI
|
||||
{
|
||||
for (UIView *subview in self.view.subviews) {
|
||||
[subview removeFromSuperview];
|
||||
}
|
||||
self.progressView = nil;
|
||||
|
||||
switch (self.backup.backupState) {
|
||||
case OWSBackupState_InProgress:
|
||||
[self showInProgressUI];
|
||||
break;
|
||||
case OWSBackupState_Cancelled:
|
||||
[self showCancelledUI];
|
||||
break;
|
||||
case OWSBackupState_Complete:
|
||||
[self showCompleteUI];
|
||||
break;
|
||||
case OWSBackupState_Failed:
|
||||
[self showFailedUI];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showInProgressUI
|
||||
{
|
||||
self.progressView = [OWSProgressView new];
|
||||
self.progressView.color = [UIColor ows_materialBlueColor];
|
||||
self.progressView.progress = self.backup.backupProgress;
|
||||
[self.progressView autoSetDimension:ALDimensionWidth toSize:300];
|
||||
[self.progressView autoSetDimension:ALDimensionHeight toSize:20];
|
||||
|
||||
UILabel *label = [UILabel new];
|
||||
label.text = NSLocalizedString(
|
||||
@"BACKUP_IMPORT_IN_PROGRESS_MESSAGE", @"Message indicating that backup import is in progress.");
|
||||
label.textColor = [UIColor blackColor];
|
||||
label.font = [UIFont ows_regularFontWithSize:18.f];
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.numberOfLines = 0;
|
||||
label.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
|
||||
UIView *container = [UIView verticalStackWithSubviews:@[
|
||||
label,
|
||||
self.progressView,
|
||||
]
|
||||
spacing:10];
|
||||
[self.view addSubview:container];
|
||||
[container autoVCenterInSuperview];
|
||||
[container autoPinWidthToSuperviewWithMargin:25.f];
|
||||
}
|
||||
|
||||
- (void)showCancelledUI
|
||||
{
|
||||
// Show nothing.
|
||||
}
|
||||
|
||||
- (void)showCompleteUI
|
||||
{
|
||||
NSMutableArray<UIView *> *subviews = [NSMutableArray new];
|
||||
|
||||
{
|
||||
NSString *message = NSLocalizedString(
|
||||
@"BACKUP_IMPORT_COMPLETE_MESSAGE", @"Message indicating that backup import is complete.");
|
||||
|
||||
UILabel *label = [UILabel new];
|
||||
label.text = message;
|
||||
label.textColor = [UIColor blackColor];
|
||||
label.font = [UIFont ows_regularFontWithSize:18.f];
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.numberOfLines = 0;
|
||||
label.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
[subviews addObject:label];
|
||||
}
|
||||
|
||||
if (self.backup.backupPassword) {
|
||||
NSString *message = [NSString stringWithFormat:NSLocalizedString(@"BACKUP_IMPORT_PASSWORD_MESSAGE_FORMAT",
|
||||
@"Format for message indicating that backup import "
|
||||
@"is complete. Embeds: {{the backup password}}."),
|
||||
self.backup.backupPassword];
|
||||
|
||||
UILabel *label = [UILabel new];
|
||||
label.text = message;
|
||||
label.textColor = [UIColor blackColor];
|
||||
label.font = [UIFont ows_regularFontWithSize:14.f];
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.numberOfLines = 0;
|
||||
label.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
[subviews addObject:label];
|
||||
}
|
||||
|
||||
[subviews addObject:[UIView new]];
|
||||
|
||||
if (self.backup.backupPassword) {
|
||||
[subviews
|
||||
addObject:[self makeButtonWithTitle:NSLocalizedString(@"BACKUP_IMPORT_COPY_PASSWORD_BUTTON",
|
||||
@"Label for button that copies backup password to the pasteboard.")
|
||||
selector:@selector(copyPassword)]];
|
||||
}
|
||||
|
||||
[subviews addObject:[self makeButtonWithTitle:NSLocalizedString(@"BACKUP_IMPORT_SHARE_BACKUP_BUTTON",
|
||||
@"Label for button that opens share UI for backup.")
|
||||
selector:@selector(shareBackup)]];
|
||||
|
||||
if (self.backup.currentThread) {
|
||||
[subviews
|
||||
addObject:[self makeButtonWithTitle:NSLocalizedString(@"BACKUP_IMPORT_SEND_BACKUP_BUTTON",
|
||||
@"Label for button that 'send backup' in the current conversation.")
|
||||
selector:@selector(sendBackup)]];
|
||||
}
|
||||
|
||||
// TODO: We should offer the option to save the backup to "Files", iCloud, Dropbox, etc.
|
||||
|
||||
UIView *container = [UIView verticalStackWithSubviews:subviews spacing:10];
|
||||
[self.view addSubview:container];
|
||||
[container autoVCenterInSuperview];
|
||||
[container autoPinWidthToSuperviewWithMargin:25.f];
|
||||
}
|
||||
|
||||
- (void)showFailedUI
|
||||
{
|
||||
NSMutableArray<UIView *> *subviews = [NSMutableArray new];
|
||||
|
||||
{
|
||||
NSString *message
|
||||
= NSLocalizedString(@"BACKUP_IMPORT_FAILED_MESSAGE", @"Message indicating that backup import failed.");
|
||||
|
||||
UILabel *label = [UILabel new];
|
||||
label.text = message;
|
||||
label.textColor = [UIColor blackColor];
|
||||
label.font = [UIFont ows_regularFontWithSize:18.f];
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.numberOfLines = 0;
|
||||
label.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
[subviews addObject:label];
|
||||
}
|
||||
|
||||
// TODO: We should offer the option to save the backup to "Files", iCloud, Dropbox, etc.
|
||||
|
||||
UIView *container = [UIView verticalStackWithSubviews:subviews spacing:10];
|
||||
[self.view addSubview:container];
|
||||
[container autoVCenterInSuperview];
|
||||
[container autoPinWidthToSuperviewWithMargin:25.f];
|
||||
}
|
||||
|
||||
- (UIView *)makeButtonWithTitle:(NSString *)title selector:(SEL)selector
|
||||
{
|
||||
const CGFloat kButtonHeight = 40;
|
||||
OWSFlatButton *button = [OWSFlatButton buttonWithTitle:title
|
||||
font:[OWSFlatButton fontForHeight:kButtonHeight]
|
||||
titleColor:[UIColor whiteColor]
|
||||
backgroundColor:[UIColor ows_materialBlueColor]
|
||||
target:self
|
||||
selector:selector];
|
||||
[button autoSetDimension:ALDimensionWidth toSize:140];
|
||||
[button autoSetDimension:ALDimensionHeight toSize:kButtonHeight];
|
||||
return button;
|
||||
}
|
||||
|
||||
- (void)dismissWasPressed:(id)sender
|
||||
{
|
||||
[self.backup cancel];
|
||||
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - OWSBackupDelegate
|
||||
|
||||
- (void)backupStateDidChange
|
||||
{
|
||||
DDLogInfo(@"%@ %s.", self.logTag, __PRETTY_FUNCTION__);
|
||||
|
||||
[self updateUI];
|
||||
}
|
||||
|
||||
- (void)backupProgressDidChange
|
||||
{
|
||||
DDLogInfo(@"%@ %s.", self.logTag, __PRETTY_FUNCTION__);
|
||||
|
||||
self.progressView.progress = self.backup.backupProgress;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue