Skip to content

Commit 3978045

Browse files
author
Kees van Dieren
committed
Add jenv file, code cleanup
1 parent 69058e0 commit 3978045

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

.java-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11

gdx-pay-android-googlebilling/src/com/badlogic/gdx/pay/android/googlebilling/PurchaseManagerGoogleBilling.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.app.Activity;
44
import android.os.Handler;
55
import android.os.Looper;
6-
import androidx.annotation.NonNull;
76
import com.android.billingclient.api.*;
87
import com.android.billingclient.api.BillingClient.ProductType;
98
import com.badlogic.gdx.Gdx;
@@ -122,14 +121,11 @@ public void onBillingServiceDisconnected() {
122121
}
123122

124123
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);
133129
}, reconnectMilliseconds);
134130
reconnectMilliseconds = Math.min(reconnectMilliseconds * 2, RECONNECT_TIMER_MAX_TIME_MILLISECONDS);
135131
}
@@ -225,9 +221,6 @@ private void queryProductDetailsForProducts(List<QueryProductDetailsParams.Produ
225221
}
226222

227223
List<ProductDetails> productDetailsList = productDetailsResult.getProductDetailsList();
228-
if (productDetailsList == null) {
229-
productDetailsList = Collections.emptyList();
230-
}
231224

232225
Gdx.app.debug(TAG, "Retrieved product count (batch " + productTypeHint + "): " + productDetailsList.size());
233226
for (ProductDetails productDetails : productDetailsList) {
@@ -262,13 +255,18 @@ private Information convertProductDetailsToInformation(ProductDetails productDet
262255
if (ProductType.SUBS.equals(productDetails.getProductType())) {
263256
convertSubscriptionProductToInformation(builder, productDetails.getSubscriptionOfferDetails());
264257
} else {
265-
convertOneTimeProductToInformation(builder, productDetails.getOneTimePurchaseOfferDetails());
258+
259+
ProductDetails.OneTimePurchaseOfferDetails details = productDetails.getOneTimePurchaseOfferDetails();
260+
if (details != null) {
261+
convertOneTimeProductToInformation(builder, details);
262+
}
266263
}
267264
return builder.build();
268265
}
269266

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()) {
272270
Gdx.app.error(TAG, "Empty SubscriptionOfferDetails");
273271
return;
274272
}
@@ -340,7 +338,8 @@ private static boolean isFreeTrialSubscriptionPhase(ProductDetails.PricingPhase
340338
(phase.getRecurrenceMode() == ProductDetails.RecurrenceMode.NON_RECURRING || phase.getRecurrenceMode() == ProductDetails.RecurrenceMode.FINITE_RECURRING);
341339
}
342340

343-
private static void convertOneTimeProductToInformation(Information.Builder builder, ProductDetails.OneTimePurchaseOfferDetails oneTimePurchaseDetails) {
341+
private static void convertOneTimeProductToInformation(Information.Builder builder, @Nullable ProductDetails.OneTimePurchaseOfferDetails oneTimePurchaseDetails) {
342+
344343
String priceString = oneTimePurchaseDetails.getFormattedPrice();
345344
builder
346345
.localPricing(priceString)
@@ -464,17 +463,14 @@ public void purchaseRestore() {
464463
mBillingClient.queryPurchasesAsync(
465464
QueryPurchasesParams.newBuilder().setProductType(productType).build(),
466465

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));
478474
}
479475
});
480476
}
@@ -542,7 +538,7 @@ private void handlePurchase(List<Purchase> purchases, boolean fromRestore) {
542538
@Override
543539
public void onConsumeResponse(@Nonnull BillingResult result, @Nonnull String outToken) {
544540
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
546542
// gdx-pay implementations
547543
//TODO what to do if it did not return OK?
548544
}

0 commit comments

Comments
 (0)