Fix online search radius

This commit is contained in:
Alexey Kulish 2017-10-27 13:11:07 +03:00
parent 96b538713f
commit 74b09a7681
5 changed files with 33 additions and 12 deletions

View file

@ -95,8 +95,8 @@ public class NominatimPoiFilter extends PoiUIFilter {
urlq = NOMINATIM_API + "?format=xml&addressdetails=0&accept-language="+ Locale.getDefault().getLanguage() urlq = NOMINATIM_API + "?format=xml&addressdetails=0&accept-language="+ Locale.getDefault().getLanguage()
+ "&q=" + URLEncoder.encode(getFilterByName()); + "&q=" + URLEncoder.encode(getFilterByName());
} else { } else {
urlq = NOMINATIM_API + URLEncoder.encode(getFilterByName()) + "?format=xml&addressdetails=1&limit=" + LIMIT urlq = NOMINATIM_API + "?format=xml&addressdetails=1&limit=" + LIMIT
+ "&bounded=1&" + viewbox; + "&bounded=1&" + viewbox + "&q=" + URLEncoder.encode(getFilterByName());
} }
log.info(urlq); log.info(urlq);
URLConnection connection = NetworkUtils.getHttpURLConnection(urlq); //$NON-NLS-1$ URLConnection connection = NetworkUtils.getHttpURLConnection(urlq); //$NON-NLS-1$

View file

@ -533,12 +533,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
updateClearButtonAndHint(); updateClearButtonAndHint();
updateClearButtonVisibility(true); updateClearButtonVisibility(true);
boolean textEmpty = newQueryText.length() == 0; boolean textEmpty = newQueryText.length() == 0;
updateTabbarVisibility(textEmpty); updateTabbarVisibility(textEmpty && !isOnlineSearch());
if (textEmpty) { if (textEmpty) {
if (addressSearch) { if (addressSearch) {
startAddressSearch(); startAddressSearch();
} else if (isOnlineSearch()) {
restoreSearch();
} }
if (poiFilterApplied) { if (poiFilterApplied) {
poiFilterApplied = false; poiFilterApplied = false;
@ -552,7 +550,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (!searchQuery.equalsIgnoreCase(newQueryText)) { if (!searchQuery.equalsIgnoreCase(newQueryText)) {
searchQuery = newQueryText; searchQuery = newQueryText;
if (Algorithms.isEmpty(searchQuery)) { if (Algorithms.isEmpty(searchQuery)) {
cancelSearch();
setResultCollection(null);
searchUICore.resetPhrase(); searchUICore.resetPhrase();
mainSearchFragment.getAdapter().clear();
} else { } else {
runSearch(); runSearch();
} }
@ -712,6 +713,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
return searchEditText.getText().toString(); return searchEditText.getText().toString();
} }
public boolean isTextEmpty() {
return Algorithms.isEmpty(getText());
}
public AccessibilityAssistant getAccessibilityAssistant() { public AccessibilityAssistant getAccessibilityAssistant() {
return accessibilityAssistant; return accessibilityAssistant;
} }
@ -999,7 +1004,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} else { } else {
tabToolbarView.setVisibility(View.GONE); tabToolbarView.setVisibility(View.GONE);
buttonToolbarView.setVisibility( buttonToolbarView.setVisibility(
(isOnlineSearch() && getText().length() > 0) (isOnlineSearch() && !isTextEmpty())
|| !searchUICore.getSearchSettings().isCustomSearch() ? View.VISIBLE : View.GONE); || !searchUICore.getSearchSettings().isCustomSearch() ? View.VISIBLE : View.GONE);
tabsView.setVisibility(View.GONE); tabsView.setVisibility(View.GONE);
searchView.setVisibility(View.VISIBLE); searchView.setVisibility(View.VISIBLE);
@ -1426,6 +1431,13 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
searchUICore.updateSettings(settings); searchUICore.updateSettings(settings);
} }
private void cancelSearch() {
cancelPrev = true;
if (!paused) {
hideProgressBar();
}
}
private void runSearch() { private void runSearch() {
runSearch(searchQuery); runSearch(searchQuery);
} }
@ -1511,7 +1523,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
app.runInUIThread(new Runnable() { app.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
if(paused) { if (paused) {
return; return;
} }
searching = false; searching = false;
@ -1722,7 +1734,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
private void addMoreButton() { private void addMoreButton() {
if (!paused && !cancelPrev && mainSearchFragment != null) { if (!paused && !cancelPrev && mainSearchFragment != null && !isTextEmpty()) {
QuickSearchMoreListItem moreListItem = QuickSearchMoreListItem moreListItem =
new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() { new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() {
@Override @Override
@ -1744,6 +1756,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}); });
moreListItem.setInterruptedSearch(interruptedSearch); moreListItem.setInterruptedSearch(interruptedSearch);
moreListItem.setEmptySearch(isResultEmpty()); moreListItem.setEmptySearch(isResultEmpty());
moreListItem.setOnlineSearch(isOnlineSearch());
mainSearchFragment.addListItem(moreListItem); mainSearchFragment.addListItem(moreListItem);
} }
} }

View file

@ -338,7 +338,8 @@ public class QuickSearchHelper implements ResourceListener {
double lon = phrase.getSettings().getOriginalLocation().getLongitude(); double lon = phrase.getSettings().getOriginalLocation().getLongitude();
String text = phrase.getUnknownSearchPhrase(); String text = phrase.getUnknownSearchPhrase();
filter.setFilterByName(text); filter.setFilterByName(text);
publishAmenities(phrase, matcher, filter.initializeNewSearch(lat, lon, -1, null, phrase.getRadiusLevel())); publishAmenities(phrase, matcher, filter.initializeNewSearch(lat, lon,
-1, null, phrase.getRadiusLevel() + 3));
return true; return true;
} }

View file

@ -242,9 +242,7 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
((QuickSearchMoreListItem) listItem).increaseRadiusOnClick(); ((QuickSearchMoreListItem) listItem).increaseRadiusOnClick();
} }
}); });
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null if (!searchMoreListItem.isOnlineSearch()) {
&& !app.getSearchUICore().getCore().getSearchSettings().isCustomSearch()
&& !app.getSearchUICore().getCore().getSearchSettings().hasCustomSearchType(ObjectType.ONLINE_SEARCH)) {
view.findViewById(R.id.online_search_row).setVisibility(View.VISIBLE); view.findViewById(R.id.online_search_row).setVisibility(View.VISIBLE);
view.findViewById(R.id.online_search_row).setOnClickListener(new View.OnClickListener() { view.findViewById(R.id.online_search_row).setOnClickListener(new View.OnClickListener() {
@Override @Override

View file

@ -10,6 +10,7 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
private String name; private String name;
private SearchMoreItemOnClickListener onClickListener; private SearchMoreItemOnClickListener onClickListener;
private boolean emptySearch; private boolean emptySearch;
private boolean onlineSearch;
private boolean interruptedSearch; private boolean interruptedSearch;
private String findMore; private String findMore;
private String restartSearch; private String restartSearch;
@ -59,6 +60,14 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
this.emptySearch = emptySearch; this.emptySearch = emptySearch;
} }
public boolean isOnlineSearch() {
return onlineSearch;
}
public void setOnlineSearch(boolean onlineSearch) {
this.onlineSearch = onlineSearch;
}
public void increaseRadiusOnClick() { public void increaseRadiusOnClick() {
if (onClickListener != null) { if (onClickListener != null) {
onClickListener.increaseRadiusOnClick(); onClickListener.increaseRadiusOnClick();