diff --git a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java index 82d73ed67f..9fa5bd70b2 100644 --- a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java +++ b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java @@ -3,7 +3,6 @@ package net.osmand.plus.render; import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; - import net.osmand.IProgress; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; @@ -25,9 +24,11 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Collection; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; +import java.util.Map.Entry; public class RendererRegistry { @@ -101,7 +102,23 @@ public class RendererRegistry { } private boolean hasRender(String name) { - return externalRenderers.containsKey(name) || internalRenderers.containsKey(name); + return externalRenderers.containsKey(name) || getInternalRender(name) != null; + } + + private String getInternalRender(String name) { + // check by key and by value + Iterator> mapIt = internalRenderers.entrySet().iterator(); + while(mapIt.hasNext()) { + Entry e = mapIt.next(); + if(e.getKey().equalsIgnoreCase(name)) { + return e.getValue(); + } + String simpleFileName = e.getValue().substring(0, e.getValue().indexOf('.')); + if(simpleFileName.equalsIgnoreCase(name)) { + return e.getValue(); + } + } + return null; } // private static boolean USE_PRECOMPILED_STYLE = false; @@ -180,7 +197,7 @@ public class RendererRegistry { if(externalRenderers.containsKey(name)){ is = new FileInputStream(externalRenderers.get(name)); } else { - if (!internalRenderers.containsKey(name)) { + if (getInternalRender(name) == null) { log.error("Rendering style not found: " + name); name = DEFAULT_RENDER; } @@ -189,7 +206,7 @@ public class RendererRegistry { is = new FileInputStream(fl); } else { copyFileForInternalStyle(name); - is = RenderingRulesStorage.class.getResourceAsStream(internalRenderers.get(name)); + is = RenderingRulesStorage.class.getResourceAsStream(getInternalRender(name)); } } return is; @@ -198,7 +215,7 @@ public class RendererRegistry { public void copyFileForInternalStyle(String name) { try { FileOutputStream fout = new FileOutputStream(getFileForInternalStyle(name)); - Algorithms.streamCopy(RenderingRulesStorage.class.getResourceAsStream(internalRenderers.get(name)), + Algorithms.streamCopy(RenderingRulesStorage.class.getResourceAsStream(getInternalRender(name)), fout); fout.close(); } catch (IOException e) { @@ -211,10 +228,11 @@ public class RendererRegistry { } public File getFileForInternalStyle(String name) { - if(!internalRenderers.containsKey(name)) { - return new File(app.getAppPath(IndexConstants.RENDERERS_DIR), "style.render.xml"); + String file = getInternalRender(name); + if(file == null) { + return new File(app.getAppPath(IndexConstants.RENDERERS_DIR), "default.render.xml"); } - File fl = new File(app.getAppPath(IndexConstants.RENDERERS_DIR), internalRenderers.get(name)); + File fl = new File(app.getAppPath(IndexConstants.RENDERERS_DIR), file); return fl; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java index cfdf687ce2..659f8fea6a 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java @@ -2,13 +2,13 @@ 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; import net.osmand.IndexConstants; import net.osmand.OsmAndCollator; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.util.Algorithms; @@ -71,12 +71,12 @@ public class WikivoyageDbHelper { 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(); + existingTravelBooks.clear(); if (possibleFiles != null) { for (File f : possibleFiles) { if (f.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) { @@ -292,4 +292,12 @@ public class WikivoyageDbHelper { return res; } + + public String formatTravelBookName(File tb) { + if(tb == null) { + return application.getString(R.string.shared_string_none); + } + String nm = tb.getName(); + return nm.substring(0, nm.indexOf('.')).replace('_', ' '); + } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java index b68a6f4d95..c9197b8dfe 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java @@ -1,9 +1,18 @@ package net.osmand.plus.wikivoyage.explore; +import java.io.File; +import java.util.List; + +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; +import android.support.v7.app.AlertDialog; +import android.support.v7.widget.AlertDialogLayout; import android.view.View; import android.webkit.WebView; - +import android.widget.Toast; import net.osmand.PicassoUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -15,18 +24,59 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper; import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper; public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment"; + protected void selectTravelBookDialog() { + WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper(); + final List list = dbHelper.getExistingTravelBooks(); + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + String[] ls = new String[list.size()]; + for (int i = 0; i < ls.length; i++) { + ls[i] = dbHelper.formatTravelBookName(list.get(i)); + } + builder.setTitle("Select travel book"); // TODO externalize + builder.setItems(ls, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + Toast.makeText(getMyApplication(), list.get(which).getName(), Toast.LENGTH_LONG).show(); + + } + }); + builder.setNegativeButton(R.string.shared_string_dismiss, null); + builder.show(); + + } + @Override public void createMenuItems(Bundle savedInstanceState) { final OsmandApplication app = getMyApplication(); final OsmandSettings.CommonPreference showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES; - + final WikivoyageDbHelper dbHelper = app.getWikivoyageDbHelper(); items.add(new TitleItem(getString(R.string.shared_string_options))); + + if(dbHelper.getExistingTravelBooks().size() > 1) { + BaseBottomSheetItem selectTravelBook = new BottomSheetItemWithDescription.Builder() + .setDescription(dbHelper.formatTravelBookName(dbHelper.getSelectedTravelBook())) + .setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light) + .setTitle("Travel book") // TODO think & externalize + .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + selectTravelBookDialog(); + dismiss(); + } + }) + .create(); + items.add(selectTravelBook); + + } BaseBottomSheetItem showImagesItem = new BottomSheetItemWithCompoundButton.Builder() .setChecked(showImagesPref.get()) @@ -75,4 +125,6 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD .create(); items.add(clearHistoryItem); } + + }