Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display backup import progress #7319

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,7 @@ Tap the + to start adding people.";

// Recover from private key
"key_backup_recover_from_private_key_info" = "Restoring backup…";
"key_backup_recover_from_private_key_progress" = "%@%% Complete";

// Recover from passphrase

Expand Down
4 changes: 4 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,10 @@ public class VectorL10n: NSObject {
public static var keyBackupRecoverFromPrivateKeyInfo: String {
return VectorL10n.tr("Vector", "key_backup_recover_from_private_key_info")
}
/// %@%% Complete
public static func keyBackupRecoverFromPrivateKeyProgress(_ p1: String) -> String {
return VectorL10n.tr("Vector", "key_backup_recover_from_private_key_progress", p1)
}
/// Use your Security Key to unlock your secure message history
public static var keyBackupRecoverFromRecoveryKeyInfo: String {
return VectorL10n.tr("Vector", "key_backup_recover_from_recovery_key_info")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="cb6-oF-e0m">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="cb6-oF-e0m">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Key Backup Recover Data Loading View Controller-->
<!--Key Backup Recover From Private Key View Controller-->
<scene sceneID="JIv-4y-eqa">
<objects>
<viewController extendedLayoutIncludesOpaqueBars="YES" automaticallyAdjustsScrollViewInsets="NO" id="cb6-oF-e0m" customClass="KeyBackupRecoverFromPrivateKeyViewController" customModule="Riot" customModuleProvider="target" sceneMemberID="viewController">
<viewController extendedLayoutIncludesOpaqueBars="YES" automaticallyAdjustsScrollViewInsets="NO" id="cb6-oF-e0m" customClass="KeyBackupRecoverFromPrivateKeyViewController" customModule="Element" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="JOd-8G-rga">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="cUL-rS-rfi">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="a4s-VR-9rG">
<rect key="frame" x="0.0" y="0.0" width="375" height="239"/>
Expand All @@ -40,15 +38,24 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="0% complete" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bMp-hX-C4X">
<rect key="frame" x="20" y="160" width="335" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="c3s-XT-wGy" firstAttribute="top" secondItem="AA6-5y-aKB" secondAttribute="top" constant="35" id="2hk-29-LeR"/>
<constraint firstItem="1dN-Ld-mvf" firstAttribute="top" secondItem="c3s-XT-wGy" secondAttribute="bottom" constant="30" id="7oJ-n1-Vec"/>
<constraint firstAttribute="trailing" secondItem="bMp-hX-C4X" secondAttribute="trailing" constant="20" id="BLV-CI-4bJ"/>
<constraint firstAttribute="trailing" secondItem="1dN-Ld-mvf" secondAttribute="trailing" constant="20" id="RRJ-XS-DKi"/>
<constraint firstItem="1dN-Ld-mvf" firstAttribute="leading" secondItem="AA6-5y-aKB" secondAttribute="leading" constant="20" id="bgC-6o-Qd3"/>
<constraint firstItem="bMp-hX-C4X" firstAttribute="leading" secondItem="AA6-5y-aKB" secondAttribute="leading" constant="20" id="ePA-YY-3Bd"/>
<constraint firstItem="c3s-XT-wGy" firstAttribute="centerX" secondItem="AA6-5y-aKB" secondAttribute="centerX" id="hhx-MR-Ssb"/>
<constraint firstAttribute="width" priority="750" constant="500" id="qn9-3x-Vus"/>
<constraint firstItem="bMp-hX-C4X" firstAttribute="top" secondItem="1dN-Ld-mvf" secondAttribute="bottom" constant="31" id="zle-dL-YQn"/>
</constraints>
</view>
</subviews>
Expand All @@ -72,17 +79,18 @@
</constraints>
</scrollView>
</subviews>
<viewLayoutGuide key="safeArea" id="Y3k-2C-Pek"/>
<color key="backgroundColor" red="0.94509803920000002" green="0.96078431369999995" blue="0.97254901959999995" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="cUL-rS-rfi" firstAttribute="leading" secondItem="Y3k-2C-Pek" secondAttribute="leading" id="9ZI-Gm-3DT"/>
<constraint firstItem="Y3k-2C-Pek" firstAttribute="trailing" secondItem="cUL-rS-rfi" secondAttribute="trailing" id="QwC-RO-L6M"/>
<constraint firstItem="Y3k-2C-Pek" firstAttribute="top" secondItem="cUL-rS-rfi" secondAttribute="top" id="ffm-HV-RhA"/>
<constraint firstAttribute="bottom" secondItem="cUL-rS-rfi" secondAttribute="bottom" id="rib-a1-j68"/>
</constraints>
<viewLayoutGuide key="safeArea" id="Y3k-2C-Pek"/>
</view>
<connections>
<outlet property="informationLabel" destination="1dN-Ld-mvf" id="RAQ-9H-hXQ"/>
<outlet property="progressLabel" destination="bMp-hX-C4X" id="Hhf-4p-YYP"/>
<outlet property="shieldImageView" destination="c3s-XT-wGy" id="jVg-AC-PGB"/>
</connections>
</viewController>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class KeyBackupRecoverFromPrivateKeyViewController: UIViewController {
@IBOutlet private weak var shieldImageView: UIImageView!

@IBOutlet private weak var informationLabel: UILabel!
@IBOutlet private weak var progressLabel: UILabel!

// MARK: Private

Expand Down Expand Up @@ -118,17 +119,20 @@ final class KeyBackupRecoverFromPrivateKeyViewController: UIViewController {

private func render(viewState: KeyBackupRecoverFromPrivateKeyViewState) {
switch viewState {
case .loading:
self.renderLoading()
case .loading(let progress):
self.renderLoading(progress: progress)
case .loaded:
self.renderLoaded()
case .error(let error):
self.render(error: error)
}
}

private func renderLoading() {
private func renderLoading(progress: Double) {
self.activityPresenter.presentActivityIndicator(on: self.view, animated: true)

let percent = Int(round(progress * 100))
self.progressLabel.text = VectorL10n.keyBackupRecoverFromPrivateKeyProgress("\(percent)")
}

private func renderLoaded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class KeyBackupRecoverFromPrivateKeyViewModel: KeyBackupRecoverFromPrivate
private let keyBackup: MXKeyBackup
private var currentHTTPOperation: MXHTTPOperation?
private let keyBackupVersion: MXKeyBackupVersion
private var progressUpdateTimer: Timer?

// MARK: Public

Expand Down Expand Up @@ -56,7 +57,14 @@ final class KeyBackupRecoverFromPrivateKeyViewModel: KeyBackupRecoverFromPrivate

private func recoverWithPrivateKey() {

self.update(viewState: .loading)
self.update(viewState: .loading(0))

// Update loading progress every second until no longer loading
progressUpdateTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in
if let progress = self?.keyBackup.importProgress {
self?.update(viewState: .loading(progress.fractionCompleted))
}
}

self.currentHTTPOperation = keyBackup.restore(usingPrivateKeyKeyBackup: keyBackupVersion, room: nil, session: nil, success: { [weak self] (_, _) in
guard let self = self else {
Expand Down Expand Up @@ -91,6 +99,11 @@ final class KeyBackupRecoverFromPrivateKeyViewModel: KeyBackupRecoverFromPrivate
}

private func update(viewState: KeyBackupRecoverFromPrivateKeyViewState) {
if case .loading = viewState {} else {
progressUpdateTimer?.invalidate()
progressUpdateTimer = nil
}

self.viewDelegate?.keyBackupRecoverFromPrivateKeyViewModel(self, didUpdateViewState: viewState)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Foundation

/// KeyBackupRecoverFromPrivateKeyViewController view state
enum KeyBackupRecoverFromPrivateKeyViewState {
case loading
case loading(Double)
case loaded
case error(Error)
}
1 change: 1 addition & 0 deletions changelog.d/pr-7319.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Backup: Display backup import progress