From 1e3e37d3ce8205827aab24026da45fcf9d038fb9 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 6 Apr 2020 08:39:52 +0200 Subject: [PATCH] Prevent crash --- .../eu/faircode/email/ActivityBilling.java | 13 ++++++++++ .../java/eu/faircode/email/FragmentPro.java | 25 +++++++++++-------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityBilling.java b/app/src/main/java/eu/faircode/email/ActivityBilling.java index 7cb7852d00..8a2e37ee2c 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBilling.java +++ b/app/src/main/java/eu/faircode/email/ActivityBilling.java @@ -29,6 +29,7 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.provider.Settings; +import android.text.TextUtils; import android.util.Base64; import android.widget.Toast; @@ -77,6 +78,7 @@ public class ActivityBilling extends ActivityBase implements PurchasesUpdatedLis static final String ACTION_PURCHASE = BuildConfig.APPLICATION_ID + ".ACTION_PURCHASE"; static final String ACTION_PURCHASE_CHECK = BuildConfig.APPLICATION_ID + ".ACTION_PURCHASE_CHECK"; + static final String ACTION_PURCHASE_ERROR = BuildConfig.APPLICATION_ID + ".ACTION_PURCHASE_ERROR"; private final static long MAX_SKU_CACHE_DURATION = 24 * 3600 * 1000L; // milliseconds private final static long MAX_SKU_NOACK_DURATION = 24 * 3600 * 1000L; // milliseconds @@ -126,6 +128,7 @@ public class ActivityBilling extends ActivityBase implements PurchasesUpdatedLis IntentFilter iff = new IntentFilter(); iff.addAction(ACTION_PURCHASE); iff.addAction(ACTION_PURCHASE_CHECK); + iff.addAction(ACTION_PURCHASE_ERROR); lbm.registerReceiver(receiver, iff); if (billingClient != null && billingClient.isReady()) @@ -202,6 +205,8 @@ public class ActivityBilling extends ActivityBase implements PurchasesUpdatedLis onPurchase(intent); else if (ACTION_PURCHASE_CHECK.equals(intent.getAction())) onPurchaseCheck(intent); + else if (ACTION_PURCHASE_ERROR.equals(intent.getAction())) + onPurchaseError(intent); } } }; @@ -243,6 +248,14 @@ public class ActivityBilling extends ActivityBase implements PurchasesUpdatedLis }); } + private void onPurchaseError(Intent intent) { + String message = intent.getStringExtra("message"); + Uri uri = Uri.parse(Helper.SUPPORT_URI); + if (!TextUtils.isEmpty(message)) + uri = uri.buildUpon().appendQueryParameter("message", "IAB: " + message).build(); + Helper.view(this, uri, true); + } + private BillingClientStateListener billingClientStateListener = new BillingClientStateListener() { private int backoff = 4; // seconds diff --git a/app/src/main/java/eu/faircode/email/FragmentPro.java b/app/src/main/java/eu/faircode/email/FragmentPro.java index 2b5ca506e8..8285f1f7fa 100644 --- a/app/src/main/java/eu/faircode/email/FragmentPro.java +++ b/app/src/main/java/eu/faircode/email/FragmentPro.java @@ -167,16 +167,21 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha } @Override - public void onError(String message) { - final Intent support = new Intent(Intent.ACTION_VIEW, Uri.parse(Helper.SUPPORT_URI)); - Snackbar snackbar = Snackbar.make(getView(), message, Snackbar.LENGTH_INDEFINITE); - if (support.resolveActivity(getContext().getPackageManager()) != null) - snackbar.setAction(R.string.title_setup_help, new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(support); - } - }); + public void onError(final String message) { + final View view = getView(); + if (view == null) + return; + + Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_INDEFINITE); + snackbar.setAction(R.string.title_setup_help, new View.OnClickListener() { + @Override + public void onClick(View view) { + LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(view.getContext()); + lbm.sendBroadcast( + new Intent(ActivityBilling.ACTION_PURCHASE_ERROR) + .putExtra("message", message)); + } + }); snackbar.show(); } });