From abc796d8239b10871a801f78c5c8bb5842ca8bce Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 27 Mar 2018 17:28:29 +0300 Subject: [PATCH] Change travel item position in navigation drawer; show travel item only if db file exists --- .../plus/activities/MapActivityActions.java | 25 +++++++++++-------- .../wikivoyage/data/WikivoyageDbHelper.java | 11 +++++++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 2819f0ac2b..a61007900f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -63,6 +63,7 @@ import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.wikivoyage.WikivoyageExploreDialogFragment; +import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper; import net.osmand.router.GeneralRouter; import org.apache.commons.logging.Log; @@ -765,6 +766,19 @@ public class MapActivityActions implements DialogProvider { }).createItem()); } + if (WikivoyageDbHelper.isDbFileExists(app)) { + optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.shared_string_travel, mapActivity) + .setIcon(R.drawable.ic_action_travel) + .setListener(new ItemClickListener() { + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { + MapActivity.clearPrevActivityIntent(); + WikivoyageExploreDialogFragment.showInstance(mapActivity.getSupportFragmentManager()); + return true; + } + }).createItem()); + } + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.measurement_tool, mapActivity) .setIcon(R.drawable.ic_action_ruler) .setListener(new ContextMenuAdapter.ItemClickListener() { @@ -775,17 +789,6 @@ public class MapActivityActions implements DialogProvider { } }).createItem()); - optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.shared_string_travel, mapActivity) - .setIcon(R.drawable.ic_action_track_16) - .setListener(new ContextMenuAdapter.ItemClickListener() { - @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { - MapActivity.clearPrevActivityIntent(); - WikivoyageExploreDialogFragment.showInstance(mapActivity.getSupportFragmentManager()); - return true; - } - }).createItem()); - optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.layer_map_appearance, mapActivity) .setIcon(R.drawable.ic_configure_screen_dark) .setListener(new ContextMenuAdapter.ItemClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java index 5b937b630a..d1b5913ea3 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java @@ -7,6 +7,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -82,7 +83,7 @@ public class WikivoyageDbHelper { @Nullable private SQLiteConnection openConnection() { - String path = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR + DB_NAME).getAbsolutePath(); + String path = getDbFile(application).getAbsolutePath(); return application.getSQLiteAPI().openByAbsolutePath(path, true); } @@ -97,6 +98,14 @@ public class WikivoyageDbHelper { return res; } + public static boolean isDbFileExists(OsmandApplication app) { + return getDbFile(app).exists(); + } + + private static File getDbFile(OsmandApplication app) { + return app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR + DB_NAME); + } + public static class SearchResult { private String searchTerm;