From 21235af0c4e40c2f8ec7ac7633f8c7cfc4bade1e 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: Thu, 9 Jul 2020 20:11:28 +0300 Subject: [PATCH] [android] Added 'View on map' button redirect handling in catalog webview [android] Fixed crash during the launch subscription activity from the 'yes, renew' button in invalid dialog --- .../bookmarks/BookmarksCatalogFragment.java | 43 ++++++++++++++++--- ...nvalidSubscriptionAlertDialogCallback.java | 7 ++- .../BookmarkSubscriptionFragment.java | 2 +- .../maps/purchase/PurchaseUtils.java | 19 ++++---- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarksCatalogFragment.java b/android/src/com/mapswithme/maps/bookmarks/BookmarksCatalogFragment.java index 74e18cfded..43cd8f4dce 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarksCatalogFragment.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarksCatalogFragment.java @@ -31,6 +31,7 @@ import com.mapswithme.maps.PrivateVariables; import com.mapswithme.maps.R; import com.mapswithme.maps.auth.BaseWebViewMwmFragment; import com.mapswithme.maps.auth.TargetFragmentCallback; +import com.mapswithme.maps.bookmarks.data.BookmarkCategory; import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.dialog.AlertDialog; import com.mapswithme.maps.dialog.AlertDialogCallback; @@ -354,6 +355,7 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment private static class WebViewBookmarksCatalogClient extends WebViewClient { private static final String SUBSCRIBE_PATH_SEGMENT = "subscribe"; + private static final String VIEW_ON_MAP_SEGMENT = "map"; private final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.BILLING); private final String TAG = WebViewBookmarksCatalogClient.class.getSimpleName(); @@ -382,15 +384,46 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment for (String each : pathSegments) { if (TextUtils.equals(each, SUBSCRIBE_PATH_SEGMENT)) - { - String group = PurchaseUtils.getTargetBookmarkGroupFromUri(uri); - openSubscriptionScreen(SubscriptionType.getTypeByBookmarksGroup(group)); - return true; - } + return handleSubscriptionUri(uri); + + if (TextUtils.equals(each, VIEW_ON_MAP_SEGMENT)) + return handleViewOnMapUri(fragment, uri); } + return result; } + private Boolean handleViewOnMapUri(@NonNull BookmarksCatalogFragment fragment, @NonNull Uri uri) + { + String serverId = uri.getQueryParameter(PurchaseUtils.SERVER_ID); + if (TextUtils.isEmpty(serverId)) + return false; + + BookmarkCategory category; + try + { + category = BookmarkManager.INSTANCE.getCategoryByServerId(serverId); + } + catch (Throwable e) + { + CrashlyticsUtils.logException(e); + return false; + } + + Intent intent = new Intent().putExtra(BookmarksCatalogActivity.EXTRA_DOWNLOADED_CATEGORY, + category); + fragment.requireActivity().setResult(Activity.RESULT_OK, intent); + fragment.requireActivity().finish(); + return true; + } + + private boolean handleSubscriptionUri(@NonNull Uri uri) + { + String group = PurchaseUtils.getTargetBookmarkGroupFromUri(uri); + openSubscriptionScreen(SubscriptionType.getTypeByBookmarksGroup(group)); + return true; + } + private void openSubscriptionScreen(@NonNull SubscriptionType type) { BookmarksCatalogFragment frag = mReference.get(); diff --git a/android/src/com/mapswithme/maps/bookmarks/InvalidSubscriptionAlertDialogCallback.java b/android/src/com/mapswithme/maps/bookmarks/InvalidSubscriptionAlertDialogCallback.java index 7f07d7bb41..659027e144 100644 --- a/android/src/com/mapswithme/maps/bookmarks/InvalidSubscriptionAlertDialogCallback.java +++ b/android/src/com/mapswithme/maps/bookmarks/InvalidSubscriptionAlertDialogCallback.java @@ -2,10 +2,9 @@ package com.mapswithme.maps.bookmarks; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; - import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.dialog.AlertDialogCallback; -import com.mapswithme.maps.purchase.BookmarkSubscriptionActivity; +import com.mapswithme.maps.purchase.BookmarksAllSubscriptionActivity; import com.mapswithme.maps.purchase.PurchaseUtils; import com.mapswithme.util.log.Logger; import com.mapswithme.util.log.LoggerFactory; @@ -24,8 +23,8 @@ class InvalidSubscriptionAlertDialogCallback implements AlertDialogCallback @Override public void onAlertDialogPositiveClick(int requestCode, int which) { - BookmarkSubscriptionActivity.startForResult(mFragment, PurchaseUtils.REQ_CODE_PAY_CONTINUE_SUBSCRIPTION, - Statistics.ParamValue.POPUP); + BookmarksAllSubscriptionActivity.startForResult(mFragment, PurchaseUtils.REQ_CODE_PAY_CONTINUE_SUBSCRIPTION, + Statistics.ParamValue.POPUP); } @Override diff --git a/android/src/com/mapswithme/maps/purchase/BookmarkSubscriptionFragment.java b/android/src/com/mapswithme/maps/purchase/BookmarkSubscriptionFragment.java index b624a14198..acd678543a 100644 --- a/android/src/com/mapswithme/maps/purchase/BookmarkSubscriptionFragment.java +++ b/android/src/com/mapswithme/maps/purchase/BookmarkSubscriptionFragment.java @@ -9,7 +9,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.mapswithme.maps.R; -class BookmarkSubscriptionFragment extends AbstractBookmarkSubscriptionFragment +public class BookmarkSubscriptionFragment extends AbstractBookmarkSubscriptionFragment { @Nullable @Override diff --git a/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java b/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java index 5f4ea8569b..e547b1b15f 100644 --- a/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java +++ b/android/src/com/mapswithme/maps/purchase/PurchaseUtils.java @@ -22,17 +22,18 @@ import java.util.List; public class PurchaseUtils { - public final static String GROUPS = "groups"; - final static int REQ_CODE_PRODUCT_DETAILS_FAILURE = 1; - final static int REQ_CODE_PAYMENT_FAILURE = 2; - final static int REQ_CODE_VALIDATION_SERVER_ERROR = 3; - final static int REQ_CODE_START_TRANSACTION_FAILURE = 4; - final static int REQ_CODE_PING_FAILURE = 5; + public static final String GROUPS = "groups"; + public static final String SERVER_ID = "server_id"; + static final int REQ_CODE_PRODUCT_DETAILS_FAILURE = 1; + static final int REQ_CODE_PAYMENT_FAILURE = 2; + static final int REQ_CODE_VALIDATION_SERVER_ERROR = 3; + static final int REQ_CODE_START_TRANSACTION_FAILURE = 4; + static final int REQ_CODE_PING_FAILURE = 5; public static final int REQ_CODE_CHECK_INVALID_SUBS_DIALOG = 6; public static final int REQ_CODE_BMK_SUBS_SUCCESS_DIALOG = 7; - public final static int REQ_CODE_PAY_CONTINUE_SUBSCRIPTION = 8; - public final static int REQ_CODE_PAY_BOOKMARK = 9; - public final static int REQ_CODE_PAY_SUBSCRIPTION = 10; + public static final int REQ_CODE_PAY_CONTINUE_SUBSCRIPTION = 8; + public static final int REQ_CODE_PAY_BOOKMARK = 9; + public static final int REQ_CODE_PAY_SUBSCRIPTION = 10; public static final String DIALOG_TAG_CHECK_INVALID_SUBS = "check_invalid_subs"; public static final String DIALOG_TAG_BMK_SUBSCRIPTION_SUCCESS = "bmk_subscription_success"; public static final String EXTRA_IS_SUBSCRIPTION = "extra_is_subscription";