mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-24 02:22:44 +02:00
Secrets setup: Handle set up recovery key screen.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh SecretsSetupRecoveryKey SecretsSetupRecoveryKey
|
||||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
final class SecretsSetupRecoveryKeyCoordinator: SecretsSetupRecoveryKeyCoordinatorType {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private var secretsSetupRecoveryKeyViewModel: SecretsSetupRecoveryKeyViewModelType
|
||||
private let secretsSetupRecoveryKeyViewController: SecretsSetupRecoveryKeyViewController
|
||||
|
||||
// MARK: Public
|
||||
|
||||
// Must be used only internally
|
||||
var childCoordinators: [Coordinator] = []
|
||||
|
||||
weak var delegate: SecretsSetupRecoveryKeyCoordinatorDelegate?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(recoveryService: MXRecoveryService, passphrase: String?) {
|
||||
let secretsSetupRecoveryKeyViewModel = SecretsSetupRecoveryKeyViewModel(recoveryService: recoveryService, passphrase: passphrase)
|
||||
let secretsSetupRecoveryKeyViewController = SecretsSetupRecoveryKeyViewController.instantiate(with: secretsSetupRecoveryKeyViewModel)
|
||||
self.secretsSetupRecoveryKeyViewModel = secretsSetupRecoveryKeyViewModel
|
||||
self.secretsSetupRecoveryKeyViewController = secretsSetupRecoveryKeyViewController
|
||||
}
|
||||
|
||||
// MARK: - Public methods
|
||||
|
||||
func start() {
|
||||
self.secretsSetupRecoveryKeyViewModel.coordinatorDelegate = self
|
||||
}
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
return self.secretsSetupRecoveryKeyViewController
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - SecretsSetupRecoveryKeyViewModelCoordinatorDelegate
|
||||
extension SecretsSetupRecoveryKeyCoordinator: SecretsSetupRecoveryKeyViewModelCoordinatorDelegate {
|
||||
|
||||
func secretsSetupRecoveryKeyViewModelDidComplete(_ viewModel: SecretsSetupRecoveryKeyViewModelType) {
|
||||
self.delegate?.secretsSetupRecoveryKeyCoordinatorDidComplete(self)
|
||||
}
|
||||
|
||||
func secretsSetupRecoveryKeyViewModelDidFailed(_ viewModel: SecretsSetupRecoveryKeyViewModelType) {
|
||||
self.delegate?.secretsSetupRecoveryKeyCoordinatorDidFailed(self)
|
||||
}
|
||||
|
||||
func secretsSetupRecoveryKeyViewModelDidCancel(_ viewModel: SecretsSetupRecoveryKeyViewModelType) {
|
||||
self.delegate?.secretsSetupRecoveryKeyCoordinatorDidCancel(self)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh SecretsSetupRecoveryKey SecretsSetupRecoveryKey
|
||||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol SecretsSetupRecoveryKeyCoordinatorDelegate: class {
|
||||
func secretsSetupRecoveryKeyCoordinatorDidComplete(_ coordinator: SecretsSetupRecoveryKeyCoordinatorType)
|
||||
func secretsSetupRecoveryKeyCoordinatorDidFailed(_ coordinator: SecretsSetupRecoveryKeyCoordinatorType)
|
||||
func secretsSetupRecoveryKeyCoordinatorDidCancel(_ coordinator: SecretsSetupRecoveryKeyCoordinatorType)
|
||||
}
|
||||
|
||||
/// `SecretsSetupRecoveryKeyCoordinatorType` is a protocol describing a Coordinator that handle key backup setup passphrase navigation flow.
|
||||
protocol SecretsSetupRecoveryKeyCoordinatorType: Coordinator, Presentable {
|
||||
var delegate: SecretsSetupRecoveryKeyCoordinatorDelegate? { get }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh SecretsSetupRecoveryKey SecretsSetupRecoveryKey
|
||||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
/// SecretsSetupRecoveryKeyViewController view actions exposed to view model
|
||||
enum SecretsSetupRecoveryKeyViewAction {
|
||||
case loadData
|
||||
case done
|
||||
case errorAlertOk
|
||||
case cancel
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
<?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="EoE-Pl-I63">
|
||||
<device id="retina6_1" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Secrets Setup Recovery Key View Controller-->
|
||||
<scene sceneID="x3I-nC-qtU">
|
||||
<objects>
|
||||
<viewController extendedLayoutIncludesOpaqueBars="YES" automaticallyAdjustsScrollViewInsets="NO" id="EoE-Pl-I63" customClass="SecretsSetupRecoveryKeyViewController" customModule="Riot" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="EZ7-Nb-xmk">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ahz-9d-sce">
|
||||
<rect key="frame" x="0.0" y="44" width="414" height="852"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Rs5-uo-2W5">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="382"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="K9F-ti-0rB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="382"/>
|
||||
<subviews>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="secrets_setup_key" translatesAutoresizingMaskIntoConstraints="NO" id="JwH-yj-Gj8">
|
||||
<rect key="frame" x="183" y="35" width="48" height="48"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" secondItem="JwH-yj-Gj8" secondAttribute="height" multiplier="1:1" id="DTn-tC-iTc"/>
|
||||
<constraint firstAttribute="width" constant="48" id="uXl-gX-etQ"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Store your Recovery Key somewhere safe. It can be used to unlock your encrypted messages & data." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="csL-ru-oas">
|
||||
<rect key="frame" x="20" y="113" width="374" height="36"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="15"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Loading…" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aDh-9M-4UN">
|
||||
<rect key="frame" x="20" y="184" width="374" height="18"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="15"/>
|
||||
<color key="textColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="zgt-AN-9EH">
|
||||
<rect key="frame" x="0.0" y="242" width="414" height="120"/>
|
||||
<subviews>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cju-9A-6Ns" customClass="RoundedButton" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="20" y="0.0" width="374" height="50"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="50" id="ywR-tU-0tp"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="16"/>
|
||||
<inset key="contentEdgeInsets" minX="20" minY="0.0" maxX="20" maxY="0.0"/>
|
||||
<state key="normal" title="Export">
|
||||
<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="exportButtonAction:" destination="EoE-Pl-I63" eventType="touchUpInside" id="8Sv-N4-mhU"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="v3h-dA-xvr" userLabel="Continue" customClass="RoundedButton" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="20" y="70" width="374" height="50"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="50" id="efg-jS-vMe"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="16"/>
|
||||
<inset key="contentEdgeInsets" minX="20" minY="0.0" maxX="20" maxY="0.0"/>
|
||||
<state key="normal" title="Export">
|
||||
<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="doneButtonAction:" destination="EoE-Pl-I63" eventType="touchUpInside" id="NO6-2J-vWo"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstItem="v3h-dA-xvr" firstAttribute="top" secondItem="cju-9A-6Ns" secondAttribute="bottom" constant="20" id="CVl-bR-ZyK"/>
|
||||
<constraint firstAttribute="bottom" secondItem="v3h-dA-xvr" secondAttribute="bottom" id="PPw-gM-JID"/>
|
||||
<constraint firstItem="v3h-dA-xvr" firstAttribute="leading" secondItem="cju-9A-6Ns" secondAttribute="leading" id="THe-E7-SvT"/>
|
||||
<constraint firstItem="v3h-dA-xvr" firstAttribute="trailing" secondItem="cju-9A-6Ns" secondAttribute="trailing" id="W5O-7M-cF3"/>
|
||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="cju-9A-6Ns" secondAttribute="trailing" constant="20" id="X0c-Z0-KGn"/>
|
||||
<constraint firstItem="cju-9A-6Ns" firstAttribute="top" secondItem="zgt-AN-9EH" secondAttribute="top" id="dPj-uh-WWa"/>
|
||||
<constraint firstItem="cju-9A-6Ns" firstAttribute="centerX" secondItem="zgt-AN-9EH" secondAttribute="centerX" id="iuh-Zf-BZM"/>
|
||||
<constraint firstItem="cju-9A-6Ns" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="zgt-AN-9EH" secondAttribute="leading" constant="20" id="iyq-Bv-kvf"/>
|
||||
<constraint firstItem="cju-9A-6Ns" firstAttribute="width" secondItem="zgt-AN-9EH" secondAttribute="width" priority="750" id="t3e-c6-wSf"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="csL-ru-oas" secondAttribute="trailing" constant="20" id="4ZO-ii-ENI"/>
|
||||
<constraint firstAttribute="width" priority="750" constant="500" id="G40-eF-Vmb"/>
|
||||
<constraint firstItem="csL-ru-oas" firstAttribute="leading" secondItem="K9F-ti-0rB" secondAttribute="leading" constant="20" id="GaH-AP-bZ1"/>
|
||||
<constraint firstItem="aDh-9M-4UN" firstAttribute="leading" secondItem="csL-ru-oas" secondAttribute="leading" id="J0Y-Fl-1Lm"/>
|
||||
<constraint firstAttribute="bottom" secondItem="zgt-AN-9EH" secondAttribute="bottom" constant="20" id="NNI-yY-2gw"/>
|
||||
<constraint firstItem="aDh-9M-4UN" firstAttribute="trailing" secondItem="csL-ru-oas" secondAttribute="trailing" id="QAS-cx-4zF"/>
|
||||
<constraint firstItem="zgt-AN-9EH" firstAttribute="top" secondItem="aDh-9M-4UN" secondAttribute="bottom" constant="40" id="WQw-uJ-5v6"/>
|
||||
<constraint firstItem="zgt-AN-9EH" firstAttribute="leading" secondItem="K9F-ti-0rB" secondAttribute="leading" id="dKH-aq-rWl"/>
|
||||
<constraint firstAttribute="trailing" secondItem="zgt-AN-9EH" secondAttribute="trailing" id="dRS-cB-t6V"/>
|
||||
<constraint firstItem="aDh-9M-4UN" firstAttribute="top" secondItem="csL-ru-oas" secondAttribute="bottom" constant="35" id="fB9-8Q-Fee"/>
|
||||
<constraint firstItem="csL-ru-oas" firstAttribute="top" secondItem="JwH-yj-Gj8" secondAttribute="bottom" constant="30" id="pKd-Oy-PNV"/>
|
||||
<constraint firstItem="JwH-yj-Gj8" firstAttribute="centerX" secondItem="K9F-ti-0rB" secondAttribute="centerX" id="qYR-oP-1zH"/>
|
||||
<constraint firstItem="JwH-yj-Gj8" firstAttribute="top" secondItem="K9F-ti-0rB" secondAttribute="top" constant="35" id="sae-bb-nrs"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstItem="K9F-ti-0rB" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="Rs5-uo-2W5" secondAttribute="leading" id="4rN-tv-wkb"/>
|
||||
<constraint firstItem="K9F-ti-0rB" firstAttribute="centerX" secondItem="Rs5-uo-2W5" secondAttribute="centerX" id="PIo-oO-BbD"/>
|
||||
<constraint firstItem="K9F-ti-0rB" firstAttribute="top" secondItem="Rs5-uo-2W5" secondAttribute="top" id="nB3-uX-q4J"/>
|
||||
<constraint firstAttribute="bottom" secondItem="K9F-ti-0rB" secondAttribute="bottom" id="t4Y-vr-8c6"/>
|
||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="K9F-ti-0rB" secondAttribute="trailing" id="txe-zb-TiV"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottom" secondItem="Rs5-uo-2W5" secondAttribute="bottom" id="Fai-XD-wYZ"/>
|
||||
<constraint firstItem="Rs5-uo-2W5" firstAttribute="leading" secondItem="Ahz-9d-sce" secondAttribute="leading" id="Fv4-4B-T6y"/>
|
||||
<constraint firstAttribute="trailing" secondItem="Rs5-uo-2W5" secondAttribute="trailing" id="lUM-5U-R9B"/>
|
||||
<constraint firstItem="Rs5-uo-2W5" firstAttribute="top" secondItem="Ahz-9d-sce" secondAttribute="top" id="s95-pV-QYC"/>
|
||||
<constraint firstItem="Rs5-uo-2W5" firstAttribute="width" secondItem="Ahz-9d-sce" secondAttribute="width" id="whx-pE-t67"/>
|
||||
</constraints>
|
||||
</scrollView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="0.94509803920000002" green="0.96078431369999995" blue="0.97254901959999995" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<constraints>
|
||||
<constraint firstItem="R4q-cd-DVX" firstAttribute="top" secondItem="Ahz-9d-sce" secondAttribute="top" id="233-gk-CKV"/>
|
||||
<constraint firstItem="R4q-cd-DVX" firstAttribute="trailing" secondItem="Ahz-9d-sce" secondAttribute="trailing" id="Rc0-Sf-qtU"/>
|
||||
<constraint firstAttribute="bottom" secondItem="Ahz-9d-sce" secondAttribute="bottom" id="V3e-5C-fSc"/>
|
||||
<constraint firstItem="Ahz-9d-sce" firstAttribute="leading" secondItem="R4q-cd-DVX" secondAttribute="leading" id="kow-MO-5hW"/>
|
||||
</constraints>
|
||||
<viewLayoutGuide key="safeArea" id="R4q-cd-DVX"/>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="doneButton" destination="v3h-dA-xvr" id="YEi-d4-sUs"/>
|
||||
<outlet property="exportButton" destination="cju-9A-6Ns" id="TU9-kQ-MbV"/>
|
||||
<outlet property="informationLabel" destination="csL-ru-oas" id="tkl-2J-VDB"/>
|
||||
<outlet property="recoveryKeyLabel" destination="aDh-9M-4UN" id="yai-aZ-7uj"/>
|
||||
<outlet property="secureKeyImageView" destination="JwH-yj-Gj8" id="H1W-pB-CN1"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="ekR-Lh-PNe" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-3772" y="-774"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="secrets_setup_key" width="48" height="48"/>
|
||||
</resources>
|
||||
</document>
|
||||
@@ -0,0 +1,225 @@
|
||||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh SecretsSetupRecoveryKey SecretsSetupRecoveryKey
|
||||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import UIKit
|
||||
|
||||
final class SecretsSetupRecoveryKeyViewController: UIViewController {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Outlets
|
||||
|
||||
@IBOutlet private weak var secureKeyImageView: UIImageView!
|
||||
@IBOutlet private weak var informationLabel: UILabel!
|
||||
@IBOutlet private weak var recoveryKeyLabel: UILabel!
|
||||
@IBOutlet private weak var exportButton: RoundedButton!
|
||||
@IBOutlet private weak var doneButton: RoundedButton!
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private var viewModel: SecretsSetupRecoveryKeyViewModelType!
|
||||
private var theme: Theme!
|
||||
private var errorPresenter: MXKErrorPresentation!
|
||||
private var activityPresenter: ActivityIndicatorPresenter!
|
||||
|
||||
private var recoveryKey: String?
|
||||
private var hasSavedRecoveryKey: Bool = false
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
class func instantiate(with viewModel: SecretsSetupRecoveryKeyViewModelType) -> SecretsSetupRecoveryKeyViewController {
|
||||
let viewController = StoryboardScene.SecretsSetupRecoveryKeyViewController.initialScene.instantiate()
|
||||
viewController.viewModel = viewModel
|
||||
viewController.theme = ThemeService.shared().theme
|
||||
return viewController
|
||||
}
|
||||
|
||||
// MARK: - Life cycle
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
|
||||
self.setupViews()
|
||||
self.activityPresenter = ActivityIndicatorPresenter()
|
||||
self.errorPresenter = MXKErrorAlertPresentation()
|
||||
|
||||
self.registerThemeServiceDidChangeThemeNotification()
|
||||
self.update(theme: self.theme)
|
||||
|
||||
self.viewModel.viewDelegate = self
|
||||
|
||||
self.viewModel.process(viewAction: .loadData)
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
// Hide back button
|
||||
self.navigationItem.setHidesBackButton(true, animated: animated)
|
||||
}
|
||||
|
||||
override var preferredStatusBarStyle: UIStatusBarStyle {
|
||||
return self.theme.statusBarStyle
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func update(theme: Theme) {
|
||||
self.theme = theme
|
||||
|
||||
self.view.backgroundColor = theme.headerBackgroundColor
|
||||
|
||||
if let navigationBar = self.navigationController?.navigationBar {
|
||||
theme.applyStyle(onNavigationBar: navigationBar)
|
||||
}
|
||||
|
||||
self.secureKeyImageView.tintColor = theme.textPrimaryColor
|
||||
self.informationLabel.textColor = theme.textPrimaryColor
|
||||
self.recoveryKeyLabel.textColor = theme.textSecondaryColor
|
||||
|
||||
self.exportButton.update(theme: theme)
|
||||
self.doneButton.update(theme: theme)
|
||||
}
|
||||
|
||||
private func registerThemeServiceDidChangeThemeNotification() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .themeServiceDidChangeTheme, object: nil)
|
||||
}
|
||||
|
||||
@objc private func themeDidChange() {
|
||||
self.update(theme: ThemeService.shared().theme)
|
||||
}
|
||||
|
||||
private func setupViews() {
|
||||
let cancelBarButtonItem = MXKBarButtonItem(title: VectorL10n.cancel, style: .plain) { [weak self] in
|
||||
self?.cancelButtonAction()
|
||||
}
|
||||
|
||||
self.navigationItem.rightBarButtonItem = cancelBarButtonItem
|
||||
|
||||
self.vc_removeBackTitle()
|
||||
|
||||
self.title = VectorL10n.secretsSetupRecoveryKeyTitle
|
||||
|
||||
self.secureKeyImageView.image = Asset.Images.secretsSetupKey.image.withRenderingMode(.alwaysTemplate)
|
||||
self.informationLabel.text = VectorL10n.secretsSetupRecoveryKeyInformation
|
||||
self.recoveryKeyLabel.text = VectorL10n.secretsSetupRecoveryKeyLoading
|
||||
|
||||
self.exportButton.setTitle(VectorL10n.secretsSetupRecoveryKeyExportAction, for: .normal)
|
||||
self.exportButton.isEnabled = false
|
||||
self.doneButton.setTitle(VectorL10n.continue, for: .normal)
|
||||
|
||||
self.updateDoneButton()
|
||||
}
|
||||
|
||||
private func render(viewState: SecretsSetupRecoveryKeyViewState) {
|
||||
switch viewState {
|
||||
case .loading:
|
||||
self.renderLoading()
|
||||
case .loaded(let recoveryKey):
|
||||
self.renderLoaded(recoveryKey: recoveryKey)
|
||||
case .error(let error):
|
||||
self.render(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func renderLoading() {
|
||||
self.activityPresenter.presentActivityIndicator(on: self.view, animated: true)
|
||||
}
|
||||
|
||||
private func renderLoaded(recoveryKey: String) {
|
||||
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
|
||||
self.exportButton.isEnabled = true
|
||||
self.recoveryKey = recoveryKey
|
||||
self.recoveryKeyLabel.text = recoveryKey
|
||||
}
|
||||
|
||||
private func render(error: Error) {
|
||||
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
|
||||
self.errorPresenter.presentError(from: self, forError: error, animated: true) {
|
||||
self.viewModel.process(viewAction: .errorAlertOk)
|
||||
}
|
||||
}
|
||||
|
||||
private func updateDoneButton() {
|
||||
self.doneButton.isEnabled = self.hasSavedRecoveryKey
|
||||
}
|
||||
|
||||
private func presentKeepSafeAlert() {
|
||||
let alertController = UIAlertController(title: VectorL10n.secretsSetupRecoveryKeyStorageAlertTitle,
|
||||
message: VectorL10n.secretsSetupRecoveryKeyStorageAlertMessage,
|
||||
preferredStyle: .alert)
|
||||
|
||||
alertController.addAction(UIAlertAction(title: VectorL10n.continue, style: .cancel, handler: { action in
|
||||
self.viewModel.process(viewAction: .done)
|
||||
}))
|
||||
|
||||
self.present(alertController, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
private func shareRecoveryKey() {
|
||||
guard let recoveryKey = self.recoveryKey else {
|
||||
return
|
||||
}
|
||||
|
||||
// Set up activity view controller
|
||||
let activityItems: [Any] = [ recoveryKey ]
|
||||
let activityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
|
||||
|
||||
activityViewController.completionWithItemsHandler = { (activityType, completed, returnedItems, error) in
|
||||
|
||||
// Enable made copy button only if user has selected an activity item and has setup recovery key without passphrase
|
||||
if completed {
|
||||
self.hasSavedRecoveryKey = true
|
||||
self.updateDoneButton()
|
||||
}
|
||||
}
|
||||
|
||||
// Configure source view when activity view controller is presented with a popover
|
||||
if let popoverPresentationController = activityViewController.popoverPresentationController {
|
||||
popoverPresentationController.sourceView = self.exportButton
|
||||
popoverPresentationController.sourceRect = self.exportButton.bounds
|
||||
popoverPresentationController.permittedArrowDirections = [.down, .up]
|
||||
}
|
||||
|
||||
self.present(activityViewController, animated: true)
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction private func exportButtonAction(_ sender: Any) {
|
||||
self.shareRecoveryKey()
|
||||
}
|
||||
|
||||
@IBAction private func doneButtonAction(_ sender: Any) {
|
||||
self.presentKeepSafeAlert()
|
||||
}
|
||||
|
||||
private func cancelButtonAction() {
|
||||
self.viewModel.process(viewAction: .cancel)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - SecretsSetupRecoveryKeyViewModelViewDelegate
|
||||
extension SecretsSetupRecoveryKeyViewController: SecretsSetupRecoveryKeyViewModelViewDelegate {
|
||||
|
||||
func secretsSetupRecoveryKeyViewModel(_ viewModel: SecretsSetupRecoveryKeyViewModelType, didUpdateViewState viewSate: SecretsSetupRecoveryKeyViewState) {
|
||||
self.render(viewState: viewSate)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh SecretsSetupRecoveryKey SecretsSetupRecoveryKey
|
||||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
final class SecretsSetupRecoveryKeyViewModel: SecretsSetupRecoveryKeyViewModelType {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let recoveryService: MXRecoveryService
|
||||
private let passphrase: String?
|
||||
|
||||
// MARK: Public
|
||||
|
||||
weak var viewDelegate: SecretsSetupRecoveryKeyViewModelViewDelegate?
|
||||
weak var coordinatorDelegate: SecretsSetupRecoveryKeyViewModelCoordinatorDelegate?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(recoveryService: MXRecoveryService, passphrase: String?) {
|
||||
self.recoveryService = recoveryService
|
||||
self.passphrase = passphrase
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func process(viewAction: SecretsSetupRecoveryKeyViewAction) {
|
||||
switch viewAction {
|
||||
case .loadData:
|
||||
self.createSecureKey()
|
||||
case .done:
|
||||
self.coordinatorDelegate?.secretsSetupRecoveryKeyViewModelDidComplete(self)
|
||||
case .errorAlertOk:
|
||||
self.coordinatorDelegate?.secretsSetupRecoveryKeyViewModelDidFailed(self)
|
||||
case .cancel:
|
||||
self.coordinatorDelegate?.secretsSetupRecoveryKeyViewModelDidCancel(self)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func createSecureKey() {
|
||||
self.update(viewState: .loading)
|
||||
|
||||
self.recoveryService.createRecovery(forSecrets: nil, withPassphrase: self.passphrase, success: { secretStorageKeyCreationInfo in
|
||||
self.update(viewState: .loaded(secretStorageKeyCreationInfo.recoveryKey))
|
||||
}, failure: { error in
|
||||
self.update(viewState: .error(error))
|
||||
})
|
||||
}
|
||||
|
||||
private func update(viewState: SecretsSetupRecoveryKeyViewState) {
|
||||
self.viewDelegate?.secretsSetupRecoveryKeyViewModel(self, didUpdateViewState: viewState)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh SecretsSetupRecoveryKey SecretsSetupRecoveryKey
|
||||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol SecretsSetupRecoveryKeyViewModelViewDelegate: class {
|
||||
func secretsSetupRecoveryKeyViewModel(_ viewModel: SecretsSetupRecoveryKeyViewModelType, didUpdateViewState viewSate: SecretsSetupRecoveryKeyViewState)
|
||||
}
|
||||
|
||||
protocol SecretsSetupRecoveryKeyViewModelCoordinatorDelegate: class {
|
||||
func secretsSetupRecoveryKeyViewModelDidComplete(_ viewModel: SecretsSetupRecoveryKeyViewModelType)
|
||||
func secretsSetupRecoveryKeyViewModelDidFailed(_ viewModel: SecretsSetupRecoveryKeyViewModelType)
|
||||
func secretsSetupRecoveryKeyViewModelDidCancel(_ viewModel: SecretsSetupRecoveryKeyViewModelType)
|
||||
}
|
||||
|
||||
/// Protocol describing the view model used by `SecretsSetupRecoveryKeyViewController`
|
||||
protocol SecretsSetupRecoveryKeyViewModelType {
|
||||
|
||||
var viewDelegate: SecretsSetupRecoveryKeyViewModelViewDelegate? { get set }
|
||||
var coordinatorDelegate: SecretsSetupRecoveryKeyViewModelCoordinatorDelegate? { get set }
|
||||
|
||||
func process(viewAction: SecretsSetupRecoveryKeyViewAction)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh SecretsSetupRecoveryKey SecretsSetupRecoveryKey
|
||||
/*
|
||||
Copyright 2020 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
/// SecretsSetupRecoveryKeyViewController view state
|
||||
enum SecretsSetupRecoveryKeyViewState {
|
||||
case loading
|
||||
case loaded(_ recoveryKey: String)
|
||||
case error(Error)
|
||||
}
|
||||
Reference in New Issue
Block a user