Update key backup setup passphrase scene

This commit is contained in:
SBiOSoftWhare
2019-02-13 13:46:05 +01:00
parent 352a0e9a48
commit a4cff07872
8 changed files with 164 additions and 64 deletions
@@ -57,11 +57,16 @@ final class KeyBackupSetupPassphraseCoordinator: KeyBackupSetupPassphraseCoordin
// MARK: - KeyBackupSetupPassphraseViewModelCoordinatorDelegate
extension KeyBackupSetupPassphraseCoordinator: KeyBackupSetupPassphraseViewModelCoordinatorDelegate {
func keyBackupSetupPassphraseViewModel(_ viewModel: KeyBackupSetupPassphraseViewModelType, didCreateBackupFromPassphraseWithResultingRecoveryKey recoveryKey: String) {
self.delegate?.keyBackupSetupPassphraseCoordinator(self, didCreateBackupFromPassphraseWithResultingRecoveryKey: recoveryKey)
}
func keyBackupSetupPassphraseViewModel(_ viewModel: KeyBackupSetupPassphraseViewModelType, didCreateBackupFromRecoveryKey recoveryKey: String) {
self.delegate?.keyBackupSetupPassphraseCoordinator(self, didCreateBackupFromRecoveryKey: recoveryKey)
}
func keyBackupSetupPassphraseViewModelDidCancel(_ viewModel: KeyBackupSetupPassphraseViewModelType) {
self.delegate?.keyBackupSetupPassphraseCoordinatorDidCancel(self)
}
func keyBackupSetupPassphraseViewModel(_ viewModel: KeyBackupSetupPassphraseViewModelType, didCompleteWithMegolmBackupCreationInfo megolmBackupCreationInfo: MXMegolmBackupCreationInfo) {
self.delegate?.keyBackupSetupPassphraseCoordinator(self, didCompleteWithMegolmBackupCreationInfo: megolmBackupCreationInfo)
}
}
@@ -17,7 +17,8 @@
import Foundation
protocol KeyBackupSetupPassphraseCoordinatorDelegate: class {
func keyBackupSetupPassphraseCoordinator(_ keyBackupSetupPassphraseCoordinator: KeyBackupSetupPassphraseCoordinatorType, didCompleteWithMegolmBackupCreationInfo megolmBackupCreationInfo: MXMegolmBackupCreationInfo)
func keyBackupSetupPassphraseCoordinator(_ keyBackupSetupPassphraseCoordinator: KeyBackupSetupPassphraseCoordinatorType, didCreateBackupFromPassphraseWithResultingRecoveryKey recoveryKey: String)
func keyBackupSetupPassphraseCoordinator(_ keyBackupSetupPassphraseCoordinator: KeyBackupSetupPassphraseCoordinatorType, didCreateBackupFromRecoveryKey recoveryKey: String)
func keyBackupSetupPassphraseCoordinatorDidCancel(_ keyBackupSetupPassphraseCoordinator: KeyBackupSetupPassphraseCoordinatorType)
}
@@ -19,6 +19,7 @@ import Foundation
/// KeyBackupSetupPassphraseViewController view actions exposed to view model
enum KeyBackupSetupPassphraseViewAction {
case setupPassphrase
case setupRecoveryKey
case skip
case skipAlertSkip
case skipAlertContinue
@@ -22,22 +22,28 @@
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="e7g-um-WO4">
<rect key="frame" x="0.0" y="0.0" width="375" height="563"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="767"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="voD-3Q-ryt">
<rect key="frame" x="0.0" y="0.0" width="375" height="563"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="767"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Secure your backup with a Passphrase" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6PP-oV-wYT">
<rect key="frame" x="20" y="35" width="335" height="20.5"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bxI-mu-qng">
<rect key="frame" x="20" y="40" width="335" height="90"/>
<string key="text">Secure your encrypted message history with a Recovery Passphrase.
<rect key="frame" x="20" y="85.5" width="335" height="107.5"/>
<string key="text">We'll store an encrypted copy of your keys on our server. Protect your backup with a passphrase to keep it secure.
Youll need it if you log out, or lose access to this device.</string>
For maximum security, this should be different from your account password.</string>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="NqM-Go-gVF">
<rect key="frame" x="0.0" y="170" width="375" height="293"/>
<rect key="frame" x="0.0" y="233" width="375" height="293"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="bottom" translatesAutoresizingMaskIntoConstraints="NO" id="4zf-cV-r09">
<rect key="frame" x="0.0" y="0.0" width="375" height="293"/>
@@ -46,13 +52,13 @@ Youll need it if you log out, or lose access to this device.</string>
<rect key="frame" x="0.0" y="0.0" width="375" height="78.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="enter" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="w95-PK-mJ8">
<rect key="frame" x="20" y="10" width="55.5" height="58.5"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<rect key="frame" x="20" y="10" width="57.5" height="58.5"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="16"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Enter passphrase" textAlignment="natural" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="WeI-qi-2Hw">
<rect key="frame" x="95.5" y="14.5" width="225.5" height="50"/>
<rect key="frame" x="97.5" y="14.5" width="223.5" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="85g-2l-RZB"/>
</constraints>
@@ -103,7 +109,7 @@ Youll need it if you log out, or lose access to this device.</string>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Try adding a word" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GW1-yJ-6Io">
<rect key="frame" x="20" y="25" width="335" height="27.5"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="1" green="0.14913141730000001" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
@@ -140,13 +146,13 @@ Youll need it if you log out, or lose access to this device.</string>
<rect key="frame" x="0.0" y="147" width="375" height="78.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="confirm" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bIh-bf-CD3">
<rect key="frame" x="20" y="10" width="55.5" height="58.5"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<rect key="frame" x="20" y="10" width="57.5" height="58.5"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="16"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Confirm passphrase" textAlignment="natural" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="tN0-Fi-84k">
<rect key="frame" x="95.5" y="14.5" width="259.5" height="50"/>
<rect key="frame" x="97.5" y="14.5" width="257.5" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="8qv-7N-hum"/>
</constraints>
@@ -176,7 +182,7 @@ Youll need it if you log out, or lose access to this device.</string>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Passphrase doesnt match" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QLJ-x6-fEO">
<rect key="frame" x="20" y="0.0" width="335" height="52.5"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="1" green="0.14913141730000001" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
@@ -208,15 +214,15 @@ Youll need it if you log out, or lose access to this device.</string>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="oxZ-I4-CTh">
<rect key="frame" x="0.0" y="493" width="375" height="50"/>
<rect key="frame" x="0.0" y="556" width="375" height="50"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="xXL-d6-V7f">
<rect key="frame" x="0.0" y="0.0" width="375" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="6k5-t4-uPs"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<state key="normal" title="Set Recovery Passphrase ">
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="16"/>
<state key="normal" title="Set Passphrase ">
<color key="titleColor" red="0.47843137254901957" green="0.78823529411764703" blue="0.63137254901960782" alpha="1" colorSpace="calibratedRGB"/>
</state>
<state key="disabled">
@@ -235,20 +241,51 @@ Youll need it if you log out, or lose access to this device.</string>
<constraint firstItem="xXL-d6-V7f" firstAttribute="leading" secondItem="oxZ-I4-CTh" secondAttribute="leading" id="gjp-yd-bno"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Or, secure your backup with a Recovery Key, saving it somewhere safe." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="RPW-VQ-iHw">
<rect key="frame" x="20" y="651" width="335" height="36"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="tBD-dv-RTe">
<rect key="frame" x="0.0" y="697" width="375" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="88Y-vG-lXl"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="16"/>
<state key="normal" title="(Advanced) Set up with Recovery Key">
<color key="titleColor" red="0.47843137250000001" green="0.78823529410000004" blue="0.63137254899999995" alpha="1" colorSpace="calibratedRGB"/>
</state>
<state key="disabled">
<color key="titleColor" red="0.47843137250000001" green="0.78823529410000004" blue="0.63137254899999995" alpha="0.5" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="setUpRecoveryKeyButtonAction:" destination="V8j-Lb-PgC" eventType="touchUpInside" id="hOI-Mh-fmJ"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="bxI-mu-qng" firstAttribute="leading" secondItem="voD-3Q-ryt" secondAttribute="leading" constant="20" id="3fO-gc-E1G"/>
<constraint firstItem="NqM-Go-gVF" firstAttribute="top" secondItem="bxI-mu-qng" secondAttribute="bottom" constant="40" id="BaV-Yg-8AU"/>
<constraint firstItem="bxI-mu-qng" firstAttribute="leading" secondItem="6PP-oV-wYT" secondAttribute="leading" id="0E7-ep-uJk"/>
<constraint firstItem="NqM-Go-gVF" firstAttribute="leading" secondItem="voD-3Q-ryt" secondAttribute="leading" id="JRa-bh-kd2"/>
<constraint firstAttribute="trailing" secondItem="bxI-mu-qng" secondAttribute="trailing" constant="20" id="Q2g-xU-EQR"/>
<constraint firstAttribute="trailing" secondItem="RPW-VQ-iHw" secondAttribute="trailing" constant="20" id="KaG-mr-iY7"/>
<constraint firstAttribute="trailing" secondItem="6PP-oV-wYT" secondAttribute="trailing" constant="20" id="N6N-Sg-9sA"/>
<constraint firstItem="6PP-oV-wYT" firstAttribute="leading" secondItem="voD-3Q-ryt" secondAttribute="leading" constant="20" id="OXh-Vu-86Y"/>
<constraint firstItem="RPW-VQ-iHw" firstAttribute="leading" secondItem="voD-3Q-ryt" secondAttribute="leading" constant="20" id="SPQ-pm-PbG"/>
<constraint firstItem="bxI-mu-qng" firstAttribute="top" secondItem="6PP-oV-wYT" secondAttribute="bottom" constant="30" id="ZmH-Mw-Qhd"/>
<constraint firstAttribute="trailing" secondItem="NqM-Go-gVF" secondAttribute="trailing" id="bxm-bA-yg6"/>
<constraint firstItem="NqM-Go-gVF" firstAttribute="top" secondItem="bxI-mu-qng" secondAttribute="bottom" constant="40" id="dOo-KV-Auw"/>
<constraint firstItem="oxZ-I4-CTh" firstAttribute="top" secondItem="NqM-Go-gVF" secondAttribute="bottom" constant="30" id="fop-Qu-P8P"/>
<constraint firstAttribute="width" priority="750" constant="500" id="glD-Sz-73O"/>
<constraint firstAttribute="bottom" secondItem="oxZ-I4-CTh" secondAttribute="bottom" constant="20" id="nmb-rx-bht"/>
<constraint firstItem="bxI-mu-qng" firstAttribute="top" secondItem="voD-3Q-ryt" secondAttribute="top" constant="40" id="qgy-FA-ETV"/>
<constraint firstItem="bxI-mu-qng" firstAttribute="trailing" secondItem="6PP-oV-wYT" secondAttribute="trailing" id="hjH-Uq-DVb"/>
<constraint firstAttribute="trailing" secondItem="tBD-dv-RTe" secondAttribute="trailing" id="i2a-JN-n6v"/>
<constraint firstAttribute="bottom" secondItem="tBD-dv-RTe" secondAttribute="bottom" constant="20" id="jMH-bs-aTm"/>
<constraint firstItem="tBD-dv-RTe" firstAttribute="leading" secondItem="voD-3Q-ryt" secondAttribute="leading" id="nGD-dO-qck"/>
<constraint firstItem="RPW-VQ-iHw" firstAttribute="top" secondItem="oxZ-I4-CTh" secondAttribute="bottom" constant="45" id="nvn-IQ-KeM"/>
<constraint firstItem="tBD-dv-RTe" firstAttribute="top" secondItem="RPW-VQ-iHw" secondAttribute="bottom" constant="10" id="sgO-62-7xP"/>
<constraint firstAttribute="trailing" secondItem="oxZ-I4-CTh" secondAttribute="trailing" id="tQa-RS-aVB"/>
<constraint firstItem="oxZ-I4-CTh" firstAttribute="leading" secondItem="voD-3Q-ryt" secondAttribute="leading" id="weK-ZJ-30E"/>
<constraint firstItem="6PP-oV-wYT" firstAttribute="top" secondItem="voD-3Q-ryt" secondAttribute="top" constant="35" id="woi-hT-03k"/>
</constraints>
</view>
</subviews>
@@ -296,6 +333,9 @@ Youll need it if you log out, or lose access to this device.</string>
<outlet property="scrollView" destination="9U2-KL-ZVA" id="ojG-2y-X7b"/>
<outlet property="setPassphraseButton" destination="xXL-d6-V7f" id="k8E-Ul-m9g"/>
<outlet property="setPassphraseButtonBackgroundView" destination="oxZ-I4-CTh" id="8If-if-aMp"/>
<outlet property="setUpRecoveryKeyButton" destination="tBD-dv-RTe" id="uDY-Ea-NP2"/>
<outlet property="setUpRecoveryKeyInfoLabel" destination="RPW-VQ-iHw" id="mll-pV-8Gx"/>
<outlet property="titleLabel" destination="6PP-oV-wYT" id="g6C-7m-C2R"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="zK0-v6-7Wt" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -29,6 +29,8 @@ final class KeyBackupSetupPassphraseViewController: UIViewController {
// MARK: Outlets
@IBOutlet private weak var scrollView: UIScrollView!
@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var informationLabel: UILabel!
@IBOutlet private weak var formBackgroundView: UIView!
@@ -51,6 +53,9 @@ final class KeyBackupSetupPassphraseViewController: UIViewController {
@IBOutlet private weak var setPassphraseButtonBackgroundView: UIView!
@IBOutlet private weak var setPassphraseButton: UIButton!
@IBOutlet private weak var setUpRecoveryKeyInfoLabel: UILabel!
@IBOutlet private weak var setUpRecoveryKeyButton: UIButton!
// MARK: Private
private var isFirstViewAppearing: Bool = true
@@ -138,6 +143,7 @@ final class KeyBackupSetupPassphraseViewController: UIViewController {
theme.applyStyle(onNavigationBar: navigationBar)
}
self.titleLabel.textColor = theme.textPrimaryColor
self.informationLabel.textColor = theme.textPrimaryColor
self.formBackgroundView.backgroundColor = theme.backgroundColor
@@ -157,6 +163,9 @@ final class KeyBackupSetupPassphraseViewController: UIViewController {
self.setPassphraseButton.backgroundColor = theme.backgroundColor
theme.applyStyle(onButton: self.setPassphraseButton)
self.setUpRecoveryKeyInfoLabel.textColor = theme.textPrimaryColor
theme.applyStyle(onButton: self.setUpRecoveryKeyButton)
}
private func registerThemeServiceDidChangeThemeNotification() {
@@ -168,14 +177,15 @@ final class KeyBackupSetupPassphraseViewController: UIViewController {
}
private func setupViews() {
let skipBarButtonItem = MXKBarButtonItem(title: VectorL10n.keyBackupSetupSkipAction, style: .plain) { [weak self] in
self?.skipButtonAction()
let cancelBarButtonItem = MXKBarButtonItem(title: VectorL10n.cancel, style: .plain) { [weak self] in
self?.cancelButtonAction()
}
self.navigationItem.rightBarButtonItem = skipBarButtonItem
self.navigationItem.rightBarButtonItem = cancelBarButtonItem
self.scrollView.keyboardDismissMode = .interactive
self.titleLabel.text = VectorL10n.keyBackupSetupPassphraseTitle
self.informationLabel.text = VectorL10n.keyBackupSetupPassphraseInfo
self.passphraseTitleLabel.text = VectorL10n.keyBackupSetupPassphrasePassphraseTitle
@@ -360,7 +370,11 @@ final class KeyBackupSetupPassphraseViewController: UIViewController {
self.viewModel.process(viewAction: .setupPassphrase)
}
private func skipButtonAction() {
@IBAction private func setUpRecoveryKeyButtonAction(_ sender: Any) {
self.viewModel.process(viewAction: .setupRecoveryKey)
}
private func cancelButtonAction() {
self.viewModel.process(viewAction: .skip)
}
}
@@ -26,6 +26,7 @@ final class KeyBackupSetupPassphraseViewModel: KeyBackupSetupPassphraseViewModel
private let passwordStrengthManager: PasswordStrengthManager
private let keyBackup: MXKeyBackup
private let coordinatorDelegateQueue: OperationQueue
private var createKeyBackupOperation: MXHTTPOperation?
// MARK: Public
@@ -63,12 +64,18 @@ final class KeyBackupSetupPassphraseViewModel: KeyBackupSetupPassphraseViewModel
self.coordinatorDelegateQueue = OperationQueue.vc_createSerialOperationQueue(name: "\(type(of: self)).coordinatorDelegateQueue")
}
deinit {
self.createKeyBackupOperation?.cancel()
}
// MARK: - Public
func process(viewAction: KeyBackupSetupPassphraseViewAction) {
switch viewAction {
case .setupPassphrase:
self.setupPassphrase()
case .setupRecoveryKey:
self.setupRecoveryKey()
case .skip:
self.coordinatorDelegateQueue.vc_pause()
self.viewDelegate?.keyBackupSetupPassphraseViewModelShowSkipAlert(self)
@@ -82,30 +89,58 @@ final class KeyBackupSetupPassphraseViewModel: KeyBackupSetupPassphraseViewModel
// MARK: - Private
func setupPassphrase() {
private func setupPassphrase() {
guard let passphrase = self.passphrase else {
return
}
self.viewDelegate?.keyBackupSetupPassphraseViewModel(self, didUpdateViewState: .loading)
self.update(viewState: .loading)
self.keyBackup.prepareKeyBackupVersion(withPassword: passphrase, success: { [weak self] (megolmBackupCreationInfo) in
guard let sself = self else {
return
}
sself.viewDelegate?.keyBackupSetupPassphraseViewModel(sself, didUpdateViewState: .loaded)
sself.coordinatorDelegateQueue.addOperation {
DispatchQueue.main.async {
sself.coordinatorDelegate?.keyBackupSetupPassphraseViewModel(sself, didCompleteWithMegolmBackupCreationInfo: megolmBackupCreationInfo)
sself.createKeyBackupOperation = sself.keyBackup.createKeyBackupVersion(megolmBackupCreationInfo, success: { (_) in
sself.update(viewState: .loaded)
sself.coordinatorDelegateQueue.addOperation {
DispatchQueue.main.async {
sself.coordinatorDelegate?.keyBackupSetupPassphraseViewModel(sself, didCreateBackupFromPassphraseWithResultingRecoveryKey: megolmBackupCreationInfo.recoveryKey)
}
}
}
}, failure: { (error) in
self?.update(viewState: .error(error))
})
}, failure: { [weak self] error in
self?.update(viewState: .error(error))
})
}
private func setupRecoveryKey() {
self.update(viewState: .loading)
self.keyBackup.prepareKeyBackupVersion(withPassword: nil, success: { [weak self] (megolmBackupCreationInfo) in
guard let sself = self else {
return
}
sself.viewDelegate?.keyBackupSetupPassphraseViewModel(sself, didUpdateViewState: .error(error))
}
sself.createKeyBackupOperation = sself.keyBackup.createKeyBackupVersion(megolmBackupCreationInfo, success: { (_) in
sself.update(viewState: .loaded)
sself.coordinatorDelegateQueue.addOperation {
DispatchQueue.main.async {
sself.coordinatorDelegate?.keyBackupSetupPassphraseViewModel(sself, didCreateBackupFromRecoveryKey: megolmBackupCreationInfo.recoveryKey)
}
}
}, failure: { (error) in
self?.update(viewState: .error(error))
})
}, failure: { [weak self] error in
self?.update(viewState: .error(error))
})
}
@@ -119,4 +154,8 @@ final class KeyBackupSetupPassphraseViewModel: KeyBackupSetupPassphraseViewModel
}
return self.passwordStrengthManager.passwordStrength(for: password)
}
private func update(viewState: KeyBackupSetupPassphraseViewState) {
self.viewDelegate?.keyBackupSetupPassphraseViewModel(self, didUpdateViewState: viewState)
}
}
@@ -22,7 +22,8 @@ protocol KeyBackupSetupPassphraseViewModelViewDelegate: class {
}
protocol KeyBackupSetupPassphraseViewModelCoordinatorDelegate: class {
func keyBackupSetupPassphraseViewModel(_ viewModel: KeyBackupSetupPassphraseViewModelType, didCompleteWithMegolmBackupCreationInfo megolmBackupCreationInfo: MXMegolmBackupCreationInfo)
func keyBackupSetupPassphraseViewModel(_ viewModel: KeyBackupSetupPassphraseViewModelType, didCreateBackupFromPassphraseWithResultingRecoveryKey recoveryKey: String)
func keyBackupSetupPassphraseViewModel(_ viewModel: KeyBackupSetupPassphraseViewModelType, didCreateBackupFromRecoveryKey recoveryKey: String)
func keyBackupSetupPassphraseViewModelDidCancel(_ viewModel: KeyBackupSetupPassphraseViewModelType)
}
@@ -19,6 +19,16 @@ import Reusable
final class PasswordStrengthView: UIView, NibOwnerLoadable {
// MARK: - Constants
private enum StrengthColors {
static let gray = UIColor(rgb: 0x9E9E9E)
static let red = UIColor(rgb: 0xF56679)
static let orange = UIColor(rgb: 0xFFC666)
static let yellow = UIColor(rgb: 0xF8E71C)
static let green = UIColor(rgb: 0x7AC9A1)
}
// MARK: - Properties
// MARK: Outlets
@@ -32,15 +42,6 @@ final class PasswordStrengthView: UIView, NibOwnerLoadable {
private var strengthViews: [UIView] = []
private let strengthViewDefaultColor = UIColor(rgb: 0x9E9E9E)
private var strengthViewColors: [Int: UIColor] = [
0: UIColor(rgb: 0xF56679),
1: UIColor(rgb: 0xFFC666),
2: UIColor(rgb: 0xF8E71C),
3: UIColor(rgb: 0x7AC9A1)
]
// MARK: Public
var strength: PasswordStrength = .tooGuessable {
@@ -88,44 +89,42 @@ final class PasswordStrengthView: UIView, NibOwnerLoadable {
private func updateStrengthColors() {
let strengthViewIndex: Int
let color: UIColor
switch self.strength {
case .tooGuessable, .veryGuessable:
strengthViewIndex = 0
color = StrengthColors.red
case .somewhatGuessable:
strengthViewIndex = 1
color = StrengthColors.orange
case .safelyUnguessable:
strengthViewIndex = 2
color = StrengthColors.yellow
case .veryUnguessable:
strengthViewIndex = 3
color = StrengthColors.green
}
self.color(until: strengthViewIndex)
self.color(until: strengthViewIndex, with: color)
}
private func color(until strengthViewIndex: Int) {
private func color(until strengthViewIndex: Int, with color: UIColor) {
var index: Int = 0
for strenghView in self.strengthViews {
let color: UIColor
let strenghViewBackgroundColor: UIColor
if index <= strengthViewIndex {
color = self.color(for: index)
strenghViewBackgroundColor = color
} else {
color = self.strengthViewDefaultColor
strenghViewBackgroundColor = StrengthColors.gray
}
strenghView.backgroundColor = color
strenghView.backgroundColor = strenghViewBackgroundColor
index+=1
}
}
private func color(for index: Int) -> UIColor {
guard let color = self.strengthViewColors[index] else {
return self.strengthViewDefaultColor
}
return color
}
}