feat: Add loading when retrieving available purchases

This commit is contained in:
Andrea Busi
2020-07-30 21:04:49 +02:00
parent e678d12de9
commit dca602a4cd
3 changed files with 61 additions and 15 deletions
@@ -10,10 +10,37 @@ import UIKit
class SubscriptionsHeaderTableViewCell: EQNBaseTableViewCell {
@IBOutlet weak var headerTitleLabel: UILabel!
var isLoading = false {
didSet {
updateUI()
}
}
var title: String? = nil {
didSet {
updateUI()
}
}
@IBOutlet private weak var headerTitleLabel: UILabel!
@IBOutlet private weak var loadingActivityIndicator: UIActivityIndicatorView!
// MARK: - View Lifecycle
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
// MARK: - Private
private func updateUI() {
headerTitleLabel.text = title
if isLoading && title != nil {
loadingActivityIndicator.startAnimating()
} else {
loadingActivityIndicator.stopAnimating()
}
}
}
@@ -38,6 +38,8 @@ class SubscriptionsViewController: UITableViewController {
private var subscribedProduct: SKProduct?
/// Availability for subscriptions
private var availability: EQNPurchaseAvailability?
/// Tells if products are loading
private var isLoading = false
// MARK: - View Lifecycle
@@ -117,7 +119,11 @@ class SubscriptionsViewController: UITableViewController {
}
private func loadData() {
isLoading = true
VersioneProProducts.store.requestProducts{ [weak self] success, products in
self?.isLoading = false
guard let self = self, let products = products, success == true else { return }
// todo: teniamo il più "alto"
@@ -172,7 +178,8 @@ class SubscriptionsViewController: UITableViewController {
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let tableSection = sections[section]
if let cell = tableView.dequeueReusableCell(withIdentifier: "SectionHeaderCell") as? SubscriptionsHeaderTableViewCell {
cell.headerTitleLabel.text = tableSection.sectionTitle
cell.title = tableSection.sectionTitle
cell.isLoading = isLoading
return cell
}
return nil