[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
This commit is contained in:
Александр Зацепин 2020-07-09 20:11:28 +03:00 committed by Arsentiy Milchakov
parent ba7fe82c37
commit 21235af0c4
4 changed files with 52 additions and 19 deletions

View file

@ -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();

View file

@ -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

View file

@ -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

View file

@ -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";