Add categories to search history
This commit is contained in:
parent
61b076e27f
commit
cc28fa4312
4 changed files with 38 additions and 16 deletions
|
@ -1,10 +1,5 @@
|
|||
package net.osmand.data;
|
||||
|
||||
import net.osmand.LocationConvert;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -13,6 +8,12 @@ import com.google.openlocationcode.OpenLocationCode;
|
|||
import com.jwetherell.openmap.common.LatLonPoint;
|
||||
import com.jwetherell.openmap.common.UTMPoint;
|
||||
|
||||
import net.osmand.LocationConvert;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class PointDescription {
|
||||
private String type = "";
|
||||
private String name = "";
|
||||
|
@ -46,6 +47,7 @@ public class PointDescription {
|
|||
public static final String POINT_TYPE_TRANSPORT_ROUTE = "transport_route";
|
||||
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 PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, "");
|
||||
|
@ -253,6 +255,10 @@ public class PointDescription {
|
|||
return POINT_TYPE_MY_LOCATION.equals(type);
|
||||
}
|
||||
|
||||
public boolean isPoiType() {
|
||||
return POINT_TYPE_POI_TYPE.equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.helpers;
|
|||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.osm.AbstractPoiType;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
|
@ -42,6 +43,11 @@ public class SearchHistoryHelper {
|
|||
addNewItemToHistory(new HistoryEntry(latitude, longitude, pointDescription));
|
||||
}
|
||||
|
||||
public void addNewItemToHistory(AbstractPoiType pt) {
|
||||
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_POI_TYPE, pt.getKeyName());
|
||||
addNewItemToHistory(new HistoryEntry(0, 0, pd));
|
||||
}
|
||||
|
||||
public List<HistoryEntry> getHistoryEntries() {
|
||||
if (loadedEntries == null) {
|
||||
checkLoadedEntries();
|
||||
|
|
|
@ -12,7 +12,6 @@ import android.support.annotation.Nullable;
|
|||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
|
@ -68,7 +67,6 @@ import net.osmand.plus.OsmAndFormatter;
|
|||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -76,7 +74,6 @@ import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode;
|
|||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.resources.RegionAddressRepository;
|
||||
import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI;
|
||||
import net.osmand.plus.search.listitems.QuickSearchButtonListItem;
|
||||
|
@ -1776,6 +1773,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
}
|
||||
|
||||
public void completeQueryWithObject(SearchResult sr) {
|
||||
if (sr.object instanceof AbstractPoiType) {
|
||||
SearchHistoryHelper.getInstance(app).addNewItemToHistory((AbstractPoiType) sr.object);
|
||||
reloadHistory();
|
||||
}
|
||||
if (sr.object instanceof PoiType && ((PoiType) sr.object).isAdditional()) {
|
||||
PoiType additional = (PoiType) sr.object;
|
||||
AbstractPoiType parent = additional.getParentType();
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.osmand.plus.OsmAndFormatter;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
||||
import net.osmand.plus.poi.NominatimPoiFilter;
|
||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
|
@ -395,17 +396,25 @@ public class QuickSearchHelper implements ResourceListener {
|
|||
|
||||
@Override
|
||||
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException {
|
||||
SearchHistoryHelper helper = SearchHistoryHelper.getInstance(app);
|
||||
List<SearchHistoryHelper.HistoryEntry> points = helper.getHistoryEntries();
|
||||
int p = 0;
|
||||
for (SearchHistoryHelper.HistoryEntry point : points) {
|
||||
for (HistoryEntry point : SearchHistoryHelper.getInstance(app).getHistoryEntries()) {
|
||||
SearchResult sr = new SearchResult(phrase);
|
||||
sr.localeName = point.getName().getName();
|
||||
sr.object = point;
|
||||
if (point.getName().isPoiType()) {
|
||||
AbstractPoiType pt = MapPoiTypes.getDefault().getAnyPoiTypeByKey(point.getName().getName());
|
||||
if (pt != null) {
|
||||
sr.localeName = pt.getTranslation();
|
||||
sr.object = pt;
|
||||
sr.priorityDistance = 0;
|
||||
sr.objectType = ObjectType.POI_TYPE;
|
||||
}
|
||||
} else {
|
||||
sr.localeName = point.getName().getName();
|
||||
sr.object = point;
|
||||
sr.objectType = ObjectType.RECENT_OBJ;
|
||||
sr.location = new LatLon(point.getLat(), point.getLon());
|
||||
sr.preferredZoom = 17;
|
||||
}
|
||||
sr.priority = SEARCH_HISTORY_OBJECT_PRIORITY + (p++);
|
||||
sr.objectType = ObjectType.RECENT_OBJ;
|
||||
sr.location = new LatLon(point.getLat(), point.getLon());
|
||||
sr.preferredZoom = 17;
|
||||
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
|
||||
resultMatcher.publish(sr);
|
||||
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
|
||||
|
|
Loading…
Reference in a new issue