From 297a9977616485254a48dac0abebf5484d90ee0f Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 2 Jul 2015 18:32:02 +0200 Subject: [PATCH] update poi types selection (taking into account map=true) elements --- .../src/net/osmand/osm/MapPoiTypes.java | 26 ++++++++++++++++--- .../activities/EditPOIFilterActivity.java | 2 +- .../osmedit/EditingPOIDialogProvider.java | 2 +- .../src/net/osmand/plus/poi/PoiUIFilter.java | 4 +-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java index 7ea871c5c2..caa6b37a08 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java @@ -28,6 +28,7 @@ public class MapPoiTypes { private String resourceName; private List categories = new ArrayList(); private PoiCategory otherCategory; + private PoiCategory otherMapCategory; static final String OSM_WIKI_CATEGORY = "osmwiki"; private PoiTranslator poiTranslator = null; @@ -67,6 +68,13 @@ public class MapPoiTypes { return otherCategory; } + public PoiCategory getOtherMapCategory() { + if(otherMapCategory == null) { + otherMapCategory = getPoiCategoryByName("Other", true); + } + return otherMapCategory; + } + public List getTopVisibleFilters() { List lf = new ArrayList(); for(PoiCategory pc : categories) { @@ -143,6 +151,9 @@ public class MapPoiTypes { public Map getAllTypesTranslatedNames(StringMatcher matcher) { TreeMap tm = new TreeMap(Collator.getInstance()); for (PoiCategory pc : categories) { + if(pc == otherMapCategory) { + continue; + } addIf(tm, pc, matcher); for (PoiFilter pt : pc.getPoiFilters()) { addIf(tm, pt, matcher); @@ -290,6 +301,9 @@ public class MapPoiTypes { lastFilter.addPoiType(tp); } allTypes.put(tp.getKeyName(), tp); + if(lastCategory == null) { + lastCategory = getOtherMapCategory(); + } lastCategory.addPoiType(tp); } } else if (tok == XmlPullParser.END_TAG) { @@ -298,6 +312,8 @@ public class MapPoiTypes { lastFilter = null; } else if (name.equals("poi_type")) { lastType = null; + } else if (name.equals("poi_category")) { + lastCategory = null; } } } @@ -336,13 +352,17 @@ public class MapPoiTypes { otherCategory = pc; } - public List getCategories() { - return categories; + public List getCategories(boolean includeMapCategory) { + ArrayList lst = new ArrayList(categories); + if(!includeMapCategory) { + lst.remove(getOtherMapCategory()); + } + return lst; } private static void print(MapPoiTypes df) { - List pc = df.getCategories(); + List pc = df.getCategories(true); for(PoiCategory p : pc) { System.out.println("Category " + p.getKeyName()); for(PoiFilter f : p.getPoiFilters()) { diff --git a/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java b/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java index b2036460d7..164788e68c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditPOIFilterActivity.java @@ -74,7 +74,7 @@ public class EditPOIFilterActivity extends OsmandListActivity { if (filter != null) { getSupportActionBar().setSubtitle(filter.getName()); - setListAdapter(new AmenityAdapter( ((OsmandApplication) getApplication()).getPoiTypes().getCategories())); + setListAdapter(new AmenityAdapter( ((OsmandApplication) getApplication()).getPoiTypes().getCategories(false))); } else { setListAdapter(new AmenityAdapter(new ArrayList())); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java index c025be53c7..456f0441c7 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIDialogProvider.java @@ -731,7 +731,7 @@ public class EditingPOIDialogProvider implements DialogProvider { case DIALOG_POI_TYPES: { final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); Builder builder = new AlertDialog.Builder(activity); - final List categories = poiTypes.getCategories(); + final List categories = poiTypes.getCategories(true); String[] vals = new String[categories.size()]; for (int i = 0; i < vals.length; i++) { vals[i] = categories.get(i).getTranslation(); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index 44dab8a144..8d4f6d6642 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -167,7 +167,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter { } private void initSearchAll(){ - for(PoiCategory t : poiTypes.getCategories()){ + for(PoiCategory t : poiTypes.getCategories(false)){ acceptedTypes.put(t, null); } distanceToSearchValues = new double[] {0.5, 1, 2, 5, 10, 20, 50, 100}; @@ -436,7 +436,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter { } public boolean areAllTypesAccepted(){ - if(poiTypes.getCategories().size() == acceptedTypes.size()){ + if(poiTypes.getCategories(false).size() == acceptedTypes.size()){ for(PoiCategory a : acceptedTypes.keySet()){ if(acceptedTypes.get(a) != null){ return false;