Skip to content

Commit 7a15c67

Browse files
committed
use better approach for getting multiple sku details
1 parent 9910a48 commit 7a15c67

File tree

8 files changed

+22
-43
lines changed

8 files changed

+22
-43
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ As a result you will get a `SkuDetails` object with the following info included:
142142
public final String priceText;
143143
```
144144

145-
To get info for multiple products / subscriptions on one query, you can use:
145+
To get info for multiple products / subscriptions on one query, just pass a list of product ids:
146146

147147
```java
148-
bp.getMultiplePurchaseListingDetails(arrayListOfProductIds);
149-
bp.getMultipleSubscriptionListingDetails(arrayListOfProductIds);
148+
bp.getPurchaseListingDetails(arrayListOfProductIds);
149+
bp.getSubscriptionListingDetails(arrayListOfProductIds);
150150
```
151151

152152
where arrayListOfProductIds is a `ArrayList<String>` containing either IDs for products or subscriptions.

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
mavenCentral()
55
}
66
dependencies {
7-
classpath 'com.android.tools.build:gradle:1.0.0'
7+
classpath 'com.android.tools.build:gradle:1.2.3'
88
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.7.0'
99
}
1010
}

inapp-billing-v3.iml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id="inapp-billing-v3" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="java-gradle" name="Java-Gradle">
55
<configuration>
66
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
<option name="BUILDABLE" value="false" />
78
</configuration>
89
</facet>
910
</component>
@@ -15,5 +16,4 @@
1516
<orderEntry type="inheritedJdk" />
1617
<orderEntry type="sourceFolder" forTests="false" />
1718
</component>
18-
</module>
19-
19+
</module>

library/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'maven'
33
apply plugin: 'signing'
44

55
group 'com.anjlab.android.iab.v3'
6-
version '1.0.24'
6+
version '1.0.25'
77

88
android {
99
compileSdkVersion 8

library/library.iml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.anjlab.android.iab.v3" external.system.module.version="1.0.23" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.anjlab.android.iab.v3" external.system.module.version="1.0.25" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -81,5 +81,4 @@
8181
<orderEntry type="jdk" jdkName="Android API 8 Platform" jdkType="Android SDK" />
8282
<orderEntry type="sourceFolder" forTests="false" />
8383
</component>
84-
</module>
85-
84+
</module>

library/src/com/anjlab/android/iab/v3/BillingProcessor.java

+10-29
Original file line numberDiff line numberDiff line change
@@ -248,34 +248,15 @@ public boolean consumePurchase(String productId) {
248248
}
249249

250250
private SkuDetails getSkuDetails(String productId, String purchaseType) {
251-
if (billingService != null) {
252-
try {
253-
ArrayList<String> skuList = new ArrayList<String>();
254-
skuList.add(productId);
255-
Bundle products = new Bundle();
256-
products.putStringArrayList(Constants.PRODUCTS_LIST, skuList);
257-
Bundle skuDetails = billingService.getSkuDetails(Constants.GOOGLE_API_VERSION, contextPackageName, purchaseType, products);
258-
int response = skuDetails.getInt(Constants.RESPONSE_CODE);
259-
if (response == Constants.BILLING_RESPONSE_RESULT_OK) {
260-
for (String responseLine : skuDetails.getStringArrayList(Constants.DETAILS_LIST)) {
261-
JSONObject object = new JSONObject(responseLine);
262-
String responseProductId = object.getString(Constants.RESPONSE_PRODUCT_ID);
263-
if (productId.equals(responseProductId))
264-
return new SkuDetails(object);
265-
}
266-
} else {
267-
if (eventHandler != null)
268-
eventHandler.onBillingError(response, null);
269-
Log.e(LOG_TAG, String.format("Failed to retrieve info for %s: error %d", productId, response));
270-
}
271-
} catch (Exception e) {
272-
Log.e(LOG_TAG, String.format("Failed to call getSkuDetails %s", e.toString()));
273-
}
274-
}
251+
ArrayList<String> productIdList = new ArrayList<String>();
252+
productIdList.add(productId);
253+
List<SkuDetails> skuDetailsList = getSkuDetails(productIdList, purchaseType);
254+
if (skuDetailsList != null && skuDetailsList.size() > 0)
255+
return skuDetailsList.get(0);
275256
return null;
276257
}
277258

278-
private List<SkuDetails> getMultipleSkuDetails(ArrayList<String> productIdList, String purchaseType) {
259+
private List<SkuDetails> getSkuDetails(ArrayList<String> productIdList, String purchaseType) {
279260
if (billingService != null && productIdList != null && productIdList.size() > 0) {
280261
try {
281262
Bundle products = new Bundle();
@@ -313,12 +294,12 @@ public SkuDetails getSubscriptionListingDetails(String productId) {
313294
return getSkuDetails(productId, Constants.PRODUCT_TYPE_SUBSCRIPTION);
314295
}
315296

316-
public List<SkuDetails> getMultiplePurchaseListingDetails(ArrayList<String> productIdList) {
317-
return getMultipleSkuDetails(productIdList, Constants.PRODUCT_TYPE_MANAGED);
297+
public List<SkuDetails> getPurchaseListingDetails(ArrayList<String> productIdList) {
298+
return getSkuDetails(productIdList, Constants.PRODUCT_TYPE_MANAGED);
318299
}
319300

320-
public List<SkuDetails> getMultipleSubscriptionListingDetails(ArrayList<String> productIdList) {
321-
return getMultipleSkuDetails(productIdList, Constants.PRODUCT_TYPE_SUBSCRIPTION);
301+
public List<SkuDetails> getSubscriptionListingDetails(ArrayList<String> productIdList) {
302+
return getSkuDetails(productIdList, Constants.PRODUCT_TYPE_SUBSCRIPTION);
322303
}
323304

324305
public TransactionDetails getPurchaseTransactionDetails(String productId) {

sample/libs/anjlab-iabv3-current.jar

284 Bytes
Binary file not shown.

sample/sample.iml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="inapp-billing-v3" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":sample" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="inapp-billing-v3" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -81,5 +81,4 @@
8181
<orderEntry type="sourceFolder" forTests="false" />
8282
<orderEntry type="module" module-name="library" exported="" />
8383
</component>
84-
</module>
85-
84+
</module>

0 commit comments

Comments
 (0)