diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2023-04-14 16:42:34 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-04-14 16:42:34 +0200 |
| commit | 8a04ce4108b5385da663d42d5014854e08bbfedd (patch) | |
| tree | d27a173e79096197f1331297be28ea1e1be01db7 /ios/MullvadVPN/Containers | |
| parent | 9ed9e881a1e16f4ec4b3783970e84a0023a6dbbc (diff) | |
| parent | e27564dd551e50d1605d1ecb899e16385d915f41 (diff) | |
| download | mullvadvpn-8a04ce4108b5385da663d42d5014854e08bbfedd.tar.xz mullvadvpn-8a04ce4108b5385da663d42d5014854e08bbfedd.zip | |
Merge branch 'add-device-name-and-time-left-labels-to-ios-96'
Diffstat (limited to 'ios/MullvadVPN/Containers')
| -rw-r--r-- | ios/MullvadVPN/Containers/Root/HeaderBarView.swift | 65 | ||||
| -rw-r--r-- | ios/MullvadVPN/Containers/Root/RootContainerViewController.swift | 6 |
2 files changed, 68 insertions, 3 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) + } +} |
