Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
503b180502
4 changed files with 97 additions and 18 deletions
|
@ -3,7 +3,6 @@ package net.osmand.plus.render;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
@ -25,9 +24,11 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
|
||||||
public class RendererRegistry {
|
public class RendererRegistry {
|
||||||
|
@ -36,7 +37,7 @@ public class RendererRegistry {
|
||||||
|
|
||||||
public final static String DEFAULT_RENDER = "OsmAnd"; //$NON-NLS-1$
|
public final static String DEFAULT_RENDER = "OsmAnd"; //$NON-NLS-1$
|
||||||
public final static String DEFAULT_RENDER_FILE_PATH = "default.render.xml";
|
public final static String DEFAULT_RENDER_FILE_PATH = "default.render.xml";
|
||||||
public final static String TOURING_VIEW = "Touring view (contrast and details)"; //$NON-NLS-1$
|
public final static String TOURING_VIEW = "Touring view"; //$NON-NLS-1$
|
||||||
public final static String WINTER_SKI_RENDER = "Winter and ski"; //$NON-NLS-1$
|
public final static String WINTER_SKI_RENDER = "Winter and ski"; //$NON-NLS-1$
|
||||||
public final static String NAUTICAL_RENDER = "Nautical"; //$NON-NLS-1$
|
public final static String NAUTICAL_RENDER = "Nautical"; //$NON-NLS-1$
|
||||||
public final static String TOPO_RENDER = "Topo"; //$NON-NLS-1$
|
public final static String TOPO_RENDER = "Topo"; //$NON-NLS-1$
|
||||||
|
@ -101,7 +102,23 @@ public class RendererRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasRender(String name) {
|
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<Entry<String, String>> mapIt = internalRenderers.entrySet().iterator();
|
||||||
|
while(mapIt.hasNext()) {
|
||||||
|
Entry<String, String> 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;
|
// private static boolean USE_PRECOMPILED_STYLE = false;
|
||||||
|
@ -179,16 +196,18 @@ public class RendererRegistry {
|
||||||
}
|
}
|
||||||
if(externalRenderers.containsKey(name)){
|
if(externalRenderers.containsKey(name)){
|
||||||
is = new FileInputStream(externalRenderers.get(name));
|
is = new FileInputStream(externalRenderers.get(name));
|
||||||
} else if(internalRenderers.containsKey(name)){
|
} else {
|
||||||
|
if (getInternalRender(name) == null) {
|
||||||
|
log.error("Rendering style not found: " + name);
|
||||||
|
name = DEFAULT_RENDER;
|
||||||
|
}
|
||||||
File fl = getFileForInternalStyle(name);
|
File fl = getFileForInternalStyle(name);
|
||||||
if(fl.exists()) {
|
if (fl.exists()) {
|
||||||
is = new FileInputStream(fl);
|
is = new FileInputStream(fl);
|
||||||
} else {
|
} else {
|
||||||
copyFileForInternalStyle(name);
|
copyFileForInternalStyle(name);
|
||||||
is = RenderingRulesStorage.class.getResourceAsStream(internalRenderers.get(name));
|
is = RenderingRulesStorage.class.getResourceAsStream(getInternalRender(name));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Not found " + name); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +215,7 @@ public class RendererRegistry {
|
||||||
public void copyFileForInternalStyle(String name) {
|
public void copyFileForInternalStyle(String name) {
|
||||||
try {
|
try {
|
||||||
FileOutputStream fout = new FileOutputStream(getFileForInternalStyle(name));
|
FileOutputStream fout = new FileOutputStream(getFileForInternalStyle(name));
|
||||||
Algorithms.streamCopy(RenderingRulesStorage.class.getResourceAsStream(internalRenderers.get(name)),
|
Algorithms.streamCopy(RenderingRulesStorage.class.getResourceAsStream(getInternalRender(name)),
|
||||||
fout);
|
fout);
|
||||||
fout.close();
|
fout.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -209,10 +228,11 @@ public class RendererRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFileForInternalStyle(String name) {
|
public File getFileForInternalStyle(String name) {
|
||||||
if(!internalRenderers.containsKey(name)) {
|
String file = getInternalRender(name);
|
||||||
return new File(app.getAppPath(IndexConstants.RENDERERS_DIR), "style.render.xml");
|
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;
|
return fl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,13 +200,12 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
|
||||||
convertView = LayoutInflater.from(context)
|
convertView = LayoutInflater.from(context)
|
||||||
.inflate(R.layout.wikivoyage_contents_list_item, parent, false);
|
.inflate(R.layout.wikivoyage_contents_list_item, parent, false);
|
||||||
}
|
}
|
||||||
boolean light = getMyApplication().getSettings().isLightContent();
|
|
||||||
TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label);
|
TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label);
|
||||||
lblListHeader.setText(headerTitle);
|
lblListHeader.setText(headerTitle);
|
||||||
lblListHeader.setTextColor(getResolvedColor(isNightMode() ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));
|
lblListHeader.setTextColor(getResolvedColor(isNightMode() ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));
|
||||||
lblListHeader.setCompoundDrawablesWithIntrinsicBounds(itemGroupIcon, null, null, null);
|
lblListHeader.setCompoundDrawablesWithIntrinsicBounds(itemGroupIcon, null, null, null);
|
||||||
|
|
||||||
adjustIndicator(getMyApplication(), groupPosition, isExpanded, convertView, light);
|
adjustIndicator(getMyApplication(), groupPosition, isExpanded, convertView, !nightMode);
|
||||||
ImageView indicator = (ImageView) convertView.findViewById(R.id.explist_indicator);
|
ImageView indicator = (ImageView) convertView.findViewById(R.id.explist_indicator);
|
||||||
indicator.setOnClickListener(new View.OnClickListener() {
|
indicator.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,13 +2,13 @@ package net.osmand.plus.wikivoyage.data;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.Collator;
|
import net.osmand.Collator;
|
||||||
import net.osmand.CollatorStringMatcher;
|
import net.osmand.CollatorStringMatcher;
|
||||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.OsmAndCollator;
|
import net.osmand.OsmAndCollator;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
@ -71,12 +71,12 @@ public class WikivoyageDbHelper {
|
||||||
public WikivoyageDbHelper(OsmandApplication application) {
|
public WikivoyageDbHelper(OsmandApplication application) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
collator = OsmAndCollator.primaryCollator();
|
collator = OsmAndCollator.primaryCollator();
|
||||||
initTravelBooks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initTravelBooks() {
|
public void initTravelBooks() {
|
||||||
File[] possibleFiles = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
|
File[] possibleFiles = application.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).listFiles();
|
||||||
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
|
String travelBook = application.getSettings().SELECTED_TRAVEL_BOOK.get();
|
||||||
|
existingTravelBooks.clear();
|
||||||
if (possibleFiles != null) {
|
if (possibleFiles != null) {
|
||||||
for (File f : possibleFiles) {
|
for (File f : possibleFiles) {
|
||||||
if (f.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) {
|
if (f.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) {
|
||||||
|
@ -292,4 +292,12 @@ public class WikivoyageDbHelper {
|
||||||
|
|
||||||
return res;
|
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('_', ' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
package net.osmand.plus.wikivoyage.explore;
|
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.os.Bundle;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.support.v7.widget.AlertDialogLayout;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import android.widget.Toast;
|
||||||
import net.osmand.PicassoUtils;
|
import net.osmand.PicassoUtils;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
|
@ -15,19 +24,60 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
|
import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
|
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
|
||||||
|
|
||||||
public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment";
|
public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment";
|
||||||
|
|
||||||
|
protected void selectTravelBookDialog() {
|
||||||
|
WikivoyageDbHelper dbHelper = getMyApplication().getWikivoyageDbHelper();
|
||||||
|
final List<File> 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
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
final OsmandSettings.CommonPreference<Boolean> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
|
final OsmandSettings.CommonPreference<Boolean> showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES;
|
||||||
|
final WikivoyageDbHelper dbHelper = app.getWikivoyageDbHelper();
|
||||||
items.add(new TitleItem(getString(R.string.shared_string_options)));
|
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()
|
BaseBottomSheetItem showImagesItem = new BottomSheetItemWithCompoundButton.Builder()
|
||||||
.setChecked(showImagesPref.get())
|
.setChecked(showImagesPref.get())
|
||||||
.setIcon(getContentIcon(R.drawable.ic_type_img))
|
.setIcon(getContentIcon(R.drawable.ic_type_img))
|
||||||
|
@ -75,4 +125,6 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
||||||
.create();
|
.create();
|
||||||
items.add(clearHistoryItem);
|
items.add(clearHistoryItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue