Add saved custom poi filters to the search history

This commit is contained in:
Alex Sytnyk 2018-09-24 18:11:39 +03:00
parent 181382dccd
commit 761d6974b1
4 changed files with 26 additions and 3 deletions

View file

@ -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;

View file

@ -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<HistoryEntry> getHistoryEntries() {
if (loadedEntries == null) {
checkLoadedEntries();

View file

@ -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;

View file

@ -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());