Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60b09134 authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Fixed DonationManager crash

parent 11537c72
Loading
Loading
Loading
Loading
+61 −70
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ import android.widget.Toast;
import com.moez.QKSMS.R;
import com.moez.QKSMS.external.iab.IabHelper;
import com.moez.QKSMS.external.iab.IabResult;
import com.moez.QKSMS.external.iab.Inventory;
import com.moez.QKSMS.external.iab.Purchase;
import com.moez.QKSMS.ui.base.QKActivity;
import com.moez.QKSMS.ui.dialog.QKDialog;
@@ -37,6 +36,8 @@ public class DonationManager {
    public static DonationManager getInstance(QKActivity context) {
        if (sInstance == null) {
            sInstance = new DonationManager(context);
        } else {
            sInstance.mContext = context; // Update the context, in case the previous context was destroyed
        }

        return sInstance;
@@ -56,10 +57,7 @@ public class DonationManager {
        // Create the helper, passing it our context and the public key to verify signatures with
        mHelper = new IabHelper(mContext, PUBLIC_KEY);

        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {

            @Override
            public void onIabSetupFinished(IabResult result) {
        mHelper.startSetup(result -> {
            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) {
                return;
@@ -76,7 +74,6 @@ public class DonationManager {

            // IAB is fully set up. Now, let's get an inventory of stuff we own.
            mHelper.queryInventoryAsync(iabInventoryListener());
            }
        });
    }

@@ -119,9 +116,7 @@ public class DonationManager {
     * Listener that's called when we finish querying the items and subscriptions we own
     */
    private IabHelper.QueryInventoryFinishedListener iabInventoryListener() {
        return new IabHelper.QueryInventoryFinishedListener() {
            @Override
            public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
        return (result, inventory) -> {
            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) {
                return;
@@ -160,7 +155,6 @@ public class DonationManager {
            if (inventory.hasPurchase(SKU_DONATE_10)) {
                mHelper.consumeAsync(inventory.getPurchase(SKU_DONATE_10), onConsumeFinishedListener);
            }
            }
        };
    }

@@ -180,9 +174,7 @@ public class DonationManager {

    public void showDonateDialog() {

        View.OnClickListener clickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
        View.OnClickListener clickListener = view -> {
            switch (view.getId()) {
                case R.id.donate_1:
                    onDonateButtonClicked(SKU_DONATE_1);
@@ -197,7 +189,6 @@ public class DonationManager {
                    donatePaypal();
                    break;
            }
            }
        };

        View view = mContext.getLayoutInflater().inflate(R.layout.dialog_donate, null);