forked from organicmaps/organicmaps
[android] Added opening the bookmark catalog categories by deeplink
This commit is contained in:
parent
aa6cdd08ad
commit
c1029dc39a
7 changed files with 63 additions and 25 deletions
|
@ -172,15 +172,6 @@
|
|||
<data
|
||||
android:host="dlink.maps.me"
|
||||
android:scheme="https"/>
|
||||
|
||||
<data
|
||||
android:host="dlink.maps.me"
|
||||
android:scheme="http"/>
|
||||
|
||||
<data
|
||||
android:host="dlink.maps.me"
|
||||
android:scheme="https"
|
||||
android:path="/catalogue"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- API CALL -->
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<BookmarksPageFactory> 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<BookmarksPageFactory> getAdapterDataSet()
|
||||
{
|
||||
|
|
19
android/src/com/mapswithme/maps/bookmarks/Constants.java
Normal file
19
android/src/com/mapswithme/maps/bookmarks/Constants.java
Normal file
|
@ -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";
|
||||
}
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue