From 263d3e764ed48a60092a3451ef218f8a1c120b90 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 15 Apr 2018 18:39:07 +0200 Subject: [PATCH] Rename travel db helper and introduce settings for markers --- .../src/net/osmand/plus/AppInitializer.java | 4 ++-- .../src/net/osmand/plus/MapMarkersHelper.java | 23 ++++++++++++++++++- .../net/osmand/plus/OsmandApplication.java | 8 +++---- .../plus/activities/MapActivityActions.java | 4 ++-- .../adapters/MapMarkersGroupsAdapter.java | 1 + .../wikivoyage/WikivoyageWebViewClient.java | 2 +- .../WikivoyageArticleDialogFragment.java | 12 +++++----- ...oyageDbHelper.java => TravelDbHelper.java} | 6 ++--- .../data/WikivoyageLocalDataHelper.java | 4 ++-- .../explore/SavedArticlesRvAdapter.java | 2 +- .../explore/SavedArticlesTabFragment.java | 2 +- ...oyageOptionsBottomSheetDialogFragment.java | 8 +++---- .../WikivoyageSearchDialogFragment.java | 2 +- .../search/WikivoyageSearchHelper.java | 2 +- 14 files changed, 51 insertions(+), 29 deletions(-) rename OsmAnd/src/net/osmand/plus/wikivoyage/data/{WikivoyageDbHelper.java => TravelDbHelper.java} (98%) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 749c5dcb44..604e1620a7 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -47,7 +47,7 @@ import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayerException; import net.osmand.plus.voice.MediaCommandPlayerImpl; import net.osmand.plus.voice.TTSCommandPlayerImpl; -import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper; +import net.osmand.plus.wikivoyage.data.TravelDbHelper; import net.osmand.render.RenderingRulesStorage; import net.osmand.router.RoutingConfiguration; import net.osmand.util.Algorithms; @@ -445,7 +445,7 @@ public class AppInitializer implements IProgress { app.mapMarkersDbHelper = startupInit(new MapMarkersDbHelper(app), MapMarkersDbHelper.class); app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class); app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class); - app.wikivoyageDbHelper = startupInit(new WikivoyageDbHelper(app), WikivoyageDbHelper.class); + app.wikivoyageDbHelper = startupInit(new TravelDbHelper(app), TravelDbHelper.class); initOpeningHoursParser(); } diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 137752ec5f..db61b71e28 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -6,7 +6,6 @@ import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; - import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.data.FavouritePoint; @@ -20,6 +19,8 @@ import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MarkersPlanRouteContext; +import net.osmand.plus.wikivoyage.data.TravelDbHelper; +import net.osmand.plus.wikivoyage.data.WikivoyageArticle; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -497,6 +498,26 @@ public class MapMarkersHelper { } return res; } + + @NonNull + public List getGroupsForSavedArticlesTravelBook() { + List res = new ArrayList<>(); + TravelDbHelper travelDbHelper = ctx.getTravelDbHelper(); + if(travelDbHelper.getSelectedTravelBook() != null) { + List savedArticles = travelDbHelper.getLocalDataHelper().getSavedArticles(); + for (WikivoyageArticle art : savedArticles) { + String gpxName = travelDbHelper.getGPXName(art); + File path = ctx.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName); + MapMarkersGroup group = getOrCreateGroup(new File(path.getAbsolutePath())); + if (!isGroupSynced(group.getId())) { + group.disabled = true; + createHeaderInGroup(group); + res.add(group); + } + } + } + return res; + } @Nullable public MapMarker getMapMarker(WptPt wptPt) { diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index f1ba71a69a..48b0755ec8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -56,7 +56,7 @@ import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.search.QuickSearchHelper; import net.osmand.plus.voice.CommandPlayer; -import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper; +import net.osmand.plus.wikivoyage.data.TravelDbHelper; import net.osmand.router.RoutingConfiguration; import net.osmand.search.SearchUICore; import net.osmand.util.Algorithms; @@ -119,7 +119,7 @@ public class OsmandApplication extends MultiDexApplication { OsmandRegions regions; GeocodingLookupService geocodingLookupService; QuickSearchHelper searchUICore; - WikivoyageDbHelper wikivoyageDbHelper; + TravelDbHelper travelDbHelper; RoutingConfiguration.Builder defaultRoutingConfig; private Locale preferredLocale = null; @@ -392,8 +392,8 @@ public class OsmandApplication extends MultiDexApplication { return searchUICore; } - public WikivoyageDbHelper getWikivoyageDbHelper() { - return wikivoyageDbHelper; + public TravelDbHelper getTravelDbHelper() { + return travelDbHelper; } public CommandPlayer getPlayer() { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index e748cbcc61..4680db276b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -63,7 +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.explore.WikivoyageExploreDialogFragment; -import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper; +import net.osmand.plus.wikivoyage.data.TravelDbHelper; import net.osmand.router.GeneralRouter; import org.apache.commons.logging.Log; @@ -771,7 +771,7 @@ public class MapActivityActions implements DialogProvider { .setListener(new ItemClickListener() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { - getMyApplication().getWikivoyageDbHelper().initTravelBooks(); + getMyApplication().getTravelDbHelper().initTravelBooks(); MapActivity.clearPrevActivityIntent(); WikivoyageExploreDialogFragment.showInstance(mapActivity.getSupportFragmentManager()); return true; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 2feadfacc0..cf7f07199d 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -93,6 +93,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter groups = new ArrayList<>(helper.getMapMarkersGroups()); groups.addAll(helper.getGroupsForDisplayedGpx()); + groups.addAll(helper.getGroupsForSavedArticlesTravelBook()); for (int i = 0; i < groups.size(); i++) { MapMarkersGroup group = groups.get(i); if (!group.isVisible()) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java index 0f63e0c975..e1b8c6a042 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageWebViewClient.java @@ -48,7 +48,7 @@ public class WikivoyageWebViewClient extends WebViewClient { } catch (UnsupportedEncodingException e) { e.printStackTrace(); } - long articleId = app.getWikivoyageDbHelper().getArticleId(articleName, lang); + long articleId = app.getTravelDbHelper().getArticleId(articleName, lang); if (articleId != 0) { WikivoyageArticleDialogFragment.showInstance(app, mFragmentManager, articleId, lang); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index a34411d5be..15e9e666d4 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -35,7 +35,7 @@ import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageShowPicturesDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageWebViewClient; import net.osmand.plus.wikivoyage.data.WikivoyageArticle; -import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper; +import net.osmand.plus.wikivoyage.data.TravelDbHelper; import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper; import net.osmand.util.Algorithms; @@ -178,7 +178,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen return; } final GPXFile gpx = article.getGpxFile(); - WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper(); + TravelDbHelper dbHelper = getMyApplication().getTravelDbHelper(); File file = getMyApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR + dbHelper.getGPXName(article)); GPXUtilities.writeGpxFile(file, gpx, getMyApplication()); @@ -267,7 +267,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen private void updateSaveButton() { if (article != null) { - final WikivoyageLocalDataHelper helper = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper(); + final WikivoyageLocalDataHelper helper = getMyApplication().getTravelDbHelper().getLocalDataHelper(); final boolean saved = helper.isArticleSaved(article); Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later); saveBtn.setText(getString(saved ? R.string.shared_string_delete : R.string.shared_string_save)); @@ -326,7 +326,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen selectedLang = langs.get(0); } articleToolbarText.setText(""); - article = getMyApplication().getWikivoyageDbHelper().getArticle(cityId, selectedLang); + article = getMyApplication().getTravelDbHelper().getArticle(cityId, selectedLang); if (article == null) { return; } @@ -335,7 +335,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen trackButton.setText(getString(R.string.points) + " (" + article.getGpxFile().getPointsSize() +")"); } - WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper(); + WikivoyageLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper(); ldh.addToHistory(article); updateSaveButton(); @@ -387,7 +387,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen @NonNull FragmentManager fm, long cityId, @Nullable String selectedLang) { - ArrayList langs = app.getWikivoyageDbHelper().getArticleLangs(cityId); + ArrayList langs = app.getTravelDbHelper().getArticleLangs(cityId); return showInstance(fm, cityId, langs, selectedLang); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java similarity index 98% rename from OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java rename to OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index e588f1efb1..369d705b6f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -29,9 +29,9 @@ import org.apache.commons.logging.Log; import gnu.trove.map.hash.TLongObjectHashMap; -public class WikivoyageDbHelper { +public class TravelDbHelper { - private static final Log LOG = PlatformUtil.getLog(WikivoyageDbHelper.class); + private static final Log LOG = PlatformUtil.getLog(TravelDbHelper.class); private static final String ARTICLES_TABLE_NAME = "wikivoyage_articles"; private static final String ARTICLES_COL_ID = "article_id"; @@ -79,7 +79,7 @@ public class WikivoyageDbHelper { private boolean initialized = false; - public WikivoyageDbHelper(OsmandApplication application) { + public TravelDbHelper(OsmandApplication application) { this.application = application; collator = OsmAndCollator.primaryCollator(); if(application.getSettings().SELECTED_TRAVEL_BOOK.get() != null) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java index 9e295145fb..c81372d15a 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageLocalDataHelper.java @@ -246,8 +246,8 @@ public class WikivoyageLocalDataHelper { if (oldVersion < 3) { conn.execSQL("ALTER TABLE " + HISTORY_TABLE_NAME + " ADD " + HISTORY_COL_TRAVEL_BOOK + " TEXT"); conn.execSQL("ALTER TABLE " + BOOKMARKS_TABLE_NAME + " ADD " + BOOKMARKS_COL_TRAVEL_BOOK + " TEXT"); - if(context.getWikivoyageDbHelper().getSelectedTravelBook() != null) { - Object[] args = new Object[]{context.getWikivoyageDbHelper().getSelectedTravelBook().getName()}; + if(context.getTravelDbHelper().getSelectedTravelBook() != null) { + Object[] args = new Object[]{context.getTravelDbHelper().getSelectedTravelBook().getName()}; conn.execSQL("UPDATE " + HISTORY_TABLE_NAME + " SET " + HISTORY_COL_TRAVEL_BOOK + " = ?", args); conn.execSQL("UPDATE " + BOOKMARKS_TABLE_NAME + " SET " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?", args); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index 8e7f3508d0..8da2f261d6 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -191,7 +191,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES; - final WikivoyageDbHelper dbHelper = app.getWikivoyageDbHelper(); + final TravelDbHelper dbHelper = app.getTravelDbHelper(); items.add(new TitleItem(getString(R.string.shared_string_options))); @@ -110,7 +110,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper(); + WikivoyageLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper(); ldh.clearHistory(); dismiss(); } @@ -120,7 +120,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD } protected void selectTravelBookDialog() { - final WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper(); + final TravelDbHelper dbHelper = getMyApplication().getTravelDbHelper(); final List list = dbHelper.getExistingTravelBooks(); String[] ls = new String[list.size()]; for (int i = 0; i < ls.length; i++) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java index 7070e4c50b..1d7629af32 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java @@ -147,7 +147,7 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment private void setAdapterItems(@Nullable List items) { if (items == null || items.isEmpty()) { - WikivoyageLocalDataHelper ldh = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper(); + WikivoyageLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper(); adapter.setHistoryItems(ldh.getAllHistory()); } else { adapter.setItems(items); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchHelper.java index c5359c0e5d..147cfbd91e 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchHelper.java @@ -42,7 +42,7 @@ public class WikivoyageSearchHelper { } if (!isCancelled()) { - List results = application.getWikivoyageDbHelper().search(query); + List results = application.getTravelDbHelper().search(query); if (!isCancelled()) { rm.publish(results); }