summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-05-19 11:37:52 +0200
committerAndrej Mihajlov <and@mullvad.net>2022-05-30 15:00:06 +0200
commit64bc9e3c2c1923a831157209fed48496b00d46ae (patch)
tree0e3f9556c97dd195b50571673809646ccefe1487 /ios/MullvadVPN
parent93befa53eb5940b765c85544c75fdfddcf04b5ee (diff)
downloadmullvadvpn-64bc9e3c2c1923a831157209fed48496b00d46ae.tar.xz
mullvadvpn-64bc9e3c2c1923a831157209fed48496b00d46ae.zip
Obsolete AccountExpiry
Diffstat (limited to 'ios/MullvadVPN')
-rw-r--r--ios/MullvadVPN/AccountContentView.swift12
-rw-r--r--ios/MullvadVPN/AccountExpiry.swift34
-rw-r--r--ios/MullvadVPN/SettingsAccountCell.swift59
3 files changed, 40 insertions, 65 deletions
diff --git a/ios/MullvadVPN/AccountContentView.swift b/ios/MullvadVPN/AccountContentView.swift
index 93fb6d3186..da3a8fa85f 100644
--- a/ios/MullvadVPN/AccountContentView.swift
+++ b/ios/MullvadVPN/AccountContentView.swift
@@ -172,9 +172,9 @@ class AccountExpiryRow: UIView {
var value: Date? {
didSet {
- let expiry = value.flatMap { AccountExpiry(date: $0) }
+ let expiry = value
- if let expiry = expiry, expiry.isExpired {
+ if let expiry = expiry, expiry <= Date() {
let localizedString = NSLocalizedString(
"ACCOUNT_OUT_OF_TIME_LABEL",
tableName: "Account",
@@ -187,7 +187,13 @@ class AccountExpiryRow: UIView {
valueLabel.textColor = .dangerColor
} else {
- let formattedDate = expiry?.formattedDate
+ let formattedDate = expiry.map { date in
+ return DateFormatter.localizedString(
+ from: date,
+ dateStyle: .medium,
+ timeStyle: .short
+ )
+ }
valueLabel.text = formattedDate
accessibilityValue = formattedDate
diff --git a/ios/MullvadVPN/AccountExpiry.swift b/ios/MullvadVPN/AccountExpiry.swift
deleted file mode 100644
index 4618e736ae..0000000000
--- a/ios/MullvadVPN/AccountExpiry.swift
+++ /dev/null
@@ -1,34 +0,0 @@
-//
-// AccountExpiry.swift
-// MullvadVPN
-//
-// Created by pronebird on 22/05/2019.
-// Copyright © 2019 Mullvad VPN AB. All rights reserved.
-//
-
-import Foundation
-
-class AccountExpiry {
- let date: Date
-
- init(date: Date) {
- self.date = date
- }
-
- var isExpired: Bool {
- return date <= Date()
- }
-
- var formattedRemainingTime: String? {
- return CustomDateComponentsFormatting.localizedString(
- from: Date(),
- to: date,
- unitsStyle: .full
- )
- }
-
- var formattedDate: String {
- return DateFormatter.localizedString(from: date, dateStyle: .medium, timeStyle: .short)
- }
-
-}
diff --git a/ios/MullvadVPN/SettingsAccountCell.swift b/ios/MullvadVPN/SettingsAccountCell.swift
index 30411a1276..6021e4cca2 100644
--- a/ios/MullvadVPN/SettingsAccountCell.swift
+++ b/ios/MullvadVPN/SettingsAccountCell.swift
@@ -17,36 +17,39 @@ class SettingsAccountCell: SettingsCell {
}
private func didUpdateAccountExpiry() {
- if let accountExpiryDate = accountExpiryDate {
- let accountExpiry = AccountExpiry(date: accountExpiryDate)
-
- if accountExpiry.isExpired {
- detailTitleLabel.text = NSLocalizedString(
- "ACCOUNT_CELL_OUT_OF_TIME_LABEL",
- tableName: "Settings",
- comment: "Label displayed when user account ran out of time."
- )
- detailTitleLabel.textColor = .dangerColor
- } else {
- if let remainingTime = accountExpiry.formattedRemainingTime {
- let localizedString = NSLocalizedString(
- "ACCOUNT_CELL_TIME_LEFT_LABEL_FORMAT",
- tableName: "Settings",
- value: "%@ left",
- comment: "The amount of time left on user account. Use %@ placeholder to position the localized text with the time duration left (i.e 10 days)."
- )
- let formattedString = String(format: localizedString, remainingTime)
-
- detailTitleLabel.text = formattedString.uppercased()
- } else {
- detailTitleLabel.text = ""
- }
- detailTitleLabel.textColor = UIColor.Cell.detailTextColor
- }
- } else {
+ guard let accountExpiryDate = accountExpiryDate else {
detailTitleLabel.text = ""
detailTitleLabel.textColor = UIColor.Cell.detailTextColor
+ return
}
- }
+ guard accountExpiryDate > Date() else {
+ detailTitleLabel.text = NSLocalizedString(
+ "ACCOUNT_CELL_OUT_OF_TIME_LABEL",
+ tableName: "Settings",
+ value: "OUT OF TIME",
+ comment: ""
+ )
+ detailTitleLabel.textColor = .dangerColor
+ return
+ }
+
+ let formattedTime = CustomDateComponentsFormatting.localizedString(
+ from: Date(),
+ to: accountExpiryDate,
+ unitsStyle: .full
+ )
+
+ detailTitleLabel.text = formattedTime.map { remainingTimeString in
+ let localizedString = NSLocalizedString(
+ "ACCOUNT_CELL_TIME_LEFT_LABEL_FORMAT",
+ tableName: "Settings",
+ value: "%@ left",
+ comment: ""
+ )
+
+ return String(format: localizedString, remainingTimeString).uppercased()
+ } ?? ""
+ detailTitleLabel.textColor = UIColor.Cell.detailTextColor
+ }
}