forked from signalapp/Signal-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c0d98b
commit 5010b02
Showing
9 changed files
with
166 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
Signal/src/ViewControllers/Registration/BackupRestoreViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
@objc | ||
public class BackupRestoreViewController: OWSTableViewController { | ||
|
||
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.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didPressCancelButton)) | ||
} | ||
|
||
override public func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
NotificationCenter.default.addObserver(self, | ||
selector: #selector(backupStateDidChange), | ||
name: NSNotification.Name(NSNotificationNameBackupStateDidChange), | ||
object: nil) | ||
|
||
backup.tryToImport() | ||
|
||
updateTableContents() | ||
} | ||
|
||
private func updateTableContents() { | ||
let contents = OWSTableContents() | ||
|
||
let section = OWSTableSection() | ||
|
||
section.add(OWSTableItem.label(withText: NSLocalizedString("BACKUP_RESTORE_STATUS", comment: "Label for the backup restore status."), accessoryText: NSStringForBackupImportState(backup.backupImportState))) | ||
|
||
if backup.backupImportState == .inProgress { | ||
if let backupImportDescription = backup.backupImportDescription { | ||
section.add(OWSTableItem.label(withText: NSLocalizedString("BACKUP_RESTORE_DESCRIPTION", comment: "Label for the backup restore description."), accessoryText: backupImportDescription)) | ||
} | ||
|
||
if let backupImportProgress = backup.backupImportProgress { | ||
let progressInt = backupImportProgress.floatValue * 100 | ||
let numberFormatter = NumberFormatter() | ||
numberFormatter.numberStyle = .percent | ||
numberFormatter.maximumFractionDigits = 0 | ||
numberFormatter.multiplier = 1 | ||
if let progressString = numberFormatter.string(from: NSNumber(value: progressInt)) { | ||
section.add(OWSTableItem.label(withText: NSLocalizedString("BACKUP_RESTORE_PROGRESS", comment: "Label for the backup restore progress."), accessoryText: progressString)) | ||
} else { | ||
owsFailDebug("Could not format progress: \(progressInt)") | ||
} | ||
} | ||
} | ||
|
||
contents.addSection(section) | ||
self.contents = contents | ||
|
||
// TODO: Add cancel button. | ||
} | ||
|
||
// MARK: Helpers | ||
|
||
@objc | ||
private func didPressCancelButton(sender: UIButton) { | ||
Logger.info("") | ||
|
||
// TODO: Cancel import. | ||
|
||
self.dismiss(animated: true) | ||
} | ||
|
||
private func showHomeView() { | ||
SignalApp.shared().showHomeView() | ||
} | ||
|
||
// MARK: - Notifications | ||
|
||
@objc func backupStateDidChange() { | ||
AssertIsOnMainThread() | ||
|
||
if backup.backupImportState == .succeeded { | ||
showHomeView() | ||
} else { | ||
updateTableContents() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,8 @@ NS_ASSUME_NONNULL_BEGIN | |
|
||
+ (void)clearAllNotifications; | ||
|
||
- (void)showHomeView; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters