Request inventory on start only

This commit is contained in:
max-klaus 2020-09-15 18:12:29 +03:00
parent bf59a702e5
commit 485368d262

View file

@ -63,6 +63,7 @@ public class InAppPurchaseHelper {
private InAppPurchases purchases; private InAppPurchases purchases;
private long lastValidationCheckTime; private long lastValidationCheckTime;
private boolean inventoryRequested;
private static final long PURCHASE_VALIDATION_PERIOD_MSEC = 1000 * 60 * 60 * 24; // daily private static final long PURCHASE_VALIDATION_PERIOD_MSEC = 1000 * 60 * 60 * 24; // daily
// (arbitrary) request code for the purchase flow // (arbitrary) request code for the purchase flow
@ -333,8 +334,8 @@ public class InAppPurchaseHelper {
} }
public boolean needRequestInventory() { public boolean needRequestInventory() {
return (isSubscribedToLiveUpdates(ctx) && Algorithms.isEmpty(ctx.getSettings().BILLING_PURCHASE_TOKENS_SENT.get())) return !inventoryRequested && ((isSubscribedToLiveUpdates(ctx) && Algorithms.isEmpty(ctx.getSettings().BILLING_PURCHASE_TOKENS_SENT.get()))
|| System.currentTimeMillis() - lastValidationCheckTime > PURCHASE_VALIDATION_PERIOD_MSEC; || System.currentTimeMillis() - lastValidationCheckTime > PURCHASE_VALIDATION_PERIOD_MSEC);
} }
public void requestInventory() { public void requestInventory() {
@ -803,6 +804,7 @@ public class InAppPurchaseHelper {
protected void onPostExecute(String response) { protected void onPostExecute(String response) {
logDebug("Response=" + response); logDebug("Response=" + response);
if (response != null) { if (response != null) {
inventoryRequested = true;
try { try {
JSONObject obj = new JSONObject(response); JSONObject obj = new JSONObject(response);
JSONArray names = obj.names(); JSONArray names = obj.names();