diff --git a/OsmAnd-java/src/net/osmand/IndexConstants.java b/OsmAnd-java/src/net/osmand/IndexConstants.java index 508f98d4b3..d6834bcf4d 100644 --- a/OsmAnd-java/src/net/osmand/IndexConstants.java +++ b/OsmAnd-java/src/net/osmand/IndexConstants.java @@ -10,11 +10,15 @@ public class IndexConstants { public final static int VOICE_VERSION = 0; //supported download versions public final static int TTSVOICE_VERSION = 1; //supported download versions + public static final String SQLITE_EXT = ".sqlitedb"; //$NON-NLS-1$ + public static final String TEMP_SOURCE_TO_LOAD = "temp"; + public static final String POI_INDEX_EXT = ".poi.odb"; //$NON-NLS-1$ public static final String BINARY_MAP_INDEX_EXT = ".obf"; //$NON-NLS-1$ public static final String BINARY_MAP_INDEX_EXT_ZIP = ".obf.zip"; //$NON-NLS-1$ + public static final String BINARY_WIKIVOYAGE_MAP_INDEX_EXT = ".sqlite"; //$NON-NLS-1$ public static final String BINARY_WIKI_MAP_INDEX_EXT = ".wiki.obf"; //$NON-NLS-1$ public static final String BINARY_WIKI_MAP_INDEX_EXT_ZIP = ".wiki.obf.zip"; //$NON-NLS-1$ public static final String BINARY_ROAD_MAP_INDEX_EXT = ".road.obf"; //$NON-NLS-1$ @@ -54,7 +58,7 @@ public class IndexConstants { public static final String SRTM_INDEX_DIR = "srtm/"; //$NON-NLS-1$ public static final String ROADS_INDEX_DIR = "roads/"; //$NON-NLS-1$ public static final String WIKI_INDEX_DIR = "wiki/"; //$NON-NLS-1$ - public static final String WIKIVOYAGE_INDEX_DIR = "wikivoyage/"; + public static final String WIKIVOYAGE_INDEX_DIR = "travel/"; public static final String AV_INDEX_DIR = "avnotes/"; //$NON-NLS-1$ public static final String FONT_INDEX_DIR = "fonts/"; //$NON-NLS-1$ public static final String VOICE_INDEX_DIR = "voice/"; //$NON-NLS-1$ @@ -62,8 +66,7 @@ public class IndexConstants { public static final String ROUTING_XML_FILE= "routing.xml"; - public static final String SQLITE_EXT = ".sqlitedb"; //$NON-NLS-1$ - public static final String TEMP_SOURCE_TO_LOAD = "temp"; + } diff --git a/OsmAnd/assets/article_style.css b/OsmAnd/assets/article_style.css index baf85339df..5562dbb38d 100644 --- a/OsmAnd/assets/article_style.css +++ b/OsmAnd/assets/article_style.css @@ -126,3 +126,8 @@ pre { font-style: italic; text-align: center; } + +.content { + display: none; + overflow: hidden; +} diff --git a/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml b/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml index 1e44100049..787f1b54aa 100644 --- a/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml +++ b/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml @@ -74,12 +74,6 @@ android:layout_height="10dp" android:background="@drawable/bg_contextmenu_shadow_top_light" /> - - + tools:ignore="UnusedAttribute" /> + tools:text="Save" /> diff --git a/OsmAnd/res/layout/wikivoyage_article_card.xml b/OsmAnd/res/layout/wikivoyage_article_card.xml index 768a7b0a1e..5f5dfc7a44 100644 --- a/OsmAnd/res/layout/wikivoyage_article_card.xml +++ b/OsmAnd/res/layout/wikivoyage_article_card.xml @@ -55,8 +55,8 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/wikivoyage_contents_list_item.xml b/OsmAnd/res/layout/wikivoyage_contents_list_item.xml index 040a075af4..5a8df25af2 100644 --- a/OsmAnd/res/layout/wikivoyage_contents_list_item.xml +++ b/OsmAnd/res/layout/wikivoyage_contents_list_item.xml @@ -1,23 +1,56 @@ + xmlns:osmand="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="?attr/selectableItemBackground" + android:orientation="vertical"> - + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values-large/sizes.xml b/OsmAnd/res/values-large/sizes.xml index ec6927b459..837f7d4504 100644 --- a/OsmAnd/res/values-large/sizes.xml +++ b/OsmAnd/res/values-large/sizes.xml @@ -195,5 +195,6 @@ 84dp 54dp - 120dp + 120dp + 60dp \ No newline at end of file diff --git a/OsmAnd/res/values-ru/phrases.xml b/OsmAnd/res/values-ru/phrases.xml index 45be223a17..e11e171e92 100644 --- a/OsmAnd/res/values-ru/phrases.xml +++ b/OsmAnd/res/values-ru/phrases.xml @@ -3779,4 +3779,8 @@ Зиплайн + Виа феррата + Количество тросов + Сложность + diff --git a/OsmAnd/res/values/phrases.xml b/OsmAnd/res/values/phrases.xml index 03072ea739..4bf23631a5 100644 --- a/OsmAnd/res/values/phrases.xml +++ b/OsmAnd/res/values/phrases.xml @@ -3799,4 +3799,8 @@ Climbing adventure + Via ferrata + Cable number + Difficulty + diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 1d050252d5..680e1974bf 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -269,7 +269,8 @@ 56dp 36dp - 80dp + 80dp + 40dp 0.01 \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 5df3842b5d..6d00d5cf6c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Travel maps + Wikivoyage Article removed Search: Country, City, Province Read @@ -309,6 +311,8 @@ Sea depth contour lines and nautical point maps. Thank you for purchasing nautical depth contours Nautical depth contours + + Worldwide Wikivoyage articles Southern hemisphere nautical depth points Northern hemisphere nautical depth points Nautical depth contours diff --git a/OsmAnd/src/net/osmand/PlatformUtil.java b/OsmAnd/src/net/osmand/PlatformUtil.java index 7fb26b8c96..301443074b 100644 --- a/OsmAnd/src/net/osmand/PlatformUtil.java +++ b/OsmAnd/src/net/osmand/PlatformUtil.java @@ -114,9 +114,9 @@ public class PlatformUtil { @Override public boolean isDebugEnabled() { - // For debur purposes always true - return android.util.Log.isLoggable(TAG, android.util.Log.DEBUG); -// return true; + // For debug purposes always true + // return android.util.Log.isLoggable(TAG, android.util.Log.DEBUG); + return true; } @Override diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index ea14d27611..4f8f2de103 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -2997,6 +2997,8 @@ public class OsmandSettings { public final OsmandPreference FOLLOW_THE_ROUTE = new BooleanPreference("follow_to_route", false).makeGlobal(); public final OsmandPreference FOLLOW_THE_GPX_ROUTE = new StringPreference("follow_gpx", null).makeGlobal(); + + public final OsmandPreference SELECTED_TRAVEL_BOOK = new StringPreference("selected_travel_book", "").makeGlobal(); public final ListStringPreference TRANSPORT_DEFAULT_SETTINGS = (ListStringPreference) new ListStringPreference("transport_default_settings", "transportStops", ",").makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java index ee46c4a867..68442682d5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java @@ -83,6 +83,8 @@ public class LocalIndexHelper { info.setDescription(app.getString(R.string.download_srtm_maps)); } else if (info.getType() == LocalIndexType.WIKI_DATA) { info.setDescription(getInstalledDate(f)); + } else if (info.getType() == LocalIndexType.TRAVEL_DATA) { + info.setDescription(getInstalledDate(f)); } else if (info.getType() == LocalIndexType.TTS_VOICE_DATA) { info.setDescription(getInstalledDate(f)); } else if (info.getType() == LocalIndexType.DEACTIVATED) { @@ -117,6 +119,10 @@ public class LocalIndexHelper { fileDir = app.getAppPath(IndexConstants.WIKI_INDEX_DIR); fileName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + IndexConstants.BINARY_WIKI_MAP_INDEX_EXT; + } else if (type == LocalIndexType.TRAVEL_DATA) { + fileDir = app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR); + fileName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + + IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT; } if (backuped) { @@ -135,33 +141,7 @@ public class LocalIndexHelper { return null; } - public LocalIndexInfo getLocalIndexInfo(String downloadName) { - LocalIndexInfo info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, false, false); - if (info == null) { - info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, true, false); - } - if (info == null) { - info = getLocalIndexInfo(LocalIndexType.SRTM_DATA, downloadName, false, false); - } - if (info == null) { - info = getLocalIndexInfo(LocalIndexType.WIKI_DATA, downloadName, false, false); - } - - if (info == null) { - info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, false, true); - } - if (info == null) { - info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, true, true); - } - if (info == null) { - info = getLocalIndexInfo(LocalIndexType.SRTM_DATA, downloadName, false, true); - } - if (info == null) { - info = getLocalIndexInfo(LocalIndexType.WIKI_DATA, downloadName, false, true); - } - - return info; - } + public List getLocalIndexInfos(String downloadName) { List list = new ArrayList<>(); @@ -210,6 +190,7 @@ public class LocalIndexHelper { loadTilesData(app.getAppPath(IndexConstants.TILES_INDEX_DIR), result, false, loadTask); loadSrtmData(app.getAppPath(IndexConstants.SRTM_INDEX_DIR), result, loadTask); loadWikiData(app.getAppPath(IndexConstants.WIKI_INDEX_DIR), result, loadTask); + loadTravelData(app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), result, loadTask); //loadVoiceData(app.getAppPath(IndexConstants.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask); loadVoiceData(app.getAppPath(IndexConstants.VOICE_INDEX_DIR), result, false, loadTask); loadFontData(app.getAppPath(IndexConstants.FONT_INDEX_DIR), result, false, loadTask); @@ -329,6 +310,19 @@ public class LocalIndexHelper { } } } + + private void loadTravelData(File mapPath, List result, AbstractLoadLocalIndexTask loadTask) { + if (mapPath.canRead()) { + for (File mapFile : listFilesSorted(mapPath)) { + if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) { + LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.TRAVEL_DATA, mapFile, false, app); + updateDescription(info); + result.add(info); + loadTask.loadFile(info); + } + } + } + } private void loadObfData(File mapPath, List result, boolean backup, AbstractLoadLocalIndexTask loadTask, Map loadedMaps) { if (mapPath.canRead()) { @@ -357,6 +351,7 @@ public class LocalIndexHelper { TILES_DATA(R.string.local_indexes_cat_tile, R.drawable.ic_map, 60), SRTM_DATA(R.string.local_indexes_cat_srtm, R.drawable.ic_plugin_srtm, 40), WIKI_DATA(R.string.local_indexes_cat_wiki, R.drawable.ic_plugin_wikipedia, 50), + TRAVEL_DATA(R.string.download_maps_travel, R.drawable.ic_plugin_wikipedia, 60), TTS_VOICE_DATA(R.string.local_indexes_cat_tts, R.drawable.ic_action_volume_up, 20), VOICE_DATA(R.string.local_indexes_cat_voice, R.drawable.ic_action_volume_up, 30), FONT_DATA(R.string.fonts_header, R.drawable.ic_action_map_language, 35), @@ -403,6 +398,10 @@ public class LocalIndexHelper { if (fileName.endsWith(IndexConstants.SQLITE_EXT)) { return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()); } + if (localIndexInfo.getType() == TRAVEL_DATA && + fileName.endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) { + return fileName.substring(0, fileName.length() - IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT.length()); + } if (this == VOICE_DATA) { int l = fileName.lastIndexOf('_'); if (l == -1) { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index ae3f38c145..e748cbcc61 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -766,18 +766,17 @@ 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 ItemBuilder().setTitle(getString(R.string.shared_string_travel) + " (Beta)") + .setIcon(R.drawable.ic_action_travel) + .setListener(new ItemClickListener() { + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { + getMyApplication().getWikivoyageDbHelper().initTravelBooks(); + 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) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index d1c1f3625d..582c18b841 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -45,6 +45,8 @@ public class DownloadActivityType { new DownloadActivityType(R.string.download_hillshade_maps, R.drawable.ic_action_hillshade_dark, "hillshade", 50); public static final DownloadActivityType WIKIPEDIA_FILE = new DownloadActivityType(R.string.download_wikipedia_maps, R.drawable.ic_plugin_wikipedia, "wikimap", 60); + public static final DownloadActivityType WIKIVOYAGE_FILE = + new DownloadActivityType(R.string.shared_string_wikivoyage, R.drawable.ic_plugin_wikipedia, "wikivoyage", 65); public static final DownloadActivityType LIVE_UPDATES_FILE = new DownloadActivityType(R.string.download_live_updates, "live_updates", 70); private final int stringResource; @@ -121,6 +123,8 @@ public class DownloadActivityType { } else if (WIKIPEDIA_FILE == this) { return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)); + } else if (WIKIVOYAGE_FILE == this) { + return fileName.endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT); } else if (SRTM_COUNTRY_FILE == this) { return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)); @@ -148,6 +152,8 @@ public class DownloadActivityType { return ctx.getAppPath(IndexConstants.SRTM_INDEX_DIR); } else if (WIKIPEDIA_FILE == this) { return ctx.getAppPath(IndexConstants.WIKI_INDEX_DIR); + } else if (WIKIVOYAGE_FILE == this) { + return ctx.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR); } else if (LIVE_UPDATES_FILE == this) { return ctx.getAppPath(IndexConstants.LIVE_INDEX_DIR); } else if (HILLSHADE_FILE == this) { @@ -159,7 +165,7 @@ public class DownloadActivityType { } public boolean isZipStream(OsmandApplication ctx, IndexItem indexItem) { - return HILLSHADE_FILE != this; + return HILLSHADE_FILE != this && WIKIVOYAGE_FILE != this; } public boolean isZipFolder(OsmandApplication ctx, IndexItem indexItem) { @@ -193,6 +199,8 @@ public class DownloadActivityType { return IndexConstants.BINARY_SRTM_MAP_INDEX_EXT; } else if (WIKIPEDIA_FILE == this) { return IndexConstants.BINARY_WIKI_MAP_INDEX_EXT; + } else if (WIKIVOYAGE_FILE == this) { + return IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT; } else if (LIVE_UPDATES_FILE == this) { return BINARY_MAP_INDEX_EXT; } else if (HILLSHADE_FILE == this) { @@ -212,6 +220,8 @@ public class DownloadActivityType { return "&srtmcountry=yes"; } else if (this == WIKIPEDIA_FILE) { return "&wiki=yes"; + } else if (this == WIKIVOYAGE_FILE) { + return "&wikivoyage=yes"; } else if (this == HILLSHADE_FILE) { return "&hillshade=yes"; } else if (this == FONT_FILE) { @@ -269,6 +279,8 @@ public class DownloadActivityType { return ctx.getString(R.string.download_srtm_maps); } else if (this == WIKIPEDIA_FILE) { return ctx.getString(R.string.shared_string_wikipedia); + } else if (this == WIKIVOYAGE_FILE) { + return ctx.getString(R.string.shared_string_wikivoyage); } else if (this == ROADS_FILE) { return ctx.getString(R.string.download_roads_only_item); } else if (this == DEPTH_CONTOUR_FILE) { @@ -356,6 +368,10 @@ public class DownloadActivityType { if (this == WIKIPEDIA_FILE) { return baseNameWithoutVersion + IndexConstants.BINARY_WIKI_MAP_INDEX_EXT; } + if (this == WIKIVOYAGE_FILE) { + return baseNameWithoutVersion + IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT; + } + if (this == ROADS_FILE) { return baseNameWithoutVersion + IndexConstants.BINARY_ROAD_MAP_INDEX_EXT; } @@ -383,6 +399,10 @@ public class DownloadActivityType { if (fileName.endsWith(IndexConstants.SQLITE_EXT)) { return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()); } + if (indexItem.getType() == WIKIVOYAGE_FILE && + fileName.endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) { + return fileName.substring(0, fileName.length() - IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT.length()); + } if (this == VOICE_FILE) { int l = fileName.lastIndexOf('_'); if (l == -1) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java index fc4b902b9c..2aef38aa1f 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadFileHelper.java @@ -205,7 +205,7 @@ public class DownloadFileHelper { try { final List downloadInputStreams = new ArrayList(); URL url = new URL(de.urlToDownload); //$NON-NLS-1$ - log.debug("Url downloading " + de.urlToDownload); + log.info("Url downloading " + de.urlToDownload); downloadInputStreams.add(getInputStreamToDownload(url, forceWifi)); de.fileToDownload = de.targetFile; if(!de.unzipFolder) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index 433f929d3d..822bfe91fc 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -204,7 +204,7 @@ public class DownloadOsmandIndexesHelper { DownloadActivityType tp = DownloadActivityType.getIndexType(parser.getAttributeValue(null, "type")); if (tp != null) { IndexItem it = tp.parseIndexItem(ctx, parser); - if(it != null && !it.getFileName().contains("_wiki")) { + if(it != null) { result.add(it); } } else if ("osmand_regions".equals(parser.getName())) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java index e1ea3a0c60..d95d45acd1 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java @@ -34,6 +34,8 @@ public class DownloadResourceGroup { SRTM_HEADER(R.string.download_srtm_maps), HILLSHADE_HEADER(R.string.download_hillshade_maps), OTHER_MAPS_HEADER(R.string.download_select_map_types), + WIKIVOYAGE_HEADER(R.string.shared_string_wikivoyage), + NAUTICAL_MAPS_HEADER(R.string.nautical_maps), // headers with voice items VOICE_HEADER_TTS(R.string.index_name_tts_voice), @@ -42,11 +44,13 @@ public class DownloadResourceGroup { FONTS_HEADER(R.string.fonts_header), // headers with resources NAUTICAL_MAPS_GROUP(R.string.nautical_maps), + TRAVEL_GROUP(R.string.download_maps_travel), OTHER_MAPS_GROUP(R.string.download_select_map_types), OTHER_GROUP(R.string.other_menu_group), SUBREGIONS(R.string.regions), // screen items NAUTICAL_MAPS(R.string.nautical_maps), + WIKIVOYAGE_MAPS(R.string.download_maps_travel), VOICE_TTS(R.string.index_name_tts_voice), FONTS(R.string.fonts_header), VOICE_REC(R.string.index_name_voice), @@ -62,7 +66,7 @@ public class DownloadResourceGroup { public boolean isScreen() { return this == WORLD || this == REGION || this == VOICE_TTS - || this == VOICE_REC || this == OTHER_MAPS || this == FONTS || this == NAUTICAL_MAPS; + || this == VOICE_REC || this == OTHER_MAPS || this == FONTS || this == NAUTICAL_MAPS || this == WIKIVOYAGE_MAPS; } public String getDefaultId() { @@ -75,15 +79,17 @@ public class DownloadResourceGroup { public boolean containsIndexItem() { return isHeader() && this != SUBREGIONS && this != OTHER_GROUP && this != OTHER_MAPS_GROUP - && this != NAUTICAL_MAPS_GROUP; + && this != NAUTICAL_MAPS_GROUP && this != TRAVEL_GROUP; } public boolean isHeader() { return this == VOICE_HEADER_REC || this == VOICE_HEADER_TTS || this == SUBREGIONS - || this == WORLD_MAPS || this == REGION_MAPS || this == OTHER_GROUP + || this == WORLD_MAPS || this == REGION_MAPS || this == OTHER_GROUP || this == HILLSHADE_HEADER || this == SRTM_HEADER || this == OTHER_MAPS_HEADER || this == OTHER_MAPS_GROUP - || this == FONTS_HEADER || this == NAUTICAL_MAPS_HEADER || this == NAUTICAL_MAPS_GROUP; + || this == FONTS_HEADER + || this == NAUTICAL_MAPS_HEADER || this == NAUTICAL_MAPS_GROUP + || this == WIKIVOYAGE_HEADER || this == TRAVEL_GROUP; } public static String getVoiceTTSId() { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 78ece750e8..41eedd613f 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -1,6 +1,7 @@ package net.osmand.plus.download; import net.osmand.IndexConstants; +import net.osmand.PlatformUtil; import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.LatLon; @@ -22,6 +23,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.apache.commons.logging.Log; + public class DownloadResources extends DownloadResourceGroup { public boolean isDownloadedFromInternet = false; public boolean downloadFromInternetFailed = false; @@ -36,6 +39,8 @@ public class DownloadResources extends DownloadResourceGroup { public static final String WORLD_SEAMARKS_NAME = "World_seamarks"; public static final String WORLD_SEAMARKS_OLD_KEY = "world_seamarks_basemap"; public static final String WORLD_SEAMARKS_OLD_NAME = "World_seamarks_basemap"; + private static final Log LOG = PlatformUtil.getLog(DownloadResources.class); + public DownloadResources(OsmandApplication app) { @@ -98,10 +103,14 @@ public class DownloadResources extends DownloadResourceGroup { java.text.DateFormat dateFormat = app.getResourceManager().getDateFormat(); Map indexActivatedFileNames = app.getResourceManager().getIndexFileNames(); listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT, indexActivatedFileNames); + listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT, + indexActivatedFileNames); Map indexFileNames = app.getResourceManager().getIndexFileNames(); listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT, indexFileNames); listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.TILES_INDEX_DIR), IndexConstants.SQLITE_EXT, indexFileNames); + listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT, + indexFileNames); app.getResourceManager().getBackupIndexes(indexFileNames); this.indexFileNames = indexFileNames; this.indexActivatedFileNames = indexActivatedFileNames; @@ -140,6 +149,7 @@ public class DownloadResources extends DownloadResourceGroup { if ((item.getType() == DownloadActivityType.NORMAL_FILE && !item.extra) || item.getType() == DownloadActivityType.ROADS_FILE || item.getType() == DownloadActivityType.WIKIPEDIA_FILE + || item.getType() == DownloadActivityType.WIKIVOYAGE_FILE || item.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE || item.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) { outdated = true; @@ -268,6 +278,10 @@ public class DownloadResources extends DownloadResourceGroup { DownloadResourceGroup nauticalMapsGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.NAUTICAL_MAPS_GROUP); DownloadResourceGroup nauticalMapsScreen = new DownloadResourceGroup(nauticalMapsGroup, DownloadResourceGroupType.NAUTICAL_MAPS); DownloadResourceGroup nauticalMaps = new DownloadResourceGroup(nauticalMapsGroup, DownloadResourceGroupType.NAUTICAL_MAPS_HEADER); + + DownloadResourceGroup wikivoyageMapsGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.TRAVEL_GROUP); + DownloadResourceGroup wikivoyageMapsScreen = new DownloadResourceGroup(wikivoyageMapsGroup, DownloadResourceGroupType.WIKIVOYAGE_MAPS); + DownloadResourceGroup wikivoyageMaps = new DownloadResourceGroup(wikivoyageMapsGroup, DownloadResourceGroupType.WIKIVOYAGE_HEADER); Map > groupByRegion = new LinkedHashMap>(); OsmandRegions regs = app.getRegions(); @@ -290,6 +304,10 @@ public class DownloadResources extends DownloadResourceGroup { } continue; } + if(ii.getType() == DownloadActivityType.WIKIVOYAGE_FILE) { + wikivoyageMaps.addItem(ii); + continue; + } String basename = ii.getBasename().toLowerCase(); WorldRegion wg = regs.getRegionDataByDownloadName(basename); if (wg != null) { @@ -354,6 +372,10 @@ public class DownloadResources extends DownloadResourceGroup { nauticalMapsGroup.addGroup(nauticalMapsScreen); addGroup(nauticalMapsGroup); + wikivoyageMapsScreen.addGroup(wikivoyageMaps); + wikivoyageMapsGroup.addGroup(wikivoyageMapsScreen); + addGroup(wikivoyageMapsGroup); + if (otherMaps.size() > 0) { addGroup(otherMapsGroup); } @@ -365,6 +387,8 @@ public class DownloadResources extends DownloadResourceGroup { } otherGroup.addGroup(voiceScreenTTS); otherGroup.addGroup(voiceScreenRec); + + if (fonts.getIndividualResources() != null) { otherGroup.addGroup(fontScreen); } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index ab9dc902d1..732424eeeb 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -405,6 +405,8 @@ public class ItemViewHolder { tp = LocalIndexType.SRTM_DATA; } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE) { tp = LocalIndexType.MAP_DATA; + } else if (indexItem.getType() == DownloadActivityType.WIKIVOYAGE_FILE) { + tp = LocalIndexType.MAP_DATA; } else if (indexItem.getType() == DownloadActivityType.FONT_FILE) { tp = LocalIndexType.FONT_DATA; } else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index 8dae91467b..92279c2d80 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -183,7 +183,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement } }; if (info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA || - info.getType() == LocalIndexType.WIKI_DATA) { + info.getType() == LocalIndexType.WIKI_DATA ) { if (!info.isBackupedData()) { adapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.local_index_mi_backup, getContext()) @@ -444,6 +444,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement parent = getMyApplication().getAppPath(IndexConstants.SRTM_INDEX_DIR); } else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) { parent = getMyApplication().getAppPath(IndexConstants.WIKI_INDEX_DIR); + } else if (i.getOriginalType() == LocalIndexType.TRAVEL_DATA) { + parent = getMyApplication().getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR); } else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA) { parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR); } else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java index 7ac6a82ed8..30d7b2a730 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java @@ -220,6 +220,8 @@ public class FileNameTranslationHelper { } else if (basename.equals(DownloadResources.WORLD_SEAMARKS_KEY) || basename.equals(DownloadResources.WORLD_SEAMARKS_OLD_KEY)) { return ctx.getString(R.string.index_item_world_seamarks); + } else if (basename.equals("world_wikivoyage")) { + return ctx.getString(R.string.index_item_world_wikivoyage); } else if (basename.equals("depth_contours_osmand_ext")) { return ctx.getString(R.string.index_item_depth_contours_osmand_ext); } else if (basename.equals("depth_points_southern_hemisphere_osmand_ext")) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java index 4001ed8e8f..3070e89739 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java @@ -537,6 +537,8 @@ public class MapDataMenuController extends MenuController { parent = app.getAppPath(IndexConstants.SRTM_INDEX_DIR); } else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) { parent = app.getAppPath(IndexConstants.WIKI_INDEX_DIR); + } else if (i.getOriginalType() == LocalIndexType.TRAVEL_DATA) { + parent = app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR); } else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA) { parent = app.getAppPath(IndexConstants.VOICE_INDEX_DIR); } else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) { @@ -561,6 +563,8 @@ public class MapDataMenuController extends MenuController { return DownloadActivityType.SRTM_COUNTRY_FILE; } else if (localIndexInfo.getOriginalType() == LocalIndexType.WIKI_DATA) { return DownloadActivityType.WIKIPEDIA_FILE; + } else if (localIndexInfo.getOriginalType() == LocalIndexType.TRAVEL_DATA) { + return DownloadActivityType.WIKIVOYAGE_FILE; } else if (localIndexInfo.getOriginalType() == LocalIndexType.TTS_VOICE_DATA || localIndexInfo.getOriginalType() == LocalIndexType.VOICE_DATA) { return DownloadActivityType.VOICE_FILE; diff --git a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java index c4dd143493..67d484259d 100644 --- a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java +++ b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java @@ -41,6 +41,8 @@ public class RendererRegistry { public final static String NAUTICAL_RENDER = "Nautical"; //$NON-NLS-1$ public final static String TOPO_RENDER = "Topo"; //$NON-NLS-1$ public final static String MAPNIK_RENDER = "Mapnik"; //$NON-NLS-1$ + public final static String OFFROAD_RENDER = "Offroad"; //$NON-NLS-1$ + public final static String LIGHTRS_RENDER = "LightRS"; //$NON-NLS-1$ private RenderingRulesStorage defaultRender = null; private RenderingRulesStorage currentSelectedRender = null; @@ -64,10 +66,10 @@ public class RendererRegistry { internalRenderers.put(TOURING_VIEW, "Touring-view_(more-contrast-and-details)" +".render.xml"); internalRenderers.put(TOPO_RENDER, "topo" + ".render.xml"); internalRenderers.put(MAPNIK_RENDER, "mapnik" + ".render.xml"); - internalRenderers.put("UniRS", "UniRS" + ".render.xml"); - internalRenderers.put("LightRS", "LightRS" + ".render.xml"); + internalRenderers.put(LIGHTRS_RENDER, "LightRS" + ".render.xml"); internalRenderers.put(NAUTICAL_RENDER, "nautical" + ".render.xml"); internalRenderers.put(WINTER_SKI_RENDER, "skimap" + ".render.xml"); + internalRenderers.put(OFFROAD_RENDER, "offroad" + ".render.xml"); } public RenderingRulesStorage defaultRender() { diff --git a/OsmAnd/src/net/osmand/plus/widgets/tools/CropRectTransformation.java b/OsmAnd/src/net/osmand/plus/widgets/tools/CropRectTransformation.java new file mode 100644 index 0000000000..6a3af820cf --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/widgets/tools/CropRectTransformation.java @@ -0,0 +1,30 @@ +package net.osmand.plus.widgets.tools; + +import android.graphics.Bitmap; + +import com.squareup.picasso.Transformation; + +public class CropRectTransformation implements Transformation { + + private static final String KEY = "CropRectTransformation"; + + @Override + public Bitmap transform(Bitmap source) { + int size = Math.min(source.getWidth(), source.getHeight()); + + int x = (source.getWidth() - size * 2) / 2; + int y = (source.getHeight() - size) / 2; + + Bitmap bitmap = Bitmap.createBitmap(source, x, y, size * 2, size); + if (bitmap != source) { + source.recycle(); + } + + return bitmap; + } + + @Override + public String key() { + return KEY; + } +} diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java index b68f09ce6d..6d0e9d6c5b 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java @@ -10,11 +10,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ExpandableListView; -import android.widget.ExpandableListView.OnGroupClickListener; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import net.osmand.AndroidUtils; import net.osmand.plus.R; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.base.MenuBottomSheetDialogFragment; @@ -36,6 +35,8 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag public static final int REQUEST_LINK_CODE = 0; + private ExpandableListView expListView; + private LinkedHashMap map; private String link; @@ -63,11 +64,14 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag items.add(new TitleItem(getString(R.string.shared_string_contents))); - ExpandableListView expListView = new ExpandableListView(getContext()); + expListView = new ExpandableListView(getContext()); ExpandableListAdapter listAdapter = new ExpandableListAdapter(getContext(), listDataHeader, listDataChild); expListView.setAdapter(listAdapter); - expListView.setChildDivider(ContextCompat.getDrawable(getContext(), R.color.color_transparent)); + Drawable transparent = ContextCompat.getDrawable(getContext(), R.color.color_transparent); + expListView.setDivider(transparent); + expListView.setGroupIndicator(transparent); + expListView.setSelector(transparent); expListView.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT) @@ -83,23 +87,12 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag return false; } }); - - int width = AndroidUtils.getScreenWidth(getActivity()); - if (android.os.Build.VERSION.SDK_INT < 18) { - expListView.setIndicatorBounds(width - (AndroidUtils.dpToPx(getContext(), 50)), - width - (AndroidUtils.dpToPx(getContext(), 10))); - } else { - expListView.setIndicatorBoundsRelative(width - (AndroidUtils.dpToPx(getContext(), 50)), - width - (AndroidUtils.dpToPx(getContext(), 10))); - } - expListView.setOnGroupClickListener(new OnGroupClickListener() { + expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { link = map.get(listDataHeader.get(groupPosition)); sendResult(); - if (listDataChild.get(listDataHeader.get(groupPosition)) == null) { - dismiss(); - } + dismiss(); return false; } }); @@ -158,7 +151,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag @Override public Object getChild(int groupPosition, int childPosititon) { - return this.listDataChild.get(this.listDataHeader.get(groupPosition)).get(childPosititon); + return listDataChild.get(listDataHeader.get(groupPosition)).get(childPosititon); } @Override @@ -181,6 +174,14 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag : R.color.wikivoyage_contents_parent_icon_light)); txtListChild.setCompoundDrawablesWithIntrinsicBounds(itemChildIcon, null, null, null); + convertView.findViewById(R.id.upper_row_divider).setVisibility(View.GONE); + txtListChild.setTypeface(null); + if (childPosition == listDataChild.get(listDataHeader.get(groupPosition)).size() - 1) { + convertView.findViewById(R.id.bottom_row_divider).setVisibility(View.VISIBLE); + } else { + convertView.findViewById(R.id.bottom_row_divider).setVisibility(View.GONE); + } + return convertView; } @@ -206,18 +207,36 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag } @Override - public View getGroupView(int groupPosition, boolean isExpanded, - View convertView, ViewGroup parent) { + public View getGroupView(final int groupPosition, final boolean isExpanded, + View convertView, ViewGroup parent) { String headerTitle = (String) getGroup(groupPosition); if (convertView == null) { convertView = LayoutInflater.from(context) .inflate(R.layout.wikivoyage_contents_list_item, parent, false); } + boolean light = getMyApplication().getSettings().isLightContent(); TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label); lblListHeader.setText(headerTitle); lblListHeader.setTextColor(getResolvedColor(isNightMode() ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light)); lblListHeader.setCompoundDrawablesWithIntrinsicBounds(itemGroupIcon, null, null, null); + adjustIndicator(getMyApplication(), groupPosition, isExpanded, convertView, light); + ImageView indicator = (ImageView) convertView.findViewById(R.id.explist_indicator); + indicator.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(isExpanded){ + expListView.collapseGroup(groupPosition); + } else { + expListView.expandGroup(groupPosition); + } + } + }); + if (isExpanded) { + convertView.findViewById(R.id.bottom_row_divider).setVisibility(View.GONE); + } else { + convertView.findViewById(R.id.bottom_row_divider).setVisibility(View.VISIBLE); + } return convertView; } @@ -231,4 +250,4 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag return true; } } -} +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java index 2cd8325b88..a00faa83d7 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java @@ -2,7 +2,6 @@ package net.osmand.plus.wikivoyage.data; import android.support.annotation.NonNull; import android.support.annotation.Nullable; - import net.osmand.Collator; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; @@ -65,18 +64,56 @@ public class WikivoyageDbHelper { private static final String SEARCH_COL_LANG = "lang"; private final OsmandApplication application; - + private SQLiteConnection connection = null; + private File selectedTravelBook = null; + private List existingTravelBooks = new ArrayList(); private Collator collator; public WikivoyageDbHelper(OsmandApplication application) { this.application = application; collator = OsmAndCollator.primaryCollator(); + initTravelBooks(); + } + + public void initTravelBooks() { + File[] possibleFiles = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles(); + String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get(); + if (possibleFiles != null) { + for (File f : possibleFiles) { + if (f.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) { + existingTravelBooks.add(f); + if (selectedTravelBook == null) { + selectedTravelBook = f; + } else if (Algorithms.objectEquals(travelBook, f.getName())) { + selectedTravelBook = f; + } + } + } + } + } + + public File getSelectedTravelBook() { + return selectedTravelBook; + } + + public List getExistingTravelBooks() { + return existingTravelBooks; } @Nullable private SQLiteConnection openConnection() { - String path = getDbFile(application).getAbsolutePath(); - return application.getSQLiteAPI().openByAbsolutePath(path, true); + if(connection == null && selectedTravelBook != null) { + application.getSettings().SELECTED_TRAVEL_BOOK.set(selectedTravelBook.getName()); + connection = application.getSQLiteAPI().openByAbsolutePath(selectedTravelBook.getAbsolutePath(), true); + } + return connection; + } + + public void closeConnection() { + if(connection != null) { + connection.close(); + connection = null; + } } @NonNull @@ -85,42 +122,39 @@ public class WikivoyageDbHelper { SQLiteConnection conn = openConnection(); String[] queries = searchQuery.replace('_', ' ').replace('/', ' ').split(" "); if (conn != null) { - try { - List params = new ArrayList<>(); - String query = "SELECT distinct wa.city_id, wa.title, wa.lang, wa.is_part_of, wa.image_title " + - "FROM wikivoyage_articles wa WHERE wa.city_id in " + - " (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE"; - for (String q : queries) { - if (q.trim().length() > 0) { - if (params.size() > 5) { - // don't explode the query search much - break; - } - if (params.size() > 0) { - query += " AND city_id IN (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE ?) "; - } else { - query += "?"; - } - params.add(q.trim() + "%"); + List params = new ArrayList<>(); + String query = "SELECT distinct wa.city_id, wa.title, wa.lang, wa.is_part_of, wa.image_title " + + "FROM wikivoyage_articles wa WHERE wa.city_id in " + + " (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE"; + for (String q : queries) { + if (q.trim().length() > 0) { + if (params.size() > 5) { + // don't explode the query search much + break; } - } - query += ") "; - if (params.size() > 0) { - SQLiteCursor cursor = conn.rawQuery(query, params.toArray(new String[params.size()])); - if (cursor.moveToFirst()) { - do { - WikivoyageSearchResult rs = new WikivoyageSearchResult(); - rs.cityId = cursor.getLong(0); - rs.articleTitles.add(cursor.getString(1)); - rs.langs.add(cursor.getString(2)); - rs.isPartOf = cursor.getString(3); - rs.imageTitle = cursor.getString(4); - res.add(rs); - } while (cursor.moveToNext()); + if (params.size() > 0) { + query += " AND city_id IN (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE ?) "; + } else { + query += "?"; } + params.add(q.trim() + "%"); } - } finally { - conn.close(); + } + query += ") "; + if (params.size() > 0) { + SQLiteCursor cursor = conn.rawQuery(query, params.toArray(new String[params.size()])); + if (cursor.moveToFirst()) { + do { + WikivoyageSearchResult rs = new WikivoyageSearchResult(); + rs.cityId = cursor.getLong(0); + rs.articleTitles.add(cursor.getString(1)); + rs.langs.add(cursor.getString(2)); + rs.isPartOf = cursor.getString(3); + rs.imageTitle = cursor.getString(4); + res.add(rs); + } while (cursor.moveToNext()); + } + cursor.close(); } } @@ -180,18 +214,12 @@ public class WikivoyageDbHelper { WikivoyageArticle res = null; SQLiteConnection conn = openConnection(); if (conn != null) { - try { - SQLiteCursor cursor = conn.rawQuery(ARTICLES_TABLE_SELECT + " WHERE " + - ARTICLES_COL_CITY_ID + " = ? AND " + - ARTICLES_COL_LANG + " = ?", - new String[]{String.valueOf(cityId), lang}); - if (cursor.moveToFirst()) { - res = readArticle(cursor); - } - cursor.close(); - } finally { - conn.close(); + SQLiteCursor cursor = conn.rawQuery(ARTICLES_TABLE_SELECT + " WHERE " + ARTICLES_COL_CITY_ID + " = ? AND " + + ARTICLES_COL_LANG + " = ?", new String[] { String.valueOf(cityId), lang }); + if (cursor.moveToFirst()) { + res = readArticle(cursor); } + cursor.close(); } return res; } @@ -201,31 +229,27 @@ public class WikivoyageDbHelper { ArrayList res = new ArrayList<>(); SQLiteConnection conn = openConnection(); if (conn != null) { - try { - SQLiteCursor cursor = conn.rawQuery("SELECT " + ARTICLES_COL_LANG + - " FROM " + ARTICLES_TABLE_NAME + - " WHERE " + ARTICLES_COL_CITY_ID + " = ?", - new String[]{String.valueOf(cityId)}); - if (cursor.moveToFirst()) { - String baseLang = application.getLanguage(); - do { - String lang = cursor.getString(0); - if (lang.equals(baseLang)) { - res.add(0, lang); - } else if (lang.equals("en")) { - if (res.size() > 0 && res.get(0).equals(baseLang)) { - res.add(1, lang); - } else { - res.add(0, lang); - } + SQLiteCursor cursor = conn.rawQuery("SELECT " + ARTICLES_COL_LANG + " FROM " + ARTICLES_TABLE_NAME + + " WHERE " + ARTICLES_COL_CITY_ID + " = ?", new String[] { String.valueOf(cityId) }); + if (cursor.moveToFirst()) { + String baseLang = application.getLanguage(); + do { + String lang = cursor.getString(0); + if (lang.equals(baseLang)) { + res.add(0, lang); + } else if (lang.equals("en")) { + if (res.size() > 0 && res.get(0).equals(baseLang)) { + res.add(1, lang); } else { - res.add(lang); + res.add(0, lang); } - } while (cursor.moveToNext()); - } - } finally { - conn.close(); + } else { + res.add(lang); + } + } while (cursor.moveToNext()); } + cursor.close(); + } return res; } @@ -255,12 +279,8 @@ public class WikivoyageDbHelper { return res; } - public static boolean isDbFileExists(OsmandApplication app) { - return getDbFile(app).exists(); + public boolean isDbFileExists() { + return selectedTravelBook != null; } - @NonNull - private static File getDbFile(OsmandApplication app) { - return app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR + DB_NAME); - } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index 797e64cda9..b4391c4169 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -19,6 +19,7 @@ import net.osmand.plus.IconsCache; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.widgets.tools.CropCircleTransformation; +import net.osmand.plus.widgets.tools.CropRectTransformation; import net.osmand.plus.wikivoyage.data.WikivoyageArticle; import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper; @@ -30,6 +31,8 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter items = new ArrayList<>(); @@ -56,7 +59,9 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter