summaryrefslogtreecommitdiffhomepage
path: root/ios
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-04-06 14:28:14 +0200
committerAndrej Mihajlov <and@mullvad.net>2020-04-06 14:28:14 +0200
commit8472bbee6053d4de4d973fbfa1a50bef8ee96e90 (patch)
tree0ee46dd3588e7e5c96868bf143dc0996468b0a82 /ios
parent7d61c0f2231ebd7222f3c8be875e274d49ee3e26 (diff)
parenteb3975a74b08e992e8d7b3fd1cc48ef1e43f230a (diff)
downloadmullvadvpn-8472bbee6053d4de4d973fbfa1a50bef8ee96e90.tar.xz
mullvadvpn-8472bbee6053d4de4d973fbfa1a50bef8ee96e90.zip
Merge branch 'improve-account-view'
Diffstat (limited to 'ios')
-rw-r--r--ios/MullvadVPN/AccountExpiry.swift2
-rw-r--r--ios/MullvadVPN/AccountViewController.swift11
-rw-r--r--ios/MullvadVPN/InAppPurchaseButton.swift45
3 files changed, 48 insertions, 10 deletions
diff --git a/ios/MullvadVPN/AccountExpiry.swift b/ios/MullvadVPN/AccountExpiry.swift
index 87d40e87fc..64f85eb0d2 100644
--- a/ios/MullvadVPN/AccountExpiry.swift
+++ b/ios/MullvadVPN/AccountExpiry.swift
@@ -33,7 +33,7 @@ class AccountExpiry {
}
var formattedDate: String {
- return DateFormatter.localizedString(from: date, dateStyle: .medium, timeStyle: .medium)
+ return DateFormatter.localizedString(from: date, dateStyle: .medium, timeStyle: .short)
}
}
diff --git a/ios/MullvadVPN/AccountViewController.swift b/ios/MullvadVPN/AccountViewController.swift
index d49e156532..0f0d300ba6 100644
--- a/ios/MullvadVPN/AccountViewController.swift
+++ b/ios/MullvadVPN/AccountViewController.swift
@@ -63,12 +63,6 @@ class AccountViewController: UIViewController {
self?.updateAccountExpiry(expiryDate: newExpiryDate)
}
- // Make sure the buy button scales down the font size to fit the long labels.
- // Changing baseline adjustment helps to prevent the text from being misaligned after
- // being scaled down.
- purchaseButton.titleLabel?.adjustsFontSizeToFitWidth = true
- purchaseButton.titleLabel?.baselineAdjustment = .alignCenters
-
accountTokenButton.setTitle(Account.shared.formattedToken, for: .normal)
if let expiryDate = Account.shared.expiry {
@@ -98,9 +92,12 @@ class AccountViewController: UIViewController {
}
private func requestStoreProducts() {
+ let inAppPurchase = AppStoreSubscription.thirtyDays
+
+ purchaseButton.setTitle(inAppPurchase.localizedTitle, for: .normal)
purchaseButton.isLoading = true
- requestProductsSubscriber = AppStorePaymentManager.shared.requestProducts(with: [.thirtyDays])
+ requestProductsSubscriber = AppStorePaymentManager.shared.requestProducts(with: [inAppPurchase])
.retry(10)
.receive(on: DispatchQueue.main)
.restrictUserInterfaceInteraction(with: self.purchaseButtonInteractionRestriction, animated: true)
diff --git a/ios/MullvadVPN/InAppPurchaseButton.swift b/ios/MullvadVPN/InAppPurchaseButton.swift
index 38ae3c90fe..63d91c3b9e 100644
--- a/ios/MullvadVPN/InAppPurchaseButton.swift
+++ b/ios/MullvadVPN/InAppPurchaseButton.swift
@@ -21,7 +21,7 @@ class InAppPurchaseButton: AppButton {
activityIndicator.stopAnimating()
}
- titleLabel?.alpha = isLoading ? 0 : 1
+ setNeedsLayout()
}
}
@@ -37,11 +37,52 @@ class InAppPurchaseButton: AppButton {
private func commonInit() {
addSubview(activityIndicator)
+
+ // Make sure the buy button scales down the font size to fit the long labels.
+ // Changing baseline adjustment helps to prevent the text from being misaligned after
+ // being scaled down.
+ titleLabel?.adjustsFontSizeToFitWidth = true
+ titleLabel?.baselineAdjustment = .alignCenters
}
override func layoutSubviews() {
super.layoutSubviews()
- activityIndicator.center = self.center
+ activityIndicator.frame = activityIndicatorRect(
+ forContentRect: contentRect(forBounds: bounds)
+ )
+ }
+
+ override func titleRect(forContentRect contentRect: CGRect) -> CGRect {
+ var titleRect = super.titleRect(forContentRect: contentRect)
+ let activityIndicatorRect = self.activityIndicatorRect(forContentRect: contentRect)
+
+ // Adjust the title frame in case if it overlaps the activity indicator
+ let intersection = titleRect.intersection(activityIndicatorRect)
+ if !intersection.isNull {
+ if case .leftToRight = effectiveUserInterfaceLayoutDirection {
+ titleRect.origin.x = max(contentRect.minX, titleRect.minX - intersection.width)
+ titleRect.size.width = intersection.minX - titleRect.minX
+ } else {
+ titleRect.origin.x = titleRect.minX + intersection.width
+ titleRect.size.width = min(contentRect.maxX, titleRect.maxX) - intersection.maxX
+ }
+ }
+
+ return titleRect
+ }
+
+ private func activityIndicatorRect(forContentRect contentRect: CGRect) -> CGRect {
+ var frame = activityIndicator.frame
+
+ if case .leftToRight = effectiveUserInterfaceLayoutDirection {
+ frame.origin.x = contentRect.maxX - frame.width
+ } else {
+ frame.origin.x = contentRect.minX
+ }
+
+ frame.origin.y = contentRect.midY - frame.height * 0.5
+
+ return frame
}
}