forked from organicmaps/organicmaps
[android] Implemented guides_page deeplink support
This commit is contained in:
parent
9c77de2a1b
commit
b647d3f6ae
7 changed files with 175 additions and 25 deletions
|
@ -94,6 +94,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
|
|||
Factory.createOldLeadUrlProcessor(),
|
||||
Factory.createDlinkBookmarkCatalogueProcessor(),
|
||||
Factory.createMapsmeBookmarkCatalogueProcessor(),
|
||||
Factory.createDlinkBookmarkGuidesPageProcessor(),
|
||||
Factory.createOldCoreLinkAdapterProcessor(),
|
||||
Factory.createOpenCountryTaskProcessor(),
|
||||
Factory.createMapsmeProcessor(),
|
||||
|
|
|
@ -2403,7 +2403,10 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
Statistics.INSTANCE.trackToolbarMenu(getItem());
|
||||
int requestCode = BookmarkCategoriesActivity.REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY;
|
||||
getActivity().closeMenu(() -> BookmarksCatalogActivity.startForResult(getActivity(), requestCode));
|
||||
String catalogUrl = BookmarkManager.INSTANCE.getCatalogFrontendUrl();
|
||||
getActivity().closeMenu(() -> BookmarksCatalogActivity.startForResult(getActivity(),
|
||||
requestCode,
|
||||
catalogUrl));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.mapswithme.maps.bookmarks;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
|
@ -14,22 +15,38 @@ public class BookmarksCatalogActivity extends BaseToolbarActivity
|
|||
public static final int REQ_CODE_CATALOG = 101;
|
||||
public static final String EXTRA_DOWNLOADED_CATEGORY = "extra_downloaded_category";
|
||||
|
||||
public static void startForResult(@NonNull Fragment fragment, int requestCode)
|
||||
public static void startForResult(@NonNull Fragment fragment, int requestCode,
|
||||
@NonNull String catalogUrl)
|
||||
{
|
||||
fragment.startActivityForResult(makeLaunchIntent(fragment.getContext()), requestCode);
|
||||
fragment.startActivityForResult(makeLaunchIntent(fragment.requireContext(), catalogUrl),
|
||||
requestCode);
|
||||
}
|
||||
|
||||
public static void startForResult(@NonNull Activity context, int requestCode)
|
||||
public static void startForResult(@NonNull Activity context, int requestCode,
|
||||
@NonNull String catalogUrl)
|
||||
{
|
||||
context.startActivityForResult(makeLaunchIntent(context), requestCode);
|
||||
context.startActivityForResult(makeLaunchIntent(context, catalogUrl), requestCode);
|
||||
}
|
||||
|
||||
public static void startByGuidesPageDeeplink(@NonNull Activity context, @NonNull String deeplink)
|
||||
{
|
||||
String baseCatalogUrl = BookmarkManager.INSTANCE.getCatalogFrontendUrl();
|
||||
String relativePath = Uri.parse(deeplink).getQueryParameter("url");
|
||||
Uri.Builder builder = Uri.parse(baseCatalogUrl)
|
||||
.buildUpon().appendEncodedPath(relativePath);
|
||||
BookmarksCatalogActivity.start(context, builder.toString());
|
||||
}
|
||||
|
||||
public static void start(@NonNull Activity context, @NonNull String catalogUrl)
|
||||
{
|
||||
context.startActivity(makeLaunchIntent(context, catalogUrl));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static Intent makeLaunchIntent(@NonNull Context context)
|
||||
private static Intent makeLaunchIntent(@NonNull Context context, @NonNull String catalogUrl)
|
||||
{
|
||||
Intent intent = new Intent(context, BookmarksCatalogActivity.class);
|
||||
intent.putExtra(BookmarksCatalogFragment.EXTRA_BOOKMARKS_CATALOG_URL,
|
||||
BookmarkManager.INSTANCE.getCatalogFrontendUrl());
|
||||
intent.putExtra(BookmarksCatalogFragment.EXTRA_BOOKMARKS_CATALOG_URL, catalogUrl);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
return intent;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
|
|||
downloadRoutesBtn.setOnClickListener(btn -> openBookmarksCatalogScreen());
|
||||
View closeHeaderBtn = view.findViewById(R.id.header_close);
|
||||
closeHeaderBtn.setOnClickListener(new CloseHeaderClickListener());
|
||||
boolean isClosed = SharedPropertiesUtils.isCatalogCategoriesHeaderClosed(getContext());
|
||||
boolean isClosed = SharedPropertiesUtils.isCatalogCategoriesHeaderClosed(requireContext());
|
||||
View header = view.findViewById(R.id.header);
|
||||
UiUtils.hideIf(isClosed, header);
|
||||
ImageView imageView = downloadRoutesBtn.findViewById(R.id.image);
|
||||
|
@ -78,7 +78,7 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
|
|||
@Override
|
||||
protected CatalogBookmarkCategoriesAdapter createAdapter()
|
||||
{
|
||||
return new CatalogBookmarkCategoriesAdapter(getContext());
|
||||
return new CatalogBookmarkCategoriesAdapter(requireContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -133,7 +133,9 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
|
|||
|
||||
private void openBookmarksCatalogScreen()
|
||||
{
|
||||
BookmarksCatalogActivity.startForResult(this, BookmarksCatalogActivity.REQ_CODE_CATALOG);
|
||||
String catalogUrl = BookmarkManager.INSTANCE.getCatalogFrontendUrl();
|
||||
BookmarksCatalogActivity.startForResult(this, BookmarksCatalogActivity.REQ_CODE_CATALOG,
|
||||
catalogUrl);
|
||||
Statistics.INSTANCE.trackOpenCatalogScreen();
|
||||
}
|
||||
|
||||
|
@ -142,8 +144,8 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
|
|||
{
|
||||
if (requestCode == BookmarksCatalogActivity.REQ_CODE_CATALOG && resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
getActivity().setResult(Activity.RESULT_OK, data);
|
||||
getActivity().finish();
|
||||
requireActivity().setResult(Activity.RESULT_OK, data);
|
||||
requireActivity().finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,7 +176,7 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
|
|||
{
|
||||
View header = mPayloadContainer.findViewById(R.id.header);
|
||||
header.setVisibility(View.GONE);
|
||||
SharedPropertiesUtils.setCatalogCategoriesHeaderClosed(getContext(), true);
|
||||
SharedPropertiesUtils.setCatalogCategoriesHeaderClosed(requireContext(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.mapswithme.maps.api.ParsedUrlMwmRequest;
|
|||
import com.mapswithme.maps.api.RoutePoint;
|
||||
import com.mapswithme.maps.background.NotificationCandidate;
|
||||
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
|
||||
import com.mapswithme.maps.bookmarks.BookmarksCatalogActivity;
|
||||
import com.mapswithme.maps.bookmarks.BookmarksPageFactory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.FeatureId;
|
||||
|
@ -87,6 +88,12 @@ public class Factory
|
|||
return new DlinkBookmarkCatalogueIntentProcessor();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static IntentProcessor createDlinkBookmarkGuidesPageProcessor()
|
||||
{
|
||||
return new DlinkGuidesPageIntentProcessor();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static IntentProcessor createOldLeadUrlProcessor()
|
||||
{
|
||||
|
@ -304,7 +311,7 @@ public class Factory
|
|||
@Override
|
||||
MapTask createIntroductionTask(@NonNull String url)
|
||||
{
|
||||
return new FreeGuideReadyToDownloadTask(url);
|
||||
return new FreeGuideReadyToDownloadIntroductionTask(url);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -315,6 +322,31 @@ public class Factory
|
|||
}
|
||||
}
|
||||
|
||||
public static class DlinkGuidesPageIntentProcessor extends DlinkIntentProcessor
|
||||
{
|
||||
static final String GUIDES_PAGE = "guides_page";
|
||||
|
||||
@Override
|
||||
boolean isLinkSupported(@NonNull Uri data)
|
||||
{
|
||||
return (File.separator + GUIDES_PAGE).equals(data.getPath());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
MapTask createIntroductionTask(@NonNull String url)
|
||||
{
|
||||
return new GuidesPageToOpenIntroductionTask(url);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
MapTask createTargetTask(@NonNull String url)
|
||||
{
|
||||
return new GuidesPageToOpenTask(url);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MapsmeBookmarkCatalogueProcessor extends MapsmeProcessor
|
||||
{
|
||||
@NonNull
|
||||
|
@ -642,7 +674,6 @@ public class Factory
|
|||
public static class ImportBookmarkCatalogueTask implements MapTask
|
||||
{
|
||||
private static final long serialVersionUID = 5363722491377575159L;
|
||||
|
||||
@NonNull
|
||||
private final String mUrl;
|
||||
|
||||
|
@ -659,25 +690,75 @@ public class Factory
|
|||
}
|
||||
}
|
||||
|
||||
public static class FreeGuideReadyToDownloadTask implements MapTask
|
||||
public static class GuidesPageToOpenTask extends BaseUrlTask
|
||||
{
|
||||
private static final long serialVersionUID = -6851782210156017186L;
|
||||
@NonNull
|
||||
private final String mUrl;
|
||||
private static final long serialVersionUID = 8388101038319062165L;
|
||||
|
||||
FreeGuideReadyToDownloadTask(@NonNull String url)
|
||||
GuidesPageToOpenTask(@NonNull String url)
|
||||
{
|
||||
mUrl = url;
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(@NonNull MwmActivity target)
|
||||
{
|
||||
target.showIntroductionScreenForDeeplink(mUrl, IntroductionScreenFactory.FREE_GUIDE);
|
||||
BookmarksCatalogActivity.startByGuidesPageDeeplink(target, getUrl());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static class FreeGuideReadyToDownloadIntroductionTask extends BaseUrlTask
|
||||
{
|
||||
private static final long serialVersionUID = -6851782210156017186L;
|
||||
|
||||
FreeGuideReadyToDownloadIntroductionTask(@NonNull String url)
|
||||
{
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(@NonNull MwmActivity target)
|
||||
{
|
||||
target.showIntroductionScreenForDeeplink(getUrl(), IntroductionScreenFactory.FREE_GUIDE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class GuidesPageToOpenIntroductionTask extends BaseUrlTask
|
||||
{
|
||||
private static final long serialVersionUID = 8388101038319062165L;
|
||||
|
||||
GuidesPageToOpenIntroductionTask(@NonNull String url)
|
||||
{
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(@NonNull MwmActivity target)
|
||||
{
|
||||
target.showIntroductionScreenForDeeplink(getUrl(), IntroductionScreenFactory.GUIDES_PAGE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
abstract static class BaseUrlTask implements MapTask
|
||||
{
|
||||
private static final long serialVersionUID = 9077126080900672394L;
|
||||
@NonNull
|
||||
private final String mUrl;
|
||||
|
||||
BaseUrlTask(@NonNull String url)
|
||||
{
|
||||
mUrl = url;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
String getUrl()
|
||||
{
|
||||
return mUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public static class OpenUrlTask implements MapTask
|
||||
{
|
||||
private static final long serialVersionUID = -7257820771228127413L;
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.support.annotation.StringRes;
|
|||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
|
||||
import com.mapswithme.maps.bookmarks.BookmarksCatalogActivity;
|
||||
import com.mapswithme.maps.bookmarks.BookmarksPageFactory;
|
||||
|
||||
public enum IntroductionScreenFactory
|
||||
|
@ -46,7 +47,50 @@ public enum IntroductionScreenFactory
|
|||
@Override
|
||||
public void onIntroductionButtonClick(@NonNull Activity activity, @NonNull String deeplink)
|
||||
{
|
||||
BookmarkCategoriesActivity.startForResult(activity, BookmarksPageFactory.DOWNLOADED.ordinal(), deeplink);
|
||||
BookmarkCategoriesActivity.startForResult(activity,
|
||||
BookmarksPageFactory.DOWNLOADED.ordinal(),
|
||||
deeplink);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
GUIDES_PAGE
|
||||
{
|
||||
@Override
|
||||
public int getTitle()
|
||||
{
|
||||
return R.string.onboarding_bydeeplink_guide_title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSubtitle()
|
||||
{
|
||||
return R.string.onboarding_bydeeplink_guide_subtitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAction()
|
||||
{
|
||||
return R.string.onboarding_guide_direct_download_button;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getImage()
|
||||
{
|
||||
return R.drawable.img_onboarding_guide;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public OnIntroductionButtonClickListener createButtonClickListener()
|
||||
{
|
||||
return new OnIntroductionButtonClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onIntroductionButtonClick(@NonNull Activity activity,
|
||||
@NonNull String deeplink)
|
||||
{
|
||||
BookmarksCatalogActivity.startByGuidesPageDeeplink(activity, deeplink);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.mapswithme.maps.MwmActivity;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
|
||||
import com.mapswithme.maps.bookmarks.BookmarksCatalogActivity;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.maplayer.Mode;
|
||||
|
||||
class ClickInterceptorFactory
|
||||
|
@ -44,9 +45,10 @@ class ClickInterceptorFactory
|
|||
@Override
|
||||
public void onInterceptClickInternal(@NonNull MwmActivity activity)
|
||||
{
|
||||
String catalogUrl = BookmarkManager.INSTANCE.getCatalogFrontendUrl();
|
||||
BookmarksCatalogActivity.startForResult(activity,
|
||||
BookmarkCategoriesActivity
|
||||
.REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY);
|
||||
.REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY, catalogUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue