From c1029dc39a0c413cb54756608dc636d48030bfdc Mon Sep 17 00:00:00 2001 From: Alexander Zatsepin Date: Wed, 4 Jul 2018 15:27:07 +0300 Subject: [PATCH] [android] Added opening the bookmark catalog categories by deeplink --- android/AndroidManifest.xml | 9 ------- .../maps/DownloadResourcesLegacyActivity.java | 26 +++++++++++-------- .../src/com/mapswithme/maps/MwmActivity.java | 2 ++ .../bookmarks/BookmarkCategoriesActivity.java | 13 ++++++++++ .../BookmarkCategoriesPagerFragment.java | 15 ++++++++--- .../mapswithme/maps/bookmarks/Constants.java | 19 ++++++++++++++ .../util/SharedPropertiesUtils.java | 4 ++- 7 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 android/src/com/mapswithme/maps/bookmarks/Constants.java diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index f1ac4fd32d..a72e4bebcc 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -172,15 +172,6 @@ - - - - diff --git a/android/src/com/mapswithme/maps/DownloadResourcesLegacyActivity.java b/android/src/com/mapswithme/maps/DownloadResourcesLegacyActivity.java index 686bfeb93b..e0f3767c36 100644 --- a/android/src/com/mapswithme/maps/DownloadResourcesLegacyActivity.java +++ b/android/src/com/mapswithme/maps/DownloadResourcesLegacyActivity.java @@ -658,10 +658,12 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity private class BookmarkCatalogueIntentProcessor extends DlinkIntentProcessor { + private static final String PATH = "/catalogue"; + @Override - boolean isLinkSupported(@NonNull Intent intent, @NonNull Uri data) + boolean isLinkSupported(@NonNull Uri data) { - return "/catalogue".equals(data.getPath()); + return PATH.equals(data.getPath()); } @NonNull @@ -677,7 +679,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity private static final String SCHEME_CORE = "mapsme"; @Override - protected boolean isLinkSupported(@NonNull Intent intent, @NonNull Uri data) + protected boolean isLinkSupported(@NonNull Uri data) { return true; } @@ -687,12 +689,14 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity protected MapTask createMapTask(@NonNull String url) { // Transform deeplink to the core expected format, - // i.e https://host/path?query -> mapsme://path?query. - url = url.replace(SCHEME_HTTPS, SCHEME_CORE) - .replace(HOST, ""); - - LOGGER.i(TAG, "MAPSME URL = " + url); - return new OpenUrlTask(url); + // i.e https://host/path?query -> mapsme:///path?query. + Uri uri = Uri.parse(url); + Uri.Builder builder = uri.buildUpon(); + builder.scheme(SCHEME_CORE) + .authority(""); + Uri coreUri = builder.build(); + LOGGER.i(TAG, "MAPSME URL = " + coreUri); + return new OpenUrlTask(coreUri.toString()); } } @@ -712,10 +716,10 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity String scheme = intent.getScheme(); String host = data.getHost(); - return SCHEME_HTTPS.equals(scheme) && HOST.equals(host) && isLinkSupported(intent, data); + return SCHEME_HTTPS.equals(scheme) && HOST.equals(host) && isLinkSupported(data); } - abstract boolean isLinkSupported(@NonNull Intent intent, @NonNull Uri data); + abstract boolean isLinkSupported(@NonNull Uri data); @Override public final boolean process(@NonNull Intent intent) diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index e390f0bd91..74861ab93f 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -43,6 +43,7 @@ import com.mapswithme.maps.base.BaseMwmFragmentActivity; import com.mapswithme.maps.base.OnBackPressListener; import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity; import com.mapswithme.maps.bookmarks.BookmarksDownloadManager; +import com.mapswithme.maps.bookmarks.Constants; import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.bookmarks.data.FeatureId; import com.mapswithme.maps.bookmarks.data.MapObject; @@ -1738,6 +1739,7 @@ public class MwmActivity extends BaseMwmFragmentActivity try { BookmarksDownloadManager.from(target).enqueueRequest(mUrl); + BookmarkCategoriesActivity.start(target, Constants.CATEGORIES_PAGE_CATALOG); } catch (BookmarksDownloadManager.UnprocessedUrlException e) { diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java index 5a4f37c1bd..54a50dff5b 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java @@ -1,5 +1,8 @@ package com.mapswithme.maps.bookmarks; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; import android.support.annotation.CallSuper; import android.support.annotation.NonNull; import android.support.annotation.StyleRes; @@ -12,6 +15,16 @@ import com.mapswithme.util.ThemeUtils; public class BookmarkCategoriesActivity extends BaseToolbarActivity { + + public static void start(@NonNull Context context, @Constants.CategoriesPage int categoriesPage) + { + Intent intent = new Intent(context, BookmarkCategoriesActivity.class); + Bundle args = new Bundle(); + args.putInt(Constants.ARG_CATEGORIES_PAGE, categoriesPage); + intent.putExtras(args); + context.startActivity(intent); + } + @CallSuper @Override public void onResume() diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesPagerFragment.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesPagerFragment.java index 2652299f5e..c2e9d4a8c0 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesPagerFragment.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesPagerFragment.java @@ -19,7 +19,6 @@ import java.util.List; public class BookmarkCategoriesPagerFragment extends BaseMwmFragment { - @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -39,15 +38,23 @@ public class BookmarkCategoriesPagerFragment extends BaseMwmFragment List dataSet = getAdapterDataSet(); BookmarksPagerAdapter adapter = new BookmarksPagerAdapter(getContext(), fm, dataSet); viewPager.setAdapter(adapter); - - int lastVisibleScreen = SharedPropertiesUtils.getLastVisibleBookmarkCategoriesPage(getActivity()); - viewPager.setCurrentItem(lastVisibleScreen); + viewPager.setCurrentItem(getInitialPage()); tabLayout.setupWithViewPager(viewPager); viewPager.addOnPageChangeListener(new PageChangeListener()); return root; } + @Constants.CategoriesPage + private int getInitialPage() + { + Bundle args = getArguments(); + if (args == null || !args.containsKey(Constants.ARG_CATEGORIES_PAGE)) + return SharedPropertiesUtils.getLastVisibleBookmarkCategoriesPage(getActivity()); + + return args.getInt(Constants.ARG_CATEGORIES_PAGE); + } + @NonNull private static List getAdapterDataSet() { diff --git a/android/src/com/mapswithme/maps/bookmarks/Constants.java b/android/src/com/mapswithme/maps/bookmarks/Constants.java new file mode 100644 index 0000000000..97d5b8bec6 --- /dev/null +++ b/android/src/com/mapswithme/maps/bookmarks/Constants.java @@ -0,0 +1,19 @@ +package com.mapswithme.maps.bookmarks; + +import android.support.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class Constants +{ + @Retention(RetentionPolicy.SOURCE) + @IntDef({ CATEGORIES_PAGE_PRIVATE, CATEGORIES_PAGE_CATALOG }) + + public @interface CategoriesPage {} + + public static final int CATEGORIES_PAGE_PRIVATE = 0; + public static final int CATEGORIES_PAGE_CATALOG = 1; + + final static String ARG_CATEGORIES_PAGE = "arg_categories_page"; +} diff --git a/android/src/com/mapswithme/util/SharedPropertiesUtils.java b/android/src/com/mapswithme/util/SharedPropertiesUtils.java index 6146b511d8..9478e9359e 100644 --- a/android/src/com/mapswithme/util/SharedPropertiesUtils.java +++ b/android/src/com/mapswithme/util/SharedPropertiesUtils.java @@ -8,6 +8,7 @@ import android.support.annotation.Nullable; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; +import com.mapswithme.maps.bookmarks.Constants; import static com.mapswithme.util.Config.KEY_PREF_STATISTICS; @@ -100,7 +101,8 @@ public final class SharedPropertiesUtils .getInt(PREFS_BOOKMARK_CATEGORIES_LAST_VISIBLE_PAGE, 0); } - public static void setLastVisibleBookmarkCategoriesPage(@NonNull Context context, int pageIndex) + public static void setLastVisibleBookmarkCategoriesPage(@NonNull Context context, + @Constants.CategoriesPage int pageIndex) { MwmApplication.prefs(context) .edit()