Small refactoring
This commit is contained in:
parent
82f2138c07
commit
6efb6f27b3
2 changed files with 10 additions and 41 deletions
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.billingclient.api.AccountIdentifiers;
|
||||
import com.android.billingclient.api.BillingClient;
|
||||
import com.android.billingclient.api.BillingResult;
|
||||
import com.android.billingclient.api.Purchase;
|
||||
|
@ -200,7 +199,6 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
|
|||
|
||||
BillingManager billingManager = getBillingManager();
|
||||
if (billingManager != null) {
|
||||
setupUserInfo(billingManager);
|
||||
billingManager.initiatePurchaseFlow(activity, skuDetails);
|
||||
} else {
|
||||
throw new IllegalStateException("BillingManager disposed");
|
||||
|
@ -228,7 +226,6 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
|
|||
}
|
||||
BillingManager billingManager = getBillingManager();
|
||||
if (billingManager != null) {
|
||||
setupUserInfo(billingManager);
|
||||
billingManager.initiatePurchaseFlow(activity, skuDetails);
|
||||
} else {
|
||||
throw new IllegalStateException("BillingManager disposed");
|
||||
|
@ -462,43 +459,27 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
|
|||
};
|
||||
|
||||
private void restoreUserInfo(OsmandSettings settings, Purchase purchase) {
|
||||
boolean restored = restoreUserInfoUsingPayload(settings, purchase);
|
||||
boolean restored = restoreUserInfoFromString(settings, purchase.getDeveloperPayload());
|
||||
if (!restored) {
|
||||
restoreUserInfoUsingAccountIdentifiers(settings, purchase);
|
||||
restoreUserInfoFromString(settings, purchase.getAccountIdentifiers().getObfuscatedAccountId());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean restoreUserInfoUsingPayload(OsmandSettings settings, Purchase purchase) {
|
||||
String payload = purchase.getDeveloperPayload();
|
||||
if (Algorithms.isEmpty(payload)) {
|
||||
private boolean restoreUserInfoFromString(OsmandSettings settings, String userInfo) {
|
||||
if (Algorithms.isEmpty(userInfo)) {
|
||||
return false;
|
||||
}
|
||||
String[] arr = payload.split(" ");
|
||||
if (arr.length > 0) {
|
||||
String[] arr = userInfo.split(" ");
|
||||
if (arr.length > 0 && !Algorithms.isEmpty(settings.BILLING_USER_ID.get())) {
|
||||
settings.BILLING_USER_ID.set(arr[0]);
|
||||
}
|
||||
if (arr.length > 1) {
|
||||
if (arr.length > 1 && !Algorithms.isEmpty(settings.BILLING_USER_TOKEN.get())) {
|
||||
token = arr[1];
|
||||
settings.BILLING_USER_TOKEN.set(token);
|
||||
}
|
||||
return needRestoreUserInfo(settings);
|
||||
}
|
||||
|
||||
private void restoreUserInfoUsingAccountIdentifiers(OsmandSettings settings, Purchase purchase) {
|
||||
AccountIdentifiers accountInfo = purchase.getAccountIdentifiers();
|
||||
if (accountInfo != null) {
|
||||
String userId = accountInfo.getObfuscatedAccountId();
|
||||
String userToken = accountInfo.getObfuscatedProfileId();
|
||||
if (Algorithms.isEmpty(settings.BILLING_USER_ID.get()) && !Algorithms.isEmpty(userId)) {
|
||||
settings.BILLING_USER_ID.set(userId);
|
||||
}
|
||||
if (Algorithms.isEmpty(settings.BILLING_USER_TOKEN.get()) && !Algorithms.isEmpty(userToken)) {
|
||||
token = userToken;
|
||||
settings.BILLING_USER_TOKEN.set(userToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean needRestoreUserInfo(OsmandSettings settings) {
|
||||
return Algorithms.isEmpty(settings.BILLING_USER_ID.get()) || Algorithms.isEmpty(settings.BILLING_USER_TOKEN.get());
|
||||
}
|
||||
|
@ -568,7 +549,9 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
|
|||
if (AndroidUtils.isActivityNotDestroyed(a) && skuDetails != null) {
|
||||
BillingManager billingManager = getBillingManager();
|
||||
if (billingManager != null) {
|
||||
setupUserInfo(billingManager);
|
||||
OsmandSettings settings = ctx.getSettings();
|
||||
String userCredential = settings.BILLING_USER_ID.get() + settings.BILLING_USER_TOKEN.get();
|
||||
billingManager.setObfuscatedAccountId(userCredential);
|
||||
billingManager.initiatePurchaseFlow(a, skuDetails);
|
||||
} else {
|
||||
throw new IllegalStateException("BillingManager disposed");
|
||||
|
@ -620,12 +603,6 @@ public class InAppPurchaseHelperImpl extends InAppPurchaseHelper {
|
|||
onPurchaseDone(getPurchaseInfo(purchase));
|
||||
}
|
||||
|
||||
private void setupUserInfo(BillingManager billingManager) {
|
||||
OsmandSettings settings = ctx.getSettings();
|
||||
billingManager.setObfuscatedAccountId(settings.BILLING_USER_ID.get());
|
||||
billingManager.setObfuscatedProfileId(settings.BILLING_USER_TOKEN.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isBillingManagerExists() {
|
||||
return getBillingManager() != null;
|
||||
|
|
|
@ -59,7 +59,6 @@ public class BillingManager implements PurchasesUpdatedListener {
|
|||
// Public key for verifying signature, in base64 encoding
|
||||
private String mSignatureBase64;
|
||||
private String mObfuscatedAccountId;
|
||||
private String mObfuscatedProfileId;
|
||||
|
||||
private final BillingUpdatesListener mBillingUpdatesListener;
|
||||
private final List<Purchase> mPurchases = new ArrayList<>();
|
||||
|
@ -152,9 +151,6 @@ public class BillingManager implements PurchasesUpdatedListener {
|
|||
if (!TextUtils.isEmpty(mObfuscatedAccountId)) {
|
||||
paramsBuilder.setObfuscatedAccountId(mObfuscatedAccountId);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mObfuscatedProfileId)) {
|
||||
paramsBuilder.setObfuscatedProfileId(mObfuscatedProfileId);
|
||||
}
|
||||
if (oldSku != null && purchaseToken != null) {
|
||||
paramsBuilder.setOldSku(oldSku, purchaseToken);
|
||||
}
|
||||
|
@ -409,10 +405,6 @@ public class BillingManager implements PurchasesUpdatedListener {
|
|||
mObfuscatedAccountId = obfuscatedAccountId;
|
||||
}
|
||||
|
||||
public void setObfuscatedProfileId(String obfuscatedProfileId) {
|
||||
mObfuscatedProfileId = obfuscatedProfileId;
|
||||
}
|
||||
|
||||
private void executeServiceRequest(Runnable runnable) {
|
||||
if (mIsServiceConnected) {
|
||||
runnable.run();
|
||||
|
|
Loading…
Reference in a new issue