in ClassyTaxiJava/app/src/main/java/com/sample/android/classytaxijava/data/DataRepository.java [161:203]
public void updateSubscriptionsFromNetwork(
@Nullable List<SubscriptionStatus> remoteSubscriptions) {
List<SubscriptionStatus> oldSubscriptions = subscriptions.getValue();
List<Purchase> purchases = billingClientLifecycle.purchases.getValue();
List<SubscriptionStatus> subscriptions =
mergeSubscriptionsAndPurchases(oldSubscriptions, remoteSubscriptions, purchases);
if (remoteSubscriptions != null) {
acknowledgeRegisteredPurchaseTokens(remoteSubscriptions);
}
// Store the subscription information when it changes.
localDataSource.updateSubscriptions(subscriptions);
// Update the content when the subscription changes.
if (remoteSubscriptions != null) {
// Figure out which content we need to fetch.
boolean updateBasic = false;
boolean updatePremium = false;
for (SubscriptionStatus subscription : remoteSubscriptions) {
if (Constants.BASIC_SKU.equals(subscription.getSku())) {
updateBasic = true;
} else {
// Premium subscribers get access to basic content as well.
updateBasic = true;
updatePremium = true;
}
}
if (updateBasic) {
// Fetch the basic content.
webDataSource.updateBasicContent();
} else {
// If we no longer own this content, clear it from the UI.
basicContent.postValue(null);
}
if (updatePremium) {
// Fetch the premium content.
webDataSource.updatePremiumContent();
} else {
// If we no longer own this content, clear it from the UI.
premiumContent.postValue(null);
}
}
}