Commit e42eb9ea authored by Jose Blaya's avatar Jose Blaya
Browse files

Subscription tile

parent 64d59f15
This diff is collapsed.
......@@ -502,8 +502,20 @@ internal enum L10n {
internal static let title = L10n.tr("Localizable", "tiles.region.title")
}
internal enum Subscription {
/// Monthly
internal static let monthly = L10n.tr("Localizable", "tiles.subscription.monthly")
/// Subscription
internal static let title = L10n.tr("Localizable", "tiles.subscription.title")
/// Trial
internal static let trial = L10n.tr("Localizable", "tiles.subscription.trial")
/// Yearly
internal static let yearly = L10n.tr("Localizable", "tiles.subscription.yearly")
internal enum Days {
/// (%d days left)
internal static func `left`(_ p1: Int) -> String {
return L10n.tr("Localizable", "tiles.subscription.days.left", p1)
}
}
}
}
......
......@@ -48,6 +48,7 @@ class SubscriptionTile: UIView, Tileable {
subscriptionTitle.style(style: TextStyle.textStyle21)
Theme.current.applySubtitle(subscriptionValue)
Theme.current.applySolidLightBackground(self)
displayAccountInformation()
}
@objc private func displayAccountInformation() {
......@@ -57,12 +58,37 @@ class SubscriptionTile: UIView, Tileable {
if userInfo.isExpired {
self.subscriptionValue.text = L10n.Account.ExpiryDate.expired
} else {
self.subscriptionValue.text = L10n.Account.ExpiryDate.information(userInfo.humanReadableExpirationDate())
var value = L10n.Account.ExpiryDate.information(userInfo.humanReadableExpirationDate())
if let days = daysLeftFromAccountInfo(userInfo) {
let daysLeft = L10n.Tiles.Subscription.Days.left(days)
let plan = planDescriptionFromPlan(userInfo.plan)
if plan != "" {
value = plan + " " + daysLeft
}
}
self.subscriptionValue.text = value
}
Theme.current.makeSmallLabelToStandOut(self.subscriptionValue,
withTextToStandOut: userInfo.humanReadableExpirationDate())
withTextToStandOut: planDescriptionFromPlan(userInfo.plan))
}
}
private func planDescriptionFromPlan(_ plan: Plan) -> String {
switch plan {
case .trial: return L10n.Tiles.Subscription.trial
case .monthly: return L10n.Tiles.Subscription.monthly
case .yearly: return L10n.Tiles.Subscription.yearly
default: return ""
}
}
private func daysLeftFromAccountInfo(_ userInfo: AccountInfo) -> Int? {
if let days = userInfo.dateComponentsBeforeExpiration.day {
return days +
1 + //today
1 //last day
}
return nil
}
}
......@@ -21,6 +21,8 @@ class SubscriptionTileCollectionViewCell: UICollectionViewCell, TileableCell {
@IBOutlet weak var tileRightConstraint: NSLayoutConstraint!
func setupCellForStatus(_ status: TileStatus) {
Theme.current.applySolidLightBackground(self)
Theme.current.applySolidLightBackground(self.contentView)
self.accessoryImageRight.image = Theme.current.dragDropImage()
tile.status = status
UIView.animate(withDuration: AppConfiguration.Animations.duration, animations: {
......@@ -36,17 +38,17 @@ class SubscriptionTileCollectionViewCell: UICollectionViewCell, TileableCell {
self.layoutIfNeeded()
})
}
private func setupVisibilityButton() {
if Client.providers.tileProvider.visibleTiles.contains(tileType) {
accessoryButtonLeft.setImage(Asset.Piax.Global.eyeActive.image, for: .normal)
accessoryButtonLeft.setImage(Asset.Piax.Global.eyeInactive.image, for: .highlighted)
accessoryButtonLeft.setImage(Theme.current.activeEyeImage(), for: .normal)
accessoryButtonLeft.setImage(Theme.current.inactiveEyeImage(), for: .highlighted)
} else {
accessoryButtonLeft.setImage(Asset.Piax.Global.eyeInactive.image, for: .normal)
accessoryButtonLeft.setImage(Asset.Piax.Global.eyeActive.image, for: .highlighted)
accessoryButtonLeft.setImage(Theme.current.inactiveEyeImage(), for: .normal)
accessoryButtonLeft.setImage(Theme.current.activeEyeImage(), for: .highlighted)
}
}
@IBAction private func changeTileVisibility() {
var visibleTiles = Client.providers.tileProvider.visibleTiles
if Client.providers.tileProvider.visibleTiles.contains(tileType) {
......
......@@ -212,3 +212,7 @@
"tiles.quick.connect.title" = "Quick connect";
"tiles.region.title" = "VPN Server";
"tiles.subscription.title" = "Subscription";
"tiles.subscription.trial" = "Trial";
"tiles.subscription.monthly" = "Monthly";
"tiles.subscription.yearly" = "Yearly";
"tiles.subscription.days.left" = "(%d days left)";
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment