Skip to content

Commit

Permalink
fix in-app purchases
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Taschauer committed May 30, 2020
1 parent a03779b commit 574c847
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion OpenDocument.core
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
package="at.tomtasche.reader"
android:installLocation="auto"
android:versionCode="131"
android:versionName="3.3.1"
android:versionCode="132"
android:versionName="3.3.2"
tools:ignore="GoogleAppIndexingWarning">

<uses-permission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public boolean hasPurchased() {
return false;
}

return sharedPreferences.getBoolean("purchased", false);
return sharedPreferences.getBoolean("purchaseAcknowledged", false);
}

public void setPurchased(boolean purchased) {
Expand All @@ -27,7 +27,7 @@ public void setPurchased(boolean purchased) {
}

Editor editor = sharedPreferences.edit();
editor.putBoolean("purchased", purchased);
editor.putBoolean("purchaseAcknowledged", purchased);
editor.apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.content.Context;

import com.android.billingclient.api.AcknowledgePurchaseParams;
import com.android.billingclient.api.AcknowledgePurchaseResponseListener;
import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingFlowParams;
Expand Down Expand Up @@ -118,8 +120,29 @@ private void refreshPurchased() {
return;
}

boolean hasPurchased = false;

Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
boolean hasPurchased = purchasesResult != null && purchasesResult.getPurchasesList() != null && !purchasesResult.getPurchasesList().isEmpty();
if (purchasesResult.getPurchasesList() != null) {
for (Purchase purchase : purchasesResult.getPurchasesList()) {
if (!purchase.isAcknowledged()) {
AcknowledgePurchaseParams.Builder builder = AcknowledgePurchaseParams.newBuilder();
builder.setPurchaseToken(purchase.getPurchaseToken());

billingClient.acknowledgePurchase(builder.build(), new AcknowledgePurchaseResponseListener() {
@Override
public void onAcknowledgePurchaseResponse(BillingResult billingResult) {
// TODO: in the best case we would set hasPurchased to true only now. not worth the effort in my opinion
}
});
}

hasPurchased = true;

break;
}
}

billingPreferences.setPurchased(hasPurchased);
}

Expand Down

0 comments on commit 574c847

Please sign in to comment.