diff options
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 4 | ||||
| -rw-r--r-- | ios/MullvadVPN/AccountContentView.swift | 12 | ||||
| -rw-r--r-- | ios/MullvadVPN/AccountExpiry.swift | 34 | ||||
| -rw-r--r-- | ios/MullvadVPN/SettingsAccountCell.swift | 59 |
4 files changed, 40 insertions, 69 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index bf644e9dc1..ad36d1046a 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -69,7 +69,6 @@ 582BB1AF229566420055B6EF /* SettingsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582BB1AE229566420055B6EF /* SettingsCell.swift */; }; 582BB1B1229569620055B6EF /* CustomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582BB1B0229569620055B6EF /* CustomNavigationBar.swift */; }; 582BB1B3229574F40055B6EF /* SettingsAccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582BB1B2229574F40055B6EF /* SettingsAccountCell.swift */; }; - 582BB1B52295780F0055B6EF /* AccountExpiry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 582BB1B42295780F0055B6EF /* AccountExpiry.swift */; }; 582CFEE726945FC30072883A /* AppStoreSubscriptions.strings in Resources */ = {isa = PBXBuildFile; fileRef = 582CFEE526945FC30072883A /* AppStoreSubscriptions.strings */; }; 582CFEEA269463B80072883A /* Settings.strings in Resources */ = {isa = PBXBuildFile; fileRef = 582CFEE8269463B80072883A /* Settings.strings */; }; 5835B7CC233B76CB0096D79F /* TunnelManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5835B7CB233B76CB0096D79F /* TunnelManager.swift */; }; @@ -398,7 +397,6 @@ 582BB1AE229566420055B6EF /* SettingsCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsCell.swift; sourceTree = "<group>"; }; 582BB1B0229569620055B6EF /* CustomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationBar.swift; sourceTree = "<group>"; }; 582BB1B2229574F40055B6EF /* SettingsAccountCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsAccountCell.swift; sourceTree = "<group>"; }; - 582BB1B42295780F0055B6EF /* AccountExpiry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountExpiry.swift; sourceTree = "<group>"; }; 582CFEE626945FC30072883A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/AppStoreSubscriptions.strings; sourceTree = "<group>"; }; 582CFEE9269463B80072883A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Settings.strings; sourceTree = "<group>"; }; 5835B7CB233B76CB0096D79F /* TunnelManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelManager.swift; sourceTree = "<group>"; }; @@ -867,7 +865,6 @@ children = ( 587AD7C92342283900E93A53 /* Account.swift */, 5896CEF126972DEB00B0FAE8 /* AccountContentView.swift */, - 582BB1B42295780F0055B6EF /* AccountExpiry.swift */, 58C3A4B122456F1A00340BDB /* AccountInputGroupView.swift */, 58CCA01D2242787B004F3011 /* AccountTextField.swift */, 582AE30F2440A6CA00E6733A /* AccountTokenInput.swift */, @@ -1344,7 +1341,6 @@ 58B993B12608A34500BA7811 /* LoginContentView.swift in Sources */, 58E6771F24ADFE7800AA26E7 /* SettingsNavigationController.swift in Sources */, 58A1AA8C23F5584C009F7EA6 /* ConnectionPanelView.swift in Sources */, - 582BB1B52295780F0055B6EF /* AccountExpiry.swift in Sources */, 582BB1B3229574F40055B6EF /* SettingsAccountCell.swift in Sources */, 588527B2276B3F0700BAA373 /* LoadTunnelOperation.swift in Sources */, 58F1311527E0B2AB007AC5BC /* Result+Extensions.swift in Sources */, 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 + } } |
