From a36426987dc18bc5125debe7d5da7b2e7831606f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=97=D0=B0=D1=86=D0=B5=D0=BF=D0=B8=D0=BD?= Date: Wed, 31 Jul 2019 17:03:23 +0300 Subject: [PATCH] [android] Added authorization before starting bookmarks subscription payment flow --- .../maps/base/BaseAsyncOperationFragment.java | 19 +++---- .../maps/base/BaseAuthFragment.java | 1 - .../BookmarkSubscriptionFragment.java | 50 +++++++++++++++++-- 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/android/src/com/mapswithme/maps/base/BaseAsyncOperationFragment.java b/android/src/com/mapswithme/maps/base/BaseAsyncOperationFragment.java index 526ea591d7..84b330841b 100644 --- a/android/src/com/mapswithme/maps/base/BaseAsyncOperationFragment.java +++ b/android/src/com/mapswithme/maps/base/BaseAsyncOperationFragment.java @@ -7,33 +7,34 @@ import android.support.v4.app.FragmentManager; import com.mapswithme.maps.R; import com.mapswithme.maps.dialog.ProgressDialogFragment; +import java.util.Objects; + public abstract class BaseAsyncOperationFragment extends BaseMwmFragment { private static final String PROGRESS_DIALOG_TAG = "base_progress_dialog"; - @SuppressWarnings("NullableProblems") protected void showProgress() { - int resId = getProgressDialogTitle(); + int resId = getProgressMessageId(); String title = getString(resId); ProgressDialogFragment dialog = ProgressDialogFragment.newInstance(title); - getFragmentManager() - .beginTransaction() - .add(dialog, PROGRESS_DIALOG_TAG) - .commitAllowingStateLoss(); + Objects.requireNonNull(getFragmentManager()) + .beginTransaction() + .add(dialog, PROGRESS_DIALOG_TAG) + .commitAllowingStateLoss(); } @StringRes - protected int getProgressDialogTitle() + protected int getProgressMessageId() { return R.string.downloading; } - @SuppressWarnings("NullableProblems") protected void hideProgress() { FragmentManager fm = getFragmentManager(); - DialogFragment frag = (DialogFragment) fm.findFragmentByTag(PROGRESS_DIALOG_TAG); + DialogFragment frag = (DialogFragment) Objects.requireNonNull(fm) + .findFragmentByTag(PROGRESS_DIALOG_TAG); if (frag != null) frag.dismissAllowingStateLoss(); } diff --git a/android/src/com/mapswithme/maps/base/BaseAuthFragment.java b/android/src/com/mapswithme/maps/base/BaseAuthFragment.java index f68800150a..5de2a95309 100644 --- a/android/src/com/mapswithme/maps/base/BaseAuthFragment.java +++ b/android/src/com/mapswithme/maps/base/BaseAuthFragment.java @@ -1,6 +1,5 @@ package com.mapswithme.maps.base; -import android.content.Context; import android.content.Intent; import android.support.annotation.CallSuper; import android.support.annotation.NonNull; diff --git a/android/src/com/mapswithme/maps/purchase/BookmarkSubscriptionFragment.java b/android/src/com/mapswithme/maps/purchase/BookmarkSubscriptionFragment.java index 66cf7b9500..dcc5b0ae9a 100644 --- a/android/src/com/mapswithme/maps/purchase/BookmarkSubscriptionFragment.java +++ b/android/src/com/mapswithme/maps/purchase/BookmarkSubscriptionFragment.java @@ -9,11 +9,13 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import android.widget.Toast; import com.android.billingclient.api.SkuDetails; +import com.mapswithme.maps.Framework; import com.mapswithme.maps.PrivateVariables; import com.mapswithme.maps.R; -import com.mapswithme.maps.base.BaseMwmFragment; +import com.mapswithme.maps.base.BaseAuthFragment; import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.dialog.AlertDialogCallback; import com.mapswithme.util.Utils; @@ -24,7 +26,7 @@ import com.mapswithme.util.statistics.Statistics; import java.util.Collections; import java.util.List; -public class BookmarkSubscriptionFragment extends BaseMwmFragment +public class BookmarkSubscriptionFragment extends BaseAuthFragment implements AlertDialogCallback, PurchaseStateActivator { private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.BILLING); @@ -249,13 +251,13 @@ public class BookmarkSubscriptionFragment extends BaseMwmFragment public void finishPinging() { - if (mPingingResult) + if (!mPingingResult) { - launchPurchaseFlow(); + PurchaseUtils.showPingFailureDialog(this); return; } - PurchaseUtils.showPingFailureDialog(this); + authorize(); } @Override @@ -275,6 +277,44 @@ public class BookmarkSubscriptionFragment extends BaseMwmFragment mPurchaseController.launchPurchaseFlow(details.getProductId()); } + @Override + protected int getProgressMessageId() + { + return R.string.please_wait; + } + + @Override + public void onAuthorizationFinish(boolean success) + { + hideProgress(); + if (!success) + { + Toast.makeText(requireContext(), R.string.profile_authorization_error, Toast.LENGTH_LONG) + .show(); + return; + } + + launchPurchaseFlow(); + } + + @Override + public void onAuthorizationStart() + { + showProgress(); + } + + @Override + public void onSocialAuthenticationCancel(@Framework.AuthTokenType int type) + { + LOGGER.i(TAG, "Social authentication cancelled, auth type = " + type); + } + + @Override + public void onSocialAuthenticationError(@Framework.AuthTokenType int type, @Nullable String error) + { + LOGGER.w(TAG, "Social authentication error = " + error + ", auth type = " + type); + } + private class AnnualCardClickListener implements View.OnClickListener { @NonNull