Skip to content

Commit

Permalink
use better approach for getting multiple sku details
Browse files Browse the repository at this point in the history
  • Loading branch information
serggl committed Jun 2, 2015
1 parent 9910a48 commit 7a15c67
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 43 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ As a result you will get a `SkuDetails` object with the following info included:
public final String priceText;
```

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

```java
bp.getMultiplePurchaseListingDetails(arrayListOfProductIds);
bp.getMultipleSubscriptionListingDetails(arrayListOfProductIds);
bp.getPurchaseListingDetails(arrayListOfProductIds);
bp.getSubscriptionListingDetails(arrayListOfProductIds);
```

where arrayListOfProductIds is a `ArrayList<String>` containing either IDs for products or subscriptions.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.7.0'
}
}
Expand Down
6 changes: 3 additions & 3 deletions inapp-billing-v3.iml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
Expand All @@ -15,5 +16,4 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

</module>
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'maven'
apply plugin: 'signing'

group 'com.anjlab.android.iab.v3'
version '1.0.24'
version '1.0.25'

android {
compileSdkVersion 8
Expand Down
5 changes: 2 additions & 3 deletions library/library.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -81,5 +81,4 @@
<orderEntry type="jdk" jdkName="Android API 8 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

</module>
39 changes: 10 additions & 29 deletions library/src/com/anjlab/android/iab/v3/BillingProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,34 +248,15 @@ public boolean consumePurchase(String productId) {
}

private SkuDetails getSkuDetails(String productId, String purchaseType) {
if (billingService != null) {
try {
ArrayList<String> skuList = new ArrayList<String>();
skuList.add(productId);
Bundle products = new Bundle();
products.putStringArrayList(Constants.PRODUCTS_LIST, skuList);
Bundle skuDetails = billingService.getSkuDetails(Constants.GOOGLE_API_VERSION, contextPackageName, purchaseType, products);
int response = skuDetails.getInt(Constants.RESPONSE_CODE);
if (response == Constants.BILLING_RESPONSE_RESULT_OK) {
for (String responseLine : skuDetails.getStringArrayList(Constants.DETAILS_LIST)) {
JSONObject object = new JSONObject(responseLine);
String responseProductId = object.getString(Constants.RESPONSE_PRODUCT_ID);
if (productId.equals(responseProductId))
return new SkuDetails(object);
}
} else {
if (eventHandler != null)
eventHandler.onBillingError(response, null);
Log.e(LOG_TAG, String.format("Failed to retrieve info for %s: error %d", productId, response));
}
} catch (Exception e) {
Log.e(LOG_TAG, String.format("Failed to call getSkuDetails %s", e.toString()));
}
}
ArrayList<String> productIdList = new ArrayList<String>();
productIdList.add(productId);
List<SkuDetails> skuDetailsList = getSkuDetails(productIdList, purchaseType);
if (skuDetailsList != null && skuDetailsList.size() > 0)
return skuDetailsList.get(0);
return null;
}

private List<SkuDetails> getMultipleSkuDetails(ArrayList<String> productIdList, String purchaseType) {
private List<SkuDetails> getSkuDetails(ArrayList<String> productIdList, String purchaseType) {
if (billingService != null && productIdList != null && productIdList.size() > 0) {
try {
Bundle products = new Bundle();
Expand Down Expand Up @@ -313,12 +294,12 @@ public SkuDetails getSubscriptionListingDetails(String productId) {
return getSkuDetails(productId, Constants.PRODUCT_TYPE_SUBSCRIPTION);
}

public List<SkuDetails> getMultiplePurchaseListingDetails(ArrayList<String> productIdList) {
return getMultipleSkuDetails(productIdList, Constants.PRODUCT_TYPE_MANAGED);
public List<SkuDetails> getPurchaseListingDetails(ArrayList<String> productIdList) {
return getSkuDetails(productIdList, Constants.PRODUCT_TYPE_MANAGED);
}

public List<SkuDetails> getMultipleSubscriptionListingDetails(ArrayList<String> productIdList) {
return getMultipleSkuDetails(productIdList, Constants.PRODUCT_TYPE_SUBSCRIPTION);
public List<SkuDetails> getSubscriptionListingDetails(ArrayList<String> productIdList) {
return getSkuDetails(productIdList, Constants.PRODUCT_TYPE_SUBSCRIPTION);
}

public TransactionDetails getPurchaseTransactionDetails(String productId) {
Expand Down
Binary file modified sample/libs/anjlab-iabv3-current.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions sample/sample.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -81,5 +81,4 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="library" exported="" />
</component>
</module>

</module>

0 comments on commit 7a15c67

Please sign in to comment.