Start integrating online search in quick search

This commit is contained in:
PavelRatushny 2017-10-23 17:10:39 +03:00 committed by Alexander Sytnyk
parent ded04f334a
commit 5cd64b8169
3 changed files with 62 additions and 0 deletions

View file

@ -9,6 +9,8 @@ public enum ObjectType {
LOCATION(true), PARTIAL_LOCATION(false), LOCATION(true), PARTIAL_LOCATION(false),
// UI OBJECTS // UI OBJECTS
FAVORITE(true), FAVORITE_GROUP(false), WPT(true), RECENT_OBJ(true), FAVORITE(true), FAVORITE_GROUP(false), WPT(true), RECENT_OBJ(true),
// ONLINE
ONLINE_POI(true), ONLINE_ADDRESS(true),
REGION(true), REGION(true),

View file

@ -1079,6 +1079,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
for (SearchResult sr : res.getCurrentSearchResults()) { for (SearchResult sr : res.getCurrentSearchResults()) {
rows.add(new QuickSearchListItem(app, sr)); rows.add(new QuickSearchListItem(app, sr));
} }
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_world_globe_dark,
app.getString(R.string.search_online_address), new OnClickListener() {
@Override
public void onClick(View view) {
startOnlinePoiSearch();
mainSearchFragment.getAdapter().clear();
updateTabbarVisibility(false);
openKeyboard();
}
}));
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_search_dark, rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_search_dark,
app.getString(R.string.custom_search), new OnClickListener() { app.getString(R.string.custom_search), new OnClickListener() {
@Override @Override
@ -1320,6 +1330,17 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
} }
private void startOnlinePoiSearch() {
SearchSettings settings = searchUICore.getSearchSettings()
.setSearchTypes(ObjectType.ONLINE_POI)
.setEmptyQueryAllowed(false)
.setAddressSearch(false)
.setSortByName(true)
.setRadiusLevel(1);
searchUICore.updateSettings(settings);
}
private void startAddressSearch() { private void startAddressSearch() {
SearchSettings settings = searchUICore.getSearchSettings() SearchSettings settings = searchUICore.getSearchSettings()
.setEmptyQueryAllowed(true) .setEmptyQueryAllowed(true)

View file

@ -1,6 +1,7 @@
package net.osmand.plus.search; package net.osmand.plus.search;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.Amenity;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
@ -10,6 +11,7 @@ import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.poi.NominatimPoiFilter;
import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.resources.ResourceManager.ResourceListener; import net.osmand.plus.resources.ResourceManager.ResourceListener;
@ -36,6 +38,7 @@ public class QuickSearchHelper implements ResourceListener {
public static final int SEARCH_WPT_OBJECT_PRIORITY = 52; public static final int SEARCH_WPT_OBJECT_PRIORITY = 52;
public static final int SEARCH_HISTORY_API_PRIORITY = 50; public static final int SEARCH_HISTORY_API_PRIORITY = 50;
public static final int SEARCH_HISTORY_OBJECT_PRIORITY = 53; public static final int SEARCH_HISTORY_OBJECT_PRIORITY = 53;
public static final int SEARCH_ONLINE_PRIORITY = 53;
private OsmandApplication app; private OsmandApplication app;
private SearchUICore core; private SearchUICore core;
private SearchResultCollection resultCollection; private SearchResultCollection resultCollection;
@ -78,6 +81,8 @@ public class QuickSearchHelper implements ResourceListener {
core.registerAPI(new SearchWptAPI(app)); core.registerAPI(new SearchWptAPI(app));
core.registerAPI(new SearchHistoryAPI(app)); core.registerAPI(new SearchHistoryAPI(app));
core.registerAPI(new SearchOnlineApi(app));
refreshCustomPoiFilters(); refreshCustomPoiFilters();
} }
@ -266,6 +271,40 @@ public class QuickSearchHelper implements ResourceListener {
} }
} }
public static class SearchOnlineApi extends SearchBaseAPI {
private NominatimPoiFilter nominatimPoiFilter;
private OsmandApplication app;
public SearchOnlineApi(OsmandApplication app) {
super(ObjectType.ONLINE_POI);
this.nominatimPoiFilter = app.getPoiFilters().getNominatimPOIFilter();
this.app = app;
}
@Override
public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) throws IOException {
List<Amenity> amenities = nominatimPoiFilter.initializeNewSearch(app.getSettings().getLastKnownMapLocation().getLatitude(), app.getSettings().getLastKnownMapLocation().getLongitude(), -1, null);
int p = 0;
for (Amenity amenity : amenities) {
SearchResult sr = new SearchResult(phrase);
sr.localeName = amenity.getName();
sr.object = amenity;
sr.priority = SEARCH_HISTORY_OBJECT_PRIORITY + (p++);
sr.objectType = ObjectType.RECENT_OBJ;
sr.location = amenity.getLocation();
sr.preferredZoom = 17;
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
resultMatcher.publish(sr);
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
resultMatcher.publish(sr);
}
}
return true;
}
}
public static class SearchHistoryAPI extends SearchBaseAPI { public static class SearchHistoryAPI extends SearchBaseAPI {
private OsmandApplication app; private OsmandApplication app;