From 761d6974b19f0f882218d503c5a69a9b572abdd1 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Mon, 24 Sep 2018 18:11:39 +0300 Subject: [PATCH] Add saved custom poi filters to the search history --- OsmAnd/src/net/osmand/data/PointDescription.java | 5 +++++ .../osmand/plus/helpers/SearchHistoryHelper.java | 6 ++++++ .../plus/search/QuickSearchDialogFragment.java | 3 +++ .../net/osmand/plus/search/QuickSearchHelper.java | 15 ++++++++++++--- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index fd5e406b41..da52048eb3 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -48,6 +48,7 @@ public class PointDescription { public static final String POINT_TYPE_TRANSPORT_STOP = "transport_stop"; public static final String POINT_TYPE_MAPILLARY_IMAGE = "mapillary_image"; public static final String POINT_TYPE_POI_TYPE = "poi_type"; + public static final String POINT_TYPE_CUSTOM_POI_FILTER = "custom_poi_filter"; public static final PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, ""); @@ -259,6 +260,10 @@ public class PointDescription { return POINT_TYPE_POI_TYPE.equals(type); } + public boolean isCustomPoiFilter() { + return POINT_TYPE_CUSTOM_POI_FILTER.equals(type); + } + @Override public int hashCode() { final int prime = 31; diff --git a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java index 6f33854f4c..d4be80a186 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/SearchHistoryHelper.java @@ -6,6 +6,7 @@ import net.osmand.osm.AbstractPoiType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; +import net.osmand.plus.poi.PoiUIFilter; import net.osmand.util.Algorithms; import java.util.ArrayList; @@ -48,6 +49,11 @@ public class SearchHistoryHelper { addNewItemToHistory(new HistoryEntry(0, 0, pd)); } + public void addNewItemToHistory(PoiUIFilter filter) { + PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_CUSTOM_POI_FILTER, filter.getFilterId()); + addNewItemToHistory(new HistoryEntry(0, 0, pd)); + } + public List getHistoryEntries() { if (loadedEntries == null) { checkLoadedEntries(); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 1cc5dab5b2..452bf88c7c 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -1776,6 +1776,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC if (sr.object instanceof AbstractPoiType) { SearchHistoryHelper.getInstance(app).addNewItemToHistory((AbstractPoiType) sr.object); reloadHistory(); + } else if (sr.object instanceof PoiUIFilter) { + SearchHistoryHelper.getInstance(app).addNewItemToHistory((PoiUIFilter) sr.object); + reloadHistory(); } if (sr.object instanceof PoiType && ((PoiType) sr.object).isAdditional()) { PoiType additional = (PoiType) sr.object; diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index ffe0d8361c..910ba6023b 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -7,6 +7,7 @@ import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter; import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; @@ -399,16 +400,24 @@ public class QuickSearchHelper implements ResourceListener { int p = 0; for (HistoryEntry point : SearchHistoryHelper.getInstance(app).getHistoryEntries()) { SearchResult sr = new SearchResult(phrase); - if (point.getName().isPoiType()) { - AbstractPoiType pt = MapPoiTypes.getDefault().getAnyPoiTypeByKey(point.getName().getName()); + PointDescription pd = point.getName(); + if (pd.isPoiType()) { + AbstractPoiType pt = MapPoiTypes.getDefault().getAnyPoiTypeByKey(pd.getName()); if (pt != null) { sr.localeName = pt.getTranslation(); sr.object = pt; sr.priorityDistance = 0; sr.objectType = ObjectType.POI_TYPE; } + } else if (pd.isCustomPoiFilter()) { + PoiUIFilter filter = app.getPoiFilters().getFilterById(pd.getName()); + if (filter != null) { + sr.localeName = filter.getName(); + sr.object = filter; + sr.objectType = ObjectType.POI_TYPE; + } } else { - sr.localeName = point.getName().getName(); + sr.localeName = pd.getName(); sr.object = point; sr.objectType = ObjectType.RECENT_OBJ; sr.location = new LatLon(point.getLat(), point.getLon());