52 lines
1.6 KiB
Swift
52 lines
1.6 KiB
Swift
//
|
|
// SubscriptionProductTableViewCell.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Busi Andrea on 29/07/2020.
|
|
// Copyright © 2020 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import StoreKit
|
|
|
|
class SubscriptionProductTableViewCell: EQNInsetTableViewCell {
|
|
|
|
var product: SKProduct? {
|
|
didSet {
|
|
updateUI()
|
|
}
|
|
}
|
|
var availability: EQNPurchaseAvailability? {
|
|
didSet {
|
|
updateUI()
|
|
}
|
|
}
|
|
|
|
@IBOutlet private weak var productImageView: UIImageView!
|
|
@IBOutlet private weak var productTitleLabel: UILabel!
|
|
@IBOutlet private weak var productDescriptionLabel: UILabel?
|
|
@IBOutlet private weak var productInfoLabel: UILabel!
|
|
|
|
|
|
// MARK: - Private
|
|
|
|
private func updateUI() {
|
|
guard let product = product else { return }
|
|
|
|
productImageView.image = imageForProductIdentifier(product.productIdentifier)
|
|
productTitleLabel.text = product.localizedTitle
|
|
productDescriptionLabel?.text = product.localizedDescription
|
|
|
|
let infoKey = is100kSubscriptionForProductIdentifier(product.productIdentifier) ? "inapp_available_100k" : "inapp_available_10k"
|
|
let counter = availability(for: product.productIdentifier)
|
|
productInfoLabel.text = String(format: NSLocalizedString(infoKey, comment: ""), counter)
|
|
}
|
|
|
|
private func availability(for productIdentifier: String) -> Int {
|
|
if is100kSubscriptionForProductIdentifier(productIdentifier) {
|
|
return availability?.top100kAvailable ?? 0
|
|
}
|
|
return availability?.top10kAvailable ?? 0
|
|
}
|
|
}
|