Permalink
Browse files

Add already-owned item handling, Add missing super.onDestroy

  • Loading branch information...
1 parent 1d005b3 commit 424424914a8a8aa6d68a173008dfa4c537d109bd @skyisle committed Dec 17, 2012
@@ -234,6 +234,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
if (result.isFailure()) {
+ if (result.getResponse() == IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
+ Log.d(TAG, "already purchased item.");
+ mIsPremium = true;
+ updateUi();
+ setWaitScreen(false);
+ return;
+ }
// Oh noes!
complain("Error purchasing: " + result);
setWaitScreen(false);
@@ -299,6 +306,7 @@ public void onDriveButtonClicked(View arg0) {
// We're being destroyed. It's important to dispose of the helper here!
@Override
public void onDestroy() {
+ super.onDestroy();
// very important:
Log.d(TAG, "Destroying helper.");
if (mHelper != null) mHelper.dispose();
@@ -325,6 +325,8 @@ public void launchPurchaseFlow(Activity act, String sku, int requestCode, OnIabP
result = new IabResult(response, "Unable to buy item");
if (listener != null) listener.onIabPurchaseFinished(result, null);
+ flagEndAsync();
+ return;
}
PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
@@ -342,13 +344,15 @@ public void launchPurchaseFlow(Activity act, String sku, int requestCode, OnIabP
result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
if (listener != null) listener.onIabPurchaseFinished(result, null);
+ flagEndAsync();
}
catch (RemoteException e) {
logError("RemoteException while launching purchase flow for sku " + sku);
e.printStackTrace();
result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
if (listener != null) listener.onIabPurchaseFinished(result, null);
+ flagEndAsync();
}
}

0 comments on commit 4244249

Please sign in to comment.