Remove Osmand code from class
This commit is contained in:
parent
9da63447c1
commit
83bd81eea7
2 changed files with 27 additions and 10 deletions
|
@ -200,6 +200,7 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
|
|||
|
||||
BillingManager billingManager = getBillingManager();
|
||||
if (billingManager != null) {
|
||||
storeUserInfo(billingManager);
|
||||
billingManager.initiatePurchaseFlow(activity, skuDetails);
|
||||
} else {
|
||||
throw new IllegalStateException("BillingManager disposed");
|
||||
|
@ -227,6 +228,7 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
|
|||
}
|
||||
BillingManager billingManager = getBillingManager();
|
||||
if (billingManager != null) {
|
||||
storeUserInfo(billingManager);
|
||||
billingManager.initiatePurchaseFlow(activity, skuDetails);
|
||||
} else {
|
||||
throw new IllegalStateException("BillingManager disposed");
|
||||
|
@ -566,6 +568,7 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
|
|||
if (AndroidUtils.isActivityNotDestroyed(a) && skuDetails != null) {
|
||||
BillingManager billingManager = getBillingManager();
|
||||
if (billingManager != null) {
|
||||
storeUserInfo(billingManager);
|
||||
billingManager.initiatePurchaseFlow(a, skuDetails);
|
||||
} else {
|
||||
throw new IllegalStateException("BillingManager disposed");
|
||||
|
@ -617,6 +620,12 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
|
|||
onPurchaseDone(getPurchaseInfo(purchase));
|
||||
}
|
||||
|
||||
private void storeUserInfo(BillingManager billingManager) {
|
||||
OsmandSettings settings = ctx.getSettings();
|
||||
billingManager.setUserId(settings.BILLING_USER_ID.get());
|
||||
billingManager.setUserToken(settings.BILLING_USER_TOKEN.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isBillingManagerExists() {
|
||||
return getBillingManager() != null;
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.inapp.util;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.billingclient.api.AcknowledgePurchaseParams;
|
||||
import com.android.billingclient.api.AcknowledgePurchaseResponseListener;
|
||||
|
@ -22,8 +23,6 @@ import com.android.billingclient.api.SkuDetailsParams;
|
|||
import com.android.billingclient.api.SkuDetailsResponseListener;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -59,6 +58,8 @@ public class BillingManager implements PurchasesUpdatedListener {
|
|||
|
||||
// Public key for verifying signature, in base64 encoding
|
||||
private String mSignatureBase64;
|
||||
private String mUserId;
|
||||
private String mUserToken;
|
||||
|
||||
private final BillingUpdatesListener mBillingUpdatesListener;
|
||||
private final List<Purchase> mPurchases = new ArrayList<>();
|
||||
|
@ -146,11 +147,14 @@ public class BillingManager implements PurchasesUpdatedListener {
|
|||
@Override
|
||||
public void run() {
|
||||
LOG.debug("Launching in-app purchase flow. Replace old SKU? " + (oldSku != null && purchaseToken != null));
|
||||
OsmandSettings settings = getSettings(activity);
|
||||
BillingFlowParams.Builder paramsBuilder = BillingFlowParams.newBuilder()
|
||||
.setSkuDetails(skuDetails)
|
||||
.setObfuscatedAccountId(settings.BILLING_USER_ID.get())
|
||||
.setObfuscatedProfileId(settings.BILLING_USER_TOKEN.get());
|
||||
.setSkuDetails(skuDetails);
|
||||
if (!TextUtils.isEmpty(mUserId)) {
|
||||
paramsBuilder.setObfuscatedAccountId(mUserId);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mUserToken)) {
|
||||
paramsBuilder.setObfuscatedProfileId(mUserToken);
|
||||
}
|
||||
if (oldSku != null && purchaseToken != null) {
|
||||
paramsBuilder.setOldSku(oldSku, purchaseToken);
|
||||
}
|
||||
|
@ -401,6 +405,14 @@ public class BillingManager implements PurchasesUpdatedListener {
|
|||
});
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
mUserId = userId;
|
||||
}
|
||||
|
||||
public void setUserToken(String userToken) {
|
||||
mUserToken = userToken;
|
||||
}
|
||||
|
||||
private void executeServiceRequest(Runnable runnable) {
|
||||
if (mIsServiceConnected) {
|
||||
runnable.run();
|
||||
|
@ -413,10 +425,6 @@ public class BillingManager implements PurchasesUpdatedListener {
|
|||
private boolean verifyValidSignature(String signedData, String signature) {
|
||||
return Security.verifyPurchase(mSignatureBase64, signedData, signature);
|
||||
}
|
||||
|
||||
private OsmandSettings getSettings(Activity activity) {
|
||||
return ((OsmandApplication) activity.getApplication()).getSettings();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue