Update wikivoyage

This commit is contained in:
Victor Shcherb 2018-04-12 01:43:32 +02:00
parent 7bccecd6a5
commit 0f29a38d0e
7 changed files with 66 additions and 23 deletions

View file

@ -311,6 +311,8 @@
<string name="depth_contour_descr">Sea depth contour lines and nautical point maps.</string>
<string name="sea_depth_thanks">Thank you for purchasing nautical depth contours</string>
<string name="index_item_depth_contours_osmand_ext">Nautical depth contours</string>
<string name="index_item_world_wikivoyage">Worldwide Wikivoyage articles</string>
<string name="index_item_depth_points_southern_hemisphere">Southern hemisphere nautical depth points </string>
<string name="index_item_depth_points_northern_hemisphere">Northern hemisphere nautical depth points</string>
<string name="download_depth_countours">Nautical depth contours</string>

View file

@ -2998,6 +2998,8 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> FOLLOW_THE_ROUTE = new BooleanPreference("follow_to_route", false).makeGlobal();
public final OsmandPreference<String> FOLLOW_THE_GPX_ROUTE = new StringPreference("follow_gpx", null).makeGlobal();
public final OsmandPreference<String> SELECTED_TRAVEL_BOOK = new StringPreference("selected_travel_book", "").makeGlobal();
public final ListStringPreference TRANSPORT_DEFAULT_SETTINGS =
(ListStringPreference) new ListStringPreference("transport_default_settings", "transportStops", ",").makeProfile();

View file

@ -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)
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<ContextMenuItem> 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)

View file

@ -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())) {

View file

@ -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) {

View file

@ -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")) {

View file

@ -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<File> existingTravelBooks = new ArrayList<File>();
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<File> 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
@ -255,12 +292,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);
}
}