summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2023-04-14 16:42:34 +0200
committerAndrej Mihajlov <and@mullvad.net>2023-04-14 16:42:34 +0200
commit8a04ce4108b5385da663d42d5014854e08bbfedd (patch)
treed27a173e79096197f1331297be28ea1e1be01db7
parent9ed9e881a1e16f4ec4b3783970e84a0023a6dbbc (diff)
parente27564dd551e50d1605d1ecb899e16385d915f41 (diff)
downloadmullvadvpn-8a04ce4108b5385da663d42d5014854e08bbfedd.tar.xz
mullvadvpn-8a04ce4108b5385da663d42d5014854e08bbfedd.zip
Merge branch 'add-device-name-and-time-left-labels-to-ios-96'
-rw-r--r--ios/MullvadVPN/Containers/Root/HeaderBarView.swift65
-rw-r--r--ios/MullvadVPN/Containers/Root/RootContainerViewController.swift6
-rw-r--r--ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift14
3 files changed, 78 insertions, 7 deletions
diff --git a/ios/MullvadVPN/Containers/Root/HeaderBarView.swift b/ios/MullvadVPN/Containers/Root/HeaderBarView.swift
index 467bdb37da..0c309e6947 100644
--- a/ios/MullvadVPN/Containers/Root/HeaderBarView.swift
+++ b/ios/MullvadVPN/Containers/Root/HeaderBarView.swift
@@ -26,6 +26,28 @@ class HeaderBarView: UIView {
return imageView
}()
+ private let deviceInfoHolder: UIStackView = {
+ let stackView = UIStackView()
+ stackView.axis = .horizontal
+ stackView.distribution = .fillProportionally
+ stackView.translatesAutoresizingMaskIntoConstraints = false
+ return stackView
+ }()
+
+ private lazy var deviceName: UILabel = {
+ let label = UILabel(frame: .zero)
+ label.font = UIFont.systemFont(ofSize: 14)
+ label.textColor = UIColor(white: 1.0, alpha: 0.8)
+ return label
+ }()
+
+ private lazy var timeLeft: UILabel = {
+ let label = UILabel(frame: .zero)
+ label.font = UIFont.systemFont(ofSize: 14)
+ label.textColor = UIColor(white: 1.0, alpha: 0.8)
+ return label
+ }()
+
let settingsButton = makeSettingsButton()
class func makeSettingsButton() -> HeaderBarButton {
@@ -105,8 +127,8 @@ class HeaderBarView: UIView {
),
brandNameImageView.heightAnchor.constraint(equalToConstant: 18),
layoutMarginsGuide.bottomAnchor.constraint(
- equalTo: brandNameImageView.bottomAnchor,
- constant: 22
+ equalTo: deviceInfoHolder.bottomAnchor,
+ constant: 4
),
settingsButton.leadingAnchor.constraint(
@@ -115,9 +137,14 @@ class HeaderBarView: UIView {
),
settingsButton.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor),
settingsButton.centerYAnchor.constraint(equalTo: brandNameImageView.centerYAnchor),
+
+ deviceInfoHolder.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor),
+ deviceInfoHolder.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor),
+ deviceInfoHolder.topAnchor.constraint(equalTo: logoImageView.bottomAnchor, constant: 7),
]
- [logoImageView, brandNameImageView, settingsButton].forEach { addSubview($0) }
+ [logoImageView, brandNameImageView, settingsButton, deviceInfoHolder].forEach { addSubview($0) }
+ [deviceName, timeLeft].forEach { deviceInfoHolder.addArrangedSubview($0) }
NSLayoutConstraint.activate(constraints)
}
@@ -132,3 +159,35 @@ class HeaderBarView: UIView {
borderLayer.frame = CGRect(x: 0, y: frame.maxY - 1, width: frame.width, height: 1)
}
}
+
+extension HeaderBarView {
+ func update(deviceState: DeviceState) {
+ switch deviceState {
+ case let .loggedIn(storedAccountData, storedDeviceData):
+ let formattedDeviceName = NSLocalizedString(
+ "DEVICE_NAME_HEADER_VIEW",
+ tableName: "Account",
+ value: "Device name : %@",
+ comment: ""
+ )
+ let formattedTimeLeft = NSLocalizedString(
+ "TIME_LEFT_HEADER_VIEW",
+ tableName: "Account",
+ value: "Time left : %@",
+ comment: ""
+ )
+ deviceName.text = .init(format: formattedDeviceName, storedDeviceData.name)
+ timeLeft.text = .init(
+ format: formattedTimeLeft,
+ CustomDateComponentsFormatting.localizedString(
+ from: Date(),
+ to: storedAccountData.expiry,
+ unitsStyle: .full
+ ) ?? ""
+ )
+ deviceInfoHolder.arrangedSubviews.forEach { $0.isHidden = false }
+ case .loggedOut, .revoked:
+ deviceInfoHolder.arrangedSubviews.forEach { $0.isHidden = true }
+ }
+ }
+}
diff --git a/ios/MullvadVPN/Containers/Root/RootContainerViewController.swift b/ios/MullvadVPN/Containers/Root/RootContainerViewController.swift
index 65ebaffd47..3b96728d12 100644
--- a/ios/MullvadVPN/Containers/Root/RootContainerViewController.swift
+++ b/ios/MullvadVPN/Containers/Root/RootContainerViewController.swift
@@ -674,3 +674,9 @@ extension UIViewController {
rootContainerController?.updateHeaderBarHiddenAppearance()
}
}
+
+extension RootContainerViewController {
+ func update(deviceState: DeviceState) {
+ headerBarView.update(deviceState: deviceState)
+ }
+}
diff --git a/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift b/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift
index 4a745e385c..710b0e2cdc 100644
--- a/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift
+++ b/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift
@@ -92,9 +92,9 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
self.devicesProxy = devicesProxy
/*
- Uncomment if you'd like to test TOS again
+ Uncomment if you'd like to test TOS again
TermsOfService.unsetAgreed()
- */
+ */
super.init()
@@ -417,7 +417,6 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
private func presentMain(animated: Bool, completion: @escaping (Coordinator) -> Void) {
precondition(!isPad)
-
let tunnelCoordinator = makeTunnelCoordinator()
horizontalFlowController.pushViewController(
@@ -587,12 +586,15 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
let tunnelObserver =
TunnelBlockObserver(didUpdateDeviceState: { [weak self] manager, deviceState in
self?.deviceStateDidChange(deviceState)
+ self?.updateView(deviceState: deviceState)
})
tunnelManager.addObserver(tunnelObserver)
self.tunnelObserver = tunnelObserver
+ updateView(deviceState: tunnelManager.deviceState)
+
splitViewController.preferredDisplayMode = tunnelManager.deviceState.splitViewMode
}
@@ -616,6 +618,11 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
}
}
+ private func updateView(deviceState: DeviceState) {
+ primaryNavigationContainer.update(deviceState: deviceState)
+ secondaryNavigationContainer.update(deviceState: deviceState)
+ }
+
// MARK: - Out of time
private func updateOutOfTimeTimer() {
@@ -723,7 +730,6 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
case .pendingReconnect:
break
}
-
return true
}