feat: Add loading when retrieving available purchases
This commit is contained in:
+28
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user