|
3 | 3 | import android.app.Activity; |
4 | 4 | import android.os.Handler; |
5 | 5 | import android.os.Looper; |
6 | | -import androidx.annotation.NonNull; |
7 | 6 | import com.android.billingclient.api.*; |
8 | 7 | import com.android.billingclient.api.BillingClient.ProductType; |
9 | 8 | import com.badlogic.gdx.Gdx; |
@@ -122,14 +121,11 @@ public void onBillingServiceDisconnected() { |
122 | 121 | } |
123 | 122 |
|
124 | 123 | private void reconnectWithService() { |
125 | | - handler.postDelayed(new Runnable() { |
126 | | - @Override |
127 | | - public void run() { |
128 | | - Runnable executeOnSetupFinished = hasBillingSetupFinishedSuccessfully |
129 | | - ? null |
130 | | - : PurchaseManagerGoogleBilling.this::handleBillingSetupFinished; |
131 | | - startServiceConnection(executeOnSetupFinished); |
132 | | - } |
| 124 | + handler.postDelayed(() -> { |
| 125 | + Runnable executeOnSetupFinished = hasBillingSetupFinishedSuccessfully |
| 126 | + ? null |
| 127 | + : PurchaseManagerGoogleBilling.this::handleBillingSetupFinished; |
| 128 | + startServiceConnection(executeOnSetupFinished); |
133 | 129 | }, reconnectMilliseconds); |
134 | 130 | reconnectMilliseconds = Math.min(reconnectMilliseconds * 2, RECONNECT_TIMER_MAX_TIME_MILLISECONDS); |
135 | 131 | } |
@@ -225,9 +221,6 @@ private void queryProductDetailsForProducts(List<QueryProductDetailsParams.Produ |
225 | 221 | } |
226 | 222 |
|
227 | 223 | List<ProductDetails> productDetailsList = productDetailsResult.getProductDetailsList(); |
228 | | - if (productDetailsList == null) { |
229 | | - productDetailsList = Collections.emptyList(); |
230 | | - } |
231 | 224 |
|
232 | 225 | Gdx.app.debug(TAG, "Retrieved product count (batch " + productTypeHint + "): " + productDetailsList.size()); |
233 | 226 | for (ProductDetails productDetails : productDetailsList) { |
@@ -262,13 +255,18 @@ private Information convertProductDetailsToInformation(ProductDetails productDet |
262 | 255 | if (ProductType.SUBS.equals(productDetails.getProductType())) { |
263 | 256 | convertSubscriptionProductToInformation(builder, productDetails.getSubscriptionOfferDetails()); |
264 | 257 | } else { |
265 | | - convertOneTimeProductToInformation(builder, productDetails.getOneTimePurchaseOfferDetails()); |
| 258 | + |
| 259 | + ProductDetails.OneTimePurchaseOfferDetails details = productDetails.getOneTimePurchaseOfferDetails(); |
| 260 | + if (details != null) { |
| 261 | + convertOneTimeProductToInformation(builder, details); |
| 262 | + } |
266 | 263 | } |
267 | 264 | return builder.build(); |
268 | 265 | } |
269 | 266 |
|
270 | | - private void convertSubscriptionProductToInformation(Information.Builder builder, List<ProductDetails.SubscriptionOfferDetails> subscriptionOfferDetails) { |
271 | | - if (subscriptionOfferDetails.isEmpty()) { |
| 267 | + private void convertSubscriptionProductToInformation(Information.Builder builder, |
| 268 | + @Nullable List<ProductDetails.SubscriptionOfferDetails> subscriptionOfferDetails) { |
| 269 | + if (subscriptionOfferDetails == null || subscriptionOfferDetails.isEmpty()) { |
272 | 270 | Gdx.app.error(TAG, "Empty SubscriptionOfferDetails"); |
273 | 271 | return; |
274 | 272 | } |
@@ -340,7 +338,8 @@ private static boolean isFreeTrialSubscriptionPhase(ProductDetails.PricingPhase |
340 | 338 | (phase.getRecurrenceMode() == ProductDetails.RecurrenceMode.NON_RECURRING || phase.getRecurrenceMode() == ProductDetails.RecurrenceMode.FINITE_RECURRING); |
341 | 339 | } |
342 | 340 |
|
343 | | - private static void convertOneTimeProductToInformation(Information.Builder builder, ProductDetails.OneTimePurchaseOfferDetails oneTimePurchaseDetails) { |
| 341 | + private static void convertOneTimeProductToInformation(Information.Builder builder, @Nullable ProductDetails.OneTimePurchaseOfferDetails oneTimePurchaseDetails) { |
| 342 | + |
344 | 343 | String priceString = oneTimePurchaseDetails.getFormattedPrice(); |
345 | 344 | builder |
346 | 345 | .localPricing(priceString) |
@@ -464,17 +463,14 @@ public void purchaseRestore() { |
464 | 463 | mBillingClient.queryPurchasesAsync( |
465 | 464 | QueryPurchasesParams.newBuilder().setProductType(productType).build(), |
466 | 465 |
|
467 | | - new PurchasesResponseListener() { |
468 | | - @Override |
469 | | - public void onQueryPurchasesResponse(@Nonnull BillingResult billingResult, @Nonnull List<Purchase> list) { |
470 | | - int responseCode = billingResult.getResponseCode(); |
471 | | - if (responseCode == BillingClient.BillingResponseCode.OK) { |
472 | | - handlePurchase(list, true); |
473 | | - } else { |
474 | | - Gdx.app.error(TAG, "queryPurchases failed with responseCode " + responseCode); |
475 | | - observer.handleRestoreError(new GdxPayException("queryPurchases failed with " + |
476 | | - "responseCode " + responseCode)); |
477 | | - } |
| 466 | + (billingResult, list) -> { |
| 467 | + int responseCode = billingResult.getResponseCode(); |
| 468 | + if (responseCode == BillingClient.BillingResponseCode.OK) { |
| 469 | + handlePurchase(list, true); |
| 470 | + } else { |
| 471 | + Gdx.app.error(TAG, "queryPurchases failed with responseCode " + responseCode); |
| 472 | + observer.handleRestoreError(new GdxPayException("queryPurchases failed with " + |
| 473 | + "responseCode " + responseCode)); |
478 | 474 | } |
479 | 475 | }); |
480 | 476 | } |
@@ -542,7 +538,7 @@ private void handlePurchase(List<Purchase> purchases, boolean fromRestore) { |
542 | 538 | @Override |
543 | 539 | public void onConsumeResponse(@Nonnull BillingResult result, @Nonnull String outToken) { |
544 | 540 | if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) { |
545 | | - // handlepurchase is done before item is consumed for compatibility with other |
| 541 | + // handlePurchase is done before item is consumed for compatibility with other |
546 | 542 | // gdx-pay implementations |
547 | 543 | //TODO what to do if it did not return OK? |
548 | 544 | } |
|
0 commit comments