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
|
||||
|
||||
@@ -2493,32 +2493,44 @@ In più sostieni il progetto di ricerca il quale non riceve finanziamenti estern
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="SectionHeaderCell" id="urG-ON-XcB" customClass="SubscriptionsHeaderTableViewCell" customModule="Earthquake_Network" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="518" width="320" height="46.5"/>
|
||||
<rect key="frame" x="0.0" y="518" width="320" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="urG-ON-XcB" id="SrE-iI-Nig">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="46.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Monthly subscriptions" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0xS-ly-xZg">
|
||||
<rect key="frame" x="0.0" y="11" width="304" height="24.5"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" translatesAutoresizingMaskIntoConstraints="NO" id="e1H-JK-cpd">
|
||||
<rect key="frame" x="0.0" y="12" width="320" height="20"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="249" verticalHuggingPriority="251" horizontalCompressionResistancePriority="749" text="Monthly subscriptions" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0xS-ly-xZg">
|
||||
<rect key="frame" x="0.0" y="0.0" width="292" height="20"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="751" verticalHuggingPriority="750" horizontalCompressionResistancePriority="751" hidesWhenStopped="YES" style="medium" translatesAutoresizingMaskIntoConstraints="NO" id="4kc-T4-2fq">
|
||||
<rect key="frame" x="292" y="0.0" width="28" height="20"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="28" id="3si-0h-9NB"/>
|
||||
<constraint firstAttribute="height" constant="20" id="vXr-mZ-d4H"/>
|
||||
</constraints>
|
||||
</activityIndicatorView>
|
||||
</subviews>
|
||||
</stackView>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottomMargin" secondItem="0xS-ly-xZg" secondAttribute="bottom" id="0q2-Ri-jjJ"/>
|
||||
<constraint firstItem="0xS-ly-xZg" firstAttribute="top" secondItem="SrE-iI-Nig" secondAttribute="topMargin" id="XVM-S7-3zZ"/>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="0xS-ly-xZg" secondAttribute="trailing" id="i7B-bw-v7t"/>
|
||||
<constraint firstItem="0xS-ly-xZg" firstAttribute="leading" secondItem="SrE-iI-Nig" secondAttribute="leading" id="mLn-v9-5p4"/>
|
||||
<constraint firstItem="e1H-JK-cpd" firstAttribute="leading" secondItem="SrE-iI-Nig" secondAttribute="leading" id="59O-Jd-Fai"/>
|
||||
<constraint firstAttribute="trailing" secondItem="e1H-JK-cpd" secondAttribute="trailing" id="HUb-bF-7ch"/>
|
||||
<constraint firstItem="e1H-JK-cpd" firstAttribute="centerY" secondItem="SrE-iI-Nig" secondAttribute="centerY" id="XIm-jA-fkD"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<connections>
|
||||
<outlet property="headerTitleLabel" destination="0xS-ly-xZg" id="9HL-cx-MaB"/>
|
||||
<outlet property="loadingActivityIndicator" destination="4kc-T4-2fq" id="VqP-5w-IuD"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="SubscriptionCell" rowHeight="140" id="ltf-er-wHX" customClass="SubscriptionProductTableViewCell" customModule="Earthquake_Network" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="564.5" width="320" height="140"/>
|
||||
<rect key="frame" x="0.0" y="561.5" width="320" height="140"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="ltf-er-wHX" id="ohD-ot-UaH">
|
||||
<rect key="frame" x="0.0" y="0.0" width="293" height="140"/>
|
||||
|
||||
Reference in New Issue
Block a user