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()
+ "&q=" + URLEncoder.encode(getFilterByName());
} else {
urlq = NOMINATIM_API + URLEncoder.encode(getFilterByName()) + "?format=xml&addressdetails=1&limit=" + LIMIT
+ "&bounded=1&" + viewbox;
urlq = NOMINATIM_API + "?format=xml&addressdetails=1&limit=" + LIMIT
+ "&bounded=1&" + viewbox + "&q=" + URLEncoder.encode(getFilterByName());
}
log.info(urlq);
URLConnection connection = NetworkUtils.getHttpURLConnection(urlq); //$NON-NLS-1$

View file

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

View file

@ -338,7 +338,8 @@ public class QuickSearchHelper implements ResourceListener {
double lon = phrase.getSettings().getOriginalLocation().getLongitude();
String text = phrase.getUnknownSearchPhrase();
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;
}

View file

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

View file

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