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.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 {
|
||||
|
@ -36,7 +37,7 @@ public class RendererRegistry {
|
|||
|
||||
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 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 NAUTICAL_RENDER = "Nautical"; //$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) {
|
||||
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;
|
||||
|
@ -179,16 +196,18 @@ public class RendererRegistry {
|
|||
}
|
||||
if(externalRenderers.containsKey(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);
|
||||
if(fl.exists()) {
|
||||
if (fl.exists()) {
|
||||
is = new FileInputStream(fl);
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
@ -196,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) {
|
||||
|
@ -209,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -200,13 +200,12 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
|
|||
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);
|
||||
adjustIndicator(getMyApplication(), groupPosition, isExpanded, convertView, !nightMode);
|
||||
ImageView indicator = (ImageView) convertView.findViewById(R.id.explist_indicator);
|
||||
indicator.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -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('_', ' ');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,19 +24,60 @@ 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<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
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
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)));
|
||||
|
||||
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())
|
||||
.setIcon(getContentIcon(R.drawable.ic_type_img))
|
||||
|
@ -75,4 +125,6 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
.create();
|
||||
items.add(clearHistoryItem);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue