Add platform-specific version purchase

This commit is contained in:
Davide De Rosa 2021-02-04 13:42:57 +01:00
parent 394762f5d6
commit d2bcfd8adc
2 changed files with 68 additions and 4 deletions

View File

@ -43,9 +43,13 @@ class PurchaseViewController: UITableViewController, StrongTableHost {
weak var delegate: PurchaseViewControllerDelegate?
private var skFeature: SKProduct?
private var skPlatformVersion: SKProduct?
private var skFullVersion: SKProduct?
private var platformVersionExtra: String?
private var fullVersionExtra: String?
// MARK: StrongTableHost
@ -59,6 +63,10 @@ class PurchaseViewController: UITableViewController, StrongTableHost {
var rows: [RowType] = []
let pm = ProductManager.shared
if let skPlatformVersion = pm.product(withIdentifier: .fullVersion_iOS) {
self.skPlatformVersion = skPlatformVersion
rows.append(.platformVersion)
}
if let skFullVersion = pm.product(withIdentifier: .fullVersion) {
self.skFullVersion = skFullVersion
rows.append(.fullVersion)
@ -70,11 +78,17 @@ class PurchaseViewController: UITableViewController, StrongTableHost {
rows.append(.restore)
model.set(rows, forSection: .products)
let featureBulletsList: [String] = ProductManager.shared.featureProducts(excluding: [.fullVersion, .fullVersion_iOS]).map {
let platformBulletsList: [String] = ProductManager.shared.featureProducts(excluding: [.fullVersion, .fullVersion_iOS, .fullVersion_macOS]).map {
return "- \($0.localizedTitle)"
}.sortedCaseInsensitive()
let featureBullets = featureBulletsList.joined(separator: "\n")
fullVersionExtra = L10n.App.Purchase.Cells.FullVersion.extraDescription(featureBullets)
let platformBullets = platformBulletsList.joined(separator: "\n")
platformVersionExtra = "- \(L10n.Core.Purchase.Cells.FullVersion.extraDescription(platformBullets))"
let fullBulletsList: [String] = ProductManager.shared.featureProducts(excluding: [.fullVersion, .fullVersion_iOS]).map {
return "- \($0.localizedTitle)"
}.sortedCaseInsensitive()
let fullBullets = fullBulletsList.joined(separator: "\n")
fullVersionExtra = "- \(L10n.Core.Purchase.Cells.FullVersion.extraDescription(fullBullets))"
}
// MARK: UIViewController
@ -113,6 +127,13 @@ class PurchaseViewController: UITableViewController, StrongTableHost {
}
purchase(sk)
}
private func purchasePlatformVersion() {
guard let sk = skPlatformVersion else {
return
}
purchase(sk)
}
private func purchaseFullVersion() {
guard let sk = skFullVersion else {
@ -174,8 +195,10 @@ extension PurchaseViewController {
enum RowType {
case feature
case fullVersion
case platformVersion
case fullVersion
case restore
}
@ -203,6 +226,12 @@ extension PurchaseViewController {
}
cell.fill(product: product)
case .platformVersion:
guard let product = skPlatformVersion else {
fatalError("Loaded platform version cell, yet no corresponding product?")
}
cell.fill(product: product, customDescription: platformVersionExtra)
case .fullVersion:
guard let product = skFullVersion else {
fatalError("Loaded full version cell, yet no corresponding product?")
@ -225,6 +254,9 @@ extension PurchaseViewController {
case .feature:
purchaseFeature()
case .platformVersion:
purchasePlatformVersion()
case .fullVersion:
purchaseFullVersion()

View File

@ -58,8 +58,12 @@ class PurchaseViewController: NSViewController {
private var skFeature: SKProduct?
private var skPlatformVersion: SKProduct?
private var skFullVersion: SKProduct?
private var platformVersionExtra: String?
private var fullVersionExtra: String?
var rows: [RowType] = []
@ -67,6 +71,10 @@ class PurchaseViewController: NSViewController {
func reloadModel() {
rows = []
let pm = ProductManager.shared
if let skPlatformVersion = pm.product(withIdentifier: .fullVersion_macOS) {
self.skPlatformVersion = skPlatformVersion
rows.append(.platformVersion)
}
if let skFullVersion = pm.product(withIdentifier: .fullVersion) {
self.skFullVersion = skFullVersion
rows.append(.fullVersion)
@ -76,6 +84,12 @@ class PurchaseViewController: NSViewController {
rows.append(.feature)
}
let platformBulletsList: [String] = ProductManager.shared.featureProducts(excluding: [.fullVersion, .fullVersion_iOS, .fullVersion_macOS]).map {
return $0.localizedTitle
}.sortedCaseInsensitive()
let platformBullets = platformBulletsList.joined(separator: "\n")
platformVersionExtra = L10n.Core.Purchase.Cells.FullVersion.extraDescription(platformBullets)
let fullBulletsList: [String] = ProductManager.shared.featureProducts(excluding: [.fullVersion, .fullVersion_macOS]).map {
return $0.localizedTitle
}.sortedCaseInsensitive()
@ -129,6 +143,9 @@ class PurchaseViewController: NSViewController {
case .feature:
purchaseFeature()
case .platformVersion:
purchasePlatformVersion()
case .fullVersion:
purchaseFullVersion()
}
@ -152,6 +169,13 @@ class PurchaseViewController: NSViewController {
purchase(sk)
}
private func purchasePlatformVersion() {
guard let sk = skPlatformVersion else {
return
}
purchase(sk)
}
private func purchaseFullVersion() {
guard let sk = skFullVersion else {
return
@ -213,6 +237,8 @@ extension PurchaseViewController: NSTableViewDataSource, NSTableViewDelegate {
enum RowType {
case feature
case platformVersion
case fullVersion
}
@ -231,6 +257,12 @@ extension PurchaseViewController: NSTableViewDataSource, NSTableViewDelegate {
}
view.fill(product: product)
case .platformVersion:
guard let product = skPlatformVersion else {
fatalError("Loaded platform version cell, yet no corresponding product?")
}
view.fill(product: product, customDescription: platformVersionExtra)
case .fullVersion:
guard let product = skFullVersion else {
fatalError("Loaded full version cell, yet no corresponding product?")