summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMojgan <Mojgan.jelodar@codic.se>2023-06-22 15:14:12 +0200
committerAndrej Mihajlov <and@mullvad.net>2023-06-26 16:33:47 +0200
commitc06e1e2c9a66030f5866250fc4326e43561744e1 (patch)
tree872891d6b22bf8d22478c68a206bfd4647ecae34
parent69234591fa28dcfb5b4e589d4ba385883e60fc0c (diff)
downloadmullvadvpn-c06e1e2c9a66030f5866250fc4326e43561744e1.tar.xz
mullvadvpn-c06e1e2c9a66030f5866250fc4326e43561744e1.zip
Hide time left when it's close to expiry or expired
-rw-r--r--ios/MullvadVPN/Containers/Root/HeaderBarView.swift87
-rw-r--r--ios/MullvadVPN/Containers/Root/RootConfiguration.swift1
-rw-r--r--ios/MullvadVPN/Containers/Root/RootContainerViewController.swift7
-rw-r--r--ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift54
4 files changed, 82 insertions, 67 deletions
diff --git a/ios/MullvadVPN/Containers/Root/HeaderBarView.swift b/ios/MullvadVPN/Containers/Root/HeaderBarView.swift
index aab9e39259..f133179658 100644
--- a/ios/MullvadVPN/Containers/Root/HeaderBarView.swift
+++ b/ios/MullvadVPN/Containers/Root/HeaderBarView.swift
@@ -29,7 +29,7 @@ class HeaderBarView: UIView {
return stackView
}()
- private lazy var deviceName: UILabel = {
+ private lazy var deviceNameLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 14)
label.textColor = UIColor(white: 1.0, alpha: 0.8)
@@ -37,7 +37,7 @@ class HeaderBarView: UIView {
return label
}()
- private lazy var timeLeft: UILabel = {
+ private lazy var timeLeftLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 14)
label.textColor = UIColor(white: 1.0, alpha: 0.8)
@@ -106,6 +106,53 @@ class HeaderBarView: UIView {
}
}
+ private var isAccountButtonHidden = false {
+ didSet {
+ accountButton.isHidden = isAccountButtonHidden
+ }
+ }
+
+ private var timeLeft: Date? {
+ didSet {
+ if let timeLeft {
+ timeLeftLabel.isHidden = false
+ let formattedTimeLeft = NSLocalizedString(
+ "TIME_LEFT_HEADER_VIEW",
+ tableName: "Account",
+ value: "Time left: %@",
+ comment: ""
+ )
+ timeLeftLabel.text = String(
+ format: formattedTimeLeft,
+ CustomDateComponentsFormatting.localizedString(
+ from: Date(),
+ to: timeLeft,
+ unitsStyle: .full
+ ) ?? ""
+ )
+ } else {
+ timeLeftLabel.isHidden = true
+ }
+ }
+ }
+
+ private var deviceName: String? {
+ didSet {
+ if let deviceName {
+ deviceNameLabel.isHidden = false
+ let formattedDeviceName = NSLocalizedString(
+ "DEVICE_NAME_HEADER_VIEW",
+ tableName: "Account",
+ value: "Device name: %@",
+ comment: ""
+ )
+ deviceNameLabel.text = String(format: formattedDeviceName, deviceName)
+ } else {
+ deviceNameLabel.isHidden = true
+ }
+ }
+ }
+
override init(frame: CGRect) {
super.init(frame: frame)
directionalLayoutMargins = NSDirectionalEdgeInsets(
@@ -120,7 +167,7 @@ class HeaderBarView: UIView {
let imageSize = brandNameImage?.size ?? .zero
let brandNameAspectRatio = imageSize.width / max(imageSize.height, 1)
- [deviceName, timeLeft].forEach { deviceInfoHolder.addArrangedSubview($0) }
+ [deviceNameLabel, timeLeftLabel].forEach { deviceInfoHolder.addArrangedSubview($0) }
addConstrainedSubviews([logoImageView, brandNameImageView, buttonContainer, deviceInfoHolder]) {
logoImageView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor)
@@ -173,38 +220,10 @@ class HeaderBarView: UIView {
return brandNameRect.intersects(buttonContainerRect)
}
-}
-extension HeaderBarView {
func update(configuration: RootConfiguration) {
- if let name = configuration.deviceName {
- let formattedDeviceName = NSLocalizedString(
- "DEVICE_NAME_HEADER_VIEW",
- tableName: "Account",
- value: "Device name: %@",
- comment: ""
- )
- deviceName.text = .init(format: formattedDeviceName, name)
- }
-
- if let expiry = configuration.expiry {
- let formattedTimeLeft = NSLocalizedString(
- "TIME_LEFT_HEADER_VIEW",
- tableName: "Account",
- value: "Time left: %@",
- comment: ""
- )
- timeLeft.text = .init(
- format: formattedTimeLeft,
- CustomDateComponentsFormatting.localizedString(
- from: Date(),
- to: expiry,
- unitsStyle: .full
- ) ?? ""
- )
- }
-
- deviceInfoHolder.arrangedSubviews.forEach { $0.isHidden = !configuration.showsDeviceInfo }
- accountButton.isHidden = !configuration.showsAccountButton
+ deviceName = configuration.deviceName
+ timeLeft = configuration.expiry
+ isAccountButtonHidden = !configuration.showsAccountButton
}
}
diff --git a/ios/MullvadVPN/Containers/Root/RootConfiguration.swift b/ios/MullvadVPN/Containers/Root/RootConfiguration.swift
index 0afbb7e68e..b6426e16a9 100644
--- a/ios/MullvadVPN/Containers/Root/RootConfiguration.swift
+++ b/ios/MullvadVPN/Containers/Root/RootConfiguration.swift
@@ -12,5 +12,4 @@ struct RootConfiguration {
var deviceName: String?
var expiry: Date?
var showsAccountButton: Bool
- let showsDeviceInfo: Bool
}
diff --git a/ios/MullvadVPN/Containers/Root/RootContainerViewController.swift b/ios/MullvadVPN/Containers/Root/RootContainerViewController.swift
index a62f0929f7..ae5f95f16a 100644
--- a/ios/MullvadVPN/Containers/Root/RootContainerViewController.swift
+++ b/ios/MullvadVPN/Containers/Root/RootContainerViewController.swift
@@ -70,7 +70,7 @@ class RootContainerViewController: UIViewController {
let transitionContainer = UIView(frame: UIScreen.main.bounds)
private var presentationContainerAccountButton: UIButton?
private var presentationContainerSettingsButton: UIButton?
- private var configuration = RootConfiguration(showsAccountButton: false, showsDeviceInfo: true)
+ private var configuration = RootConfiguration(showsAccountButton: false)
private(set) var headerBarPresentation = HeaderBarPresentation.default
private(set) var headerBarHidden = false
@@ -789,8 +789,11 @@ extension UIViewController {
extension RootContainerViewController {
func update(configuration: RootConfiguration) {
self.configuration = configuration
-
presentationContainerAccountButton?.isHidden = !configuration.showsAccountButton
headerBarView.update(configuration: configuration)
}
+
+ func hideDeviceInfo() {
+ update(configuration: RootConfiguration(showsAccountButton: false))
+ }
}
diff --git a/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift b/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift
index 74d99cd59c..75272cd271 100644
--- a/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift
+++ b/ios/MullvadVPN/Coordinators/App/ApplicationCoordinator.swift
@@ -257,7 +257,7 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
// MARK: - Private
- private var isPresentingRegisteredDeviceBanner = false
+ private var isPresentingAccountExpiryBanner = false
/**
Continues application flow by evaluating what route to present next.
@@ -703,17 +703,14 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
self.tunnelObserver = tunnelObserver
- updateView(deviceState: tunnelManager.deviceState)
+ updateDeviceInfo(deviceState: tunnelManager.deviceState)
splitViewController.preferredDisplayMode = tunnelManager.deviceState.splitViewMode
}
private func deviceStateDidChange(_ deviceState: DeviceState, previousDeviceState: DeviceState) {
splitViewController.preferredDisplayMode = deviceState.splitViewMode
- updateView(
- deviceState: deviceState,
- showDeviceInfo: shouldShowDeviceInfo(deviceState, previousDeviceState: previousDeviceState)
- )
+ updateDeviceInfo(deviceState: deviceState)
switch deviceState {
case let .loggedIn(accountData, _):
@@ -741,30 +738,24 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
}
}
- private func shouldShowDeviceInfo(_ deviceState: DeviceState, previousDeviceState: DeviceState) -> Bool {
- switch (previousDeviceState, deviceState) {
- case (.loggedOut, .loggedIn):
- isPresentingRegisteredDeviceBanner = true
- return false
- case (.loggedIn, .loggedIn):
- return !isPresentingRegisteredDeviceBanner
- default:
- return false
+ private func updateDeviceInfo(deviceState: DeviceState) {
+ switch deviceState {
+ case let .loggedIn(storedAccountData, _):
+ let configuration = RootConfiguration(
+ deviceName: deviceState.deviceData?.capitalizedName,
+ expiry: (isPresentingAccountExpiryBanner || storedAccountData.isExpired)
+ ? nil
+ : deviceState.accountData?.expiry,
+ showsAccountButton: true
+ )
+ primaryNavigationContainer.update(configuration: configuration)
+ secondaryNavigationContainer.update(configuration: configuration)
+ case .loggedOut, .revoked:
+ primaryNavigationContainer.hideDeviceInfo()
+ secondaryNavigationContainer.hideDeviceInfo()
}
}
- private func updateView(deviceState: DeviceState, showDeviceInfo: Bool = true) {
- let configuration = RootConfiguration(
- deviceName: deviceState.deviceData?.capitalizedName,
- expiry: deviceState.accountData?.expiry,
- showsAccountButton: deviceState.isLoggedIn,
- showsDeviceInfo: showDeviceInfo
- )
-
- primaryNavigationContainer.update(configuration: configuration)
- secondaryNavigationContainer.update(configuration: configuration)
- }
-
// MARK: - Out of time
private func updateOutOfTimeTimer(accountData: StoredAccountData) {
@@ -891,6 +882,9 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
_ manager: NotificationManager,
notifications: [InAppNotificationDescriptor]
) {
+ isPresentingAccountExpiryBanner = notifications
+ .contains(where: { $0.identifier == .accountExpiryInAppNotification })
+ updateDeviceInfo(deviceState: tunnelManager.deviceState)
notificationController.setNotifications(notifications, animated: true)
}
@@ -898,9 +892,9 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
switch response.providerIdentifier {
case .accountExpirySystemNotification:
router.present(.account)
- case .registeredDeviceInAppNotification:
- isPresentingRegisteredDeviceBanner = false
- updateView(deviceState: tunnelManager.deviceState)
+ case .accountExpiryInAppNotification:
+ isPresentingAccountExpiryBanner = false
+ updateDeviceInfo(deviceState: tunnelManager.deviceState)
default: return
}
}