Skip to content
This repository has been archived by the owner. It is now read-only.

Upgrade flow #244

Merged
merged 3 commits into from Feb 7, 2019
Merged
Changes from all commits
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -305,6 +305,7 @@ class VPNViewController: UIViewController {
let countryButtonHeight: CGFloat = 50.0

var upgradeView: UpgradeView?
var upgradeButton: ButtonWithUnderlinedText?

var VPNStatus: NEVPNStatus {
return VPN.shared.status;
@@ -347,10 +348,23 @@ class VPNViewController: UIViewController {
view.addSubview(infoLabel)
view.addSubview(connectButton)
#if PAID
if let trialRemainingDays = SubscriptionController.shared.getCurrentSubscription().trialRemainingDays(), trialRemainingDays < 8 {
self.upgradeView = UpgradeView()
self.upgradeView?.delegate = self
view.addSubview(upgradeView!)
let currentSubscription = SubscriptionController.shared.getCurrentSubscription()
switch currentSubscription {
case .trial(_):
if let trialRemainingDays = currentSubscription.trialRemainingDays(), trialRemainingDays < 8 {
self.upgradeView = UpgradeView()
self.upgradeView?.delegate = self
view.addSubview(upgradeView!)
}
case .limited:
infoLabel.removeFromSuperview()
let title = NSLocalizedString("Unlock the VPN feature to get the best out of Lumen.", tableName: "Lumen", comment: "Unlock the VPN feature text")
let action = NSLocalizedString("LEARN MORE", tableName: "Lumen", comment: "LEARN MORE action")
upgradeButton = ButtonWithUnderlinedText(startText: (title, UIColor.theme.lumenSubscription.upgradeLabel), underlinedText: (action, UIColor.lumenBrightBlue), position: .next)
upgradeButton?.addTarget(self, action: #selector(showUpgradeViewController), for: .touchUpInside)
self.view.addSubview(upgradeButton!)
default:
break
}
#endif
}
@@ -379,18 +393,33 @@ class VPNViewController: UIViewController {
make.top.equalTo(tableView.snp.bottom).offset(20)
}

connectButton.snp.makeConstraints { (make) in
make.centerX.equalToSuperview()
make.bottom.equalTo(infoLabel.snp.top).offset(-16)
}

infoLabel.snp.makeConstraints { (make) in
make.bottom.equalToSuperview().offset(-26)
make.width.equalToSuperview().dividedBy(1.25)
make.centerX.equalToSuperview()
//I should not set the height. Quick fix.
make.height.equalTo(40)
if let upgradeButton = self.upgradeButton {
connectButton.snp.makeConstraints { (make) in
make.centerX.equalToSuperview()
make.bottom.equalTo(upgradeButton.snp.top).offset(-16)
}
upgradeButton.snp.makeConstraints { (make) in
make.bottom.equalToSuperview().offset(-26)
make.width.equalToSuperview().dividedBy(1.25)
make.centerX.equalToSuperview()
//I should not set the height. Quick fix.
make.height.equalTo(40)
}
} else {
connectButton.snp.makeConstraints { (make) in
make.centerX.equalToSuperview()
make.bottom.equalTo(infoLabel.snp.top).offset(-16)
}
infoLabel.snp.makeConstraints { (make) in
make.bottom.equalToSuperview().offset(-26)
make.width.equalToSuperview().dividedBy(1.25)
make.centerX.equalToSuperview()
//I should not set the height. Quick fix.
make.height.equalTo(40)
}
}

}

private func setStyling() {
@@ -637,7 +666,7 @@ extension VPNViewController: Themeable {
}

extension VPNViewController : UpgradeLumenDelegate {
func showUpgradeViewController() {
@objc func showUpgradeViewController() {
let upgradLumenViewController = UpgradLumenViewController()
self.present(upgradLumenViewController, animated: true, completion: nil)
}
@@ -27,6 +27,7 @@ var lumenDashboardMode: LumenThemeMode = UserPreferences.instance.isProtectionOn
class PaidControlCenterViewController: ControlCenterViewController {

var upgradeView: UpgradeView?
var upgradeButton: ButtonWithUnderlinedText?
let controls = CCControlsView()
let tabs = UISegmentedControl(items: [NSLocalizedString("Today", tableName: "Lumen", comment:"[Lumen->Dashboard] Today tab"),
NSLocalizedString("Last 7 days", tableName: "Lumen", comment:"[Lumen->Dashboard] Last 7 days tab")])
@@ -102,9 +103,18 @@ class PaidControlCenterViewController: ControlCenterViewController {
make.top.equalTo(tabs.snp.bottom).offset(12)
make.trailing.leading.equalToSuperview()
}

if let upgradeButton = upgradeButton {
upgradeButton.snp.makeConstraints { (make) in
make.top.equalTo(protectionLabel.snp.bottom)
make.centerX.equalToSuperview()
}
}
dashboard.view.snp.makeConstraints { (make) in
make.top.equalTo(protectionLabel.snp.bottom).offset(10)
if let upgradeButton = upgradeButton {
make.top.equalTo(upgradeButton.snp.bottom).offset(10)
} else {
make.top.equalTo(protectionLabel.snp.bottom).offset(10)
}
make.trailing.leading.bottom.equalToSuperview()
}
}
@@ -340,7 +350,7 @@ class CCControlsView: UIView {
}

extension PaidControlCenterViewController : UpgradeLumenDelegate {
func showUpgradeViewController() {
@objc func showUpgradeViewController() {
let upgradLumenViewController = UpgradLumenViewController()
self.present(upgradLumenViewController, animated: true, completion: nil)
}
@@ -349,9 +359,19 @@ extension PaidControlCenterViewController : UpgradeLumenDelegate {
let currentSubscription = SubscriptionController.shared.getCurrentSubscription()
switch currentSubscription {
case .trial(_):
if let trialRemainingDays = currentSubscription.trialRemainingDays(), trialRemainingDays < 8 {
self.addUpgradeView()
let trialRemainingDays = currentSubscription.trialRemainingDays() ?? -1
if trialRemainingDays > 7 {
let title = String(format: NSLocalizedString("%d more days left in trial", tableName: "Lumen", comment: "Trial days left title"), trialRemainingDays)
let action = NSLocalizedString("UPGRADE", tableName: "Lumen", comment: "Upgrade action")
upgradeButton = ButtonWithUnderlinedText(startText: (title, UIColor.theme.lumenSubscription.upgradeLabel), underlinedText: (action, UIColor.lumenBrightBlue), position: .next)
upgradeButton?.addTarget(self, action: #selector(showUpgradeViewController), for: .touchUpInside)
self.view.addSubview(upgradeButton!)
} else if trialRemainingDays >= 0 {
self.addUpgradeView()
} else {
// TODO: invalid state
}

case .limited:
self.addUpgradeView()
self.disableView()
@@ -31,8 +31,12 @@ class LumenFreshtabViewController: FreshtabViewController {
let type = SubscriptionController.shared.getCurrentSubscription()
switch (type) {
case .limited:
break
// do something
if SubscriptionController.shared.shouldShowTrialExpiredView() {
let trialExpiredView = TrialExpiredView()
trialExpiredView.delegate = self
infoView = trialExpiredView
view.addSubview(trialExpiredView)
}
case .trial:
let days = type.trialRemainingDays() ?? -1
if days > 7 {
@@ -79,7 +83,17 @@ class LumenFreshtabViewController: FreshtabViewController {
make.bottom.left.right.equalToSuperview()
make.top.equalTo(view2ndWeek.snp.bottom)
})
}
} else if let trialExpiredView = self.infoView as? TrialExpiredView {
trialExpiredView.snp.makeConstraints { (make) in
make.left.right.bottom.equalToSuperview().inset(10)
make.height.equalTo(TrialExpiredViewUX.height)
}
self.scrollView.snp.remakeConstraints({ (make) in
make.top.left.right.equalToSuperview()
make.bottom.equalTo(trialExpiredView.snp.top)
})
}

}

fileprivate func showUpgradeOptionsViewController() {
ProTip! Use n and p to navigate between commits in a pull request.