Merge pull request #6101 from osmandapp/SearchImprovement
Fix last searched city update
This commit is contained in:
commit
844d25452b
2 changed files with 147 additions and 135 deletions
|
@ -10,6 +10,9 @@
|
||||||
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<string name="search_street">Search street</string>
|
||||||
|
<string name="start_search_from_city">Start search from city</string>
|
||||||
<string name="shared_string_restore">Restore</string>
|
<string name="shared_string_restore">Restore</string>
|
||||||
<string name="keep_passed_markers_descr">Markers added as a group of Favorites or GPX waypoints marked "Passed" will remain on the map. If the group is not active, the markers will disappear from the map.</string>
|
<string name="keep_passed_markers_descr">Markers added as a group of Favorites or GPX waypoints marked "Passed" will remain on the map. If the group is not active, the markers will disappear from the map.</string>
|
||||||
<string name="keep_passed_markers">Keep passed markers on the map</string>
|
<string name="keep_passed_markers">Keep passed markers on the map</string>
|
||||||
|
|
|
@ -1255,140 +1255,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean searchFinished(SearchPhrase phrase) {
|
public boolean searchFinished(SearchPhrase phrase) {
|
||||||
SearchResultCollection res = getResultCollection();
|
|
||||||
if (SearchUICore.isDebugMode()) {
|
if (SearchUICore.isDebugMode()) {
|
||||||
LOG.info("UI >> Nearest cities found: " + getSearchResultCollectionFormattedSize(res));
|
LOG.info("UI >> Nearest cities found: " + getSearchResultCollectionFormattedSize(getResultCollection()));
|
||||||
}
|
}
|
||||||
|
updateCitiesItems();
|
||||||
final OsmandSettings settings = app.getSettings();
|
|
||||||
List<QuickSearchListItem> rows = new ArrayList<>();
|
|
||||||
|
|
||||||
if (SearchUICore.isDebugMode()) {
|
|
||||||
LOG.info("UI >> Start last city searching (within nearests)");
|
|
||||||
}
|
|
||||||
SearchResult lastCity = null;
|
|
||||||
if (res != null) {
|
|
||||||
citiesLoaded = res.getCurrentSearchResults().size() > 0;
|
|
||||||
final long lastCityId = settings.getLastSearchedCity();
|
|
||||||
for (SearchResult sr : res.getCurrentSearchResults()) {
|
|
||||||
if (sr.objectType == ObjectType.CITY && ((City) sr.object).getId() == lastCityId) {
|
|
||||||
lastCity = sr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (SearchUICore.isDebugMode()) {
|
|
||||||
LOG.info("UI >> Last city found: " + (lastCity != null ? lastCity.localeName : "-"));
|
|
||||||
}
|
|
||||||
|
|
||||||
final String lastCityName = lastCity == null ? settings.getLastSearchedCityName() : lastCity.localeName;
|
|
||||||
if (!Algorithms.isEmpty(lastCityName)) {
|
|
||||||
String selectStreets = app.getString(R.string.select_street);
|
|
||||||
String inCityName = app.getString(R.string.shared_string_in_name, lastCityName);
|
|
||||||
Spannable spannable = new SpannableString(selectStreets + " " + inCityName);
|
|
||||||
boolean light = settings.isLightContent();
|
|
||||||
spannable.setSpan(new ForegroundColorSpan(getResources().getColor(light ? R.color.icon_color : R.color.color_white)),
|
|
||||||
selectStreets.length() + 1, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
|
|
||||||
final SearchResult lastCityFinal = lastCity;
|
|
||||||
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_street_name,
|
|
||||||
spannable, new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (lastCityFinal == null) {
|
|
||||||
final long lastCityId = settings.getLastSearchedCity();
|
|
||||||
final LatLon lastCityPoint = settings.getLastSearchedPoint();
|
|
||||||
if (lastCityId != -1 && lastCityPoint != null) {
|
|
||||||
startLastCitySearch(lastCityPoint);
|
|
||||||
if (SearchUICore.isDebugMode()) {
|
|
||||||
LOG.info("UI >> Start last city searching (standalone)");
|
|
||||||
}
|
|
||||||
runCoreSearch("", false, false, new SearchResultListener() {
|
|
||||||
|
|
||||||
boolean cityFound = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void publish(SearchResultCollection res, boolean append) {
|
|
||||||
if (res != null) {
|
|
||||||
for (SearchResult sr : res.getCurrentSearchResults()) {
|
|
||||||
if (sr.objectType == ObjectType.CITY && ((City) sr.object).getId() == lastCityId) {
|
|
||||||
if (SearchUICore.isDebugMode()) {
|
|
||||||
LOG.info("UI >> Last city found: " + sr.localeName);
|
|
||||||
}
|
|
||||||
cityFound = true;
|
|
||||||
completeQueryWithObject(sr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void searchStarted(SearchPhrase phrase) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean searchFinished(SearchPhrase phrase) {
|
|
||||||
if (!cityFound) {
|
|
||||||
replaceQueryWithText(lastCityName + " ");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
restoreSearch();
|
|
||||||
} else {
|
|
||||||
replaceQueryWithText(lastCityName + " ");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
completeQueryWithObject(lastCityFinal);
|
|
||||||
}
|
|
||||||
openKeyboard();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_building_number,
|
|
||||||
app.getString(R.string.select_city), new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
searchEditText.setHint(R.string.type_city_town);
|
|
||||||
startCitySearch();
|
|
||||||
updateTabbarVisibility(false);
|
|
||||||
runCoreSearch("", false, false);
|
|
||||||
openKeyboard();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_postcode,
|
|
||||||
app.getString(R.string.select_postcode), new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
searchEditText.setHint(R.string.type_postcode);
|
|
||||||
startPostcodeSearch();
|
|
||||||
mainSearchFragment.getAdapter().clear();
|
|
||||||
updateTabbarVisibility(false);
|
|
||||||
openKeyboard();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_marker_dark,
|
|
||||||
app.getString(R.string.coords_search), new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
LatLon latLon = searchUICore.getSearchSettings().getOriginalLocation();
|
|
||||||
QuickSearchCoordinatesFragment.showDialog(QuickSearchDialogFragment.this,
|
|
||||||
latLon.getLatitude(), latLon.getLongitude());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (res != null) {
|
|
||||||
rows.add(new QuickSearchHeaderListItem(app, app.getString(R.string.nearest_cities), true));
|
|
||||||
int limit = 15;
|
|
||||||
for (SearchResult sr : res.getCurrentSearchResults()) {
|
|
||||||
if (limit > 0) {
|
|
||||||
rows.add(new QuickSearchListItem(app, sr));
|
|
||||||
}
|
|
||||||
limit--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addressSearchFragment.updateListAdapter(rows, false);
|
|
||||||
if (SearchUICore.isDebugMode()) {
|
if (SearchUICore.isDebugMode()) {
|
||||||
LOG.info("UI >> Nearest cities loaded");
|
LOG.info("UI >> Nearest cities loaded");
|
||||||
}
|
}
|
||||||
|
@ -1398,6 +1268,140 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
restoreSearch();
|
restoreSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateCitiesItems() {
|
||||||
|
SearchResultCollection res = getResultCollection();
|
||||||
|
|
||||||
|
final OsmandSettings settings = app.getSettings();
|
||||||
|
List<QuickSearchListItem> rows = new ArrayList<>();
|
||||||
|
|
||||||
|
if (SearchUICore.isDebugMode()) {
|
||||||
|
LOG.info("UI >> Start last city searching (within nearests)");
|
||||||
|
}
|
||||||
|
SearchResult lastCity = null;
|
||||||
|
if (res != null) {
|
||||||
|
citiesLoaded = res.getCurrentSearchResults().size() > 0;
|
||||||
|
final long lastCityId = settings.getLastSearchedCity();
|
||||||
|
for (SearchResult sr : res.getCurrentSearchResults()) {
|
||||||
|
if (sr.objectType == ObjectType.CITY && ((City) sr.object).getId() == lastCityId) {
|
||||||
|
lastCity = sr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (SearchUICore.isDebugMode()) {
|
||||||
|
LOG.info("UI >> Last city found: " + (lastCity != null ? lastCity.localeName : "-"));
|
||||||
|
}
|
||||||
|
|
||||||
|
final String lastCityName = lastCity == null ? settings.getLastSearchedCityName() : lastCity.localeName;
|
||||||
|
if (!Algorithms.isEmpty(lastCityName)) {
|
||||||
|
String selectStreets = app.getString(R.string.search_street);
|
||||||
|
String inCityName = app.getString(R.string.shared_string_in_name, lastCityName);
|
||||||
|
Spannable spannable = new SpannableString(selectStreets + " " + inCityName);
|
||||||
|
boolean light = settings.isLightContent();
|
||||||
|
spannable.setSpan(new ForegroundColorSpan(getResources().getColor(light ? R.color.icon_color : R.color.color_white)),
|
||||||
|
selectStreets.length() + 1, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
|
||||||
|
final SearchResult lastCityFinal = lastCity;
|
||||||
|
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_street_name,
|
||||||
|
spannable, new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (lastCityFinal == null) {
|
||||||
|
final long lastCityId = settings.getLastSearchedCity();
|
||||||
|
final LatLon lastCityPoint = settings.getLastSearchedPoint();
|
||||||
|
if (lastCityId != -1 && lastCityPoint != null) {
|
||||||
|
startLastCitySearch(lastCityPoint);
|
||||||
|
if (SearchUICore.isDebugMode()) {
|
||||||
|
LOG.info("UI >> Start last city searching (standalone)");
|
||||||
|
}
|
||||||
|
runCoreSearch("", false, false, new SearchResultListener() {
|
||||||
|
|
||||||
|
boolean cityFound = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publish(SearchResultCollection res, boolean append) {
|
||||||
|
if (res != null) {
|
||||||
|
for (SearchResult sr : res.getCurrentSearchResults()) {
|
||||||
|
if (sr.objectType == ObjectType.CITY && ((City) sr.object).getId() == lastCityId) {
|
||||||
|
if (SearchUICore.isDebugMode()) {
|
||||||
|
LOG.info("UI >> Last city found: " + sr.localeName);
|
||||||
|
}
|
||||||
|
cityFound = true;
|
||||||
|
completeQueryWithObject(sr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void searchStarted(SearchPhrase phrase) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean searchFinished(SearchPhrase phrase) {
|
||||||
|
if (!cityFound) {
|
||||||
|
replaceQueryWithText(lastCityName + " ");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
restoreSearch();
|
||||||
|
} else {
|
||||||
|
replaceQueryWithText(lastCityName + " ");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
completeQueryWithObject(lastCityFinal);
|
||||||
|
}
|
||||||
|
openKeyboard();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_building_number,
|
||||||
|
app.getString(R.string.start_search_from_city), new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
searchEditText.setHint(R.string.type_city_town);
|
||||||
|
startCitySearch();
|
||||||
|
updateTabbarVisibility(false);
|
||||||
|
runCoreSearch("", false, false);
|
||||||
|
openKeyboard();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_postcode,
|
||||||
|
app.getString(R.string.select_postcode), new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
searchEditText.setHint(R.string.type_postcode);
|
||||||
|
startPostcodeSearch();
|
||||||
|
mainSearchFragment.getAdapter().clear();
|
||||||
|
updateTabbarVisibility(false);
|
||||||
|
openKeyboard();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_marker_dark,
|
||||||
|
app.getString(R.string.coords_search), new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
LatLon latLon = searchUICore.getSearchSettings().getOriginalLocation();
|
||||||
|
QuickSearchCoordinatesFragment.showDialog(QuickSearchDialogFragment.this,
|
||||||
|
latLon.getLatitude(), latLon.getLongitude());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (res != null) {
|
||||||
|
rows.add(new QuickSearchHeaderListItem(app, app.getString(R.string.nearest_cities), true));
|
||||||
|
int limit = 15;
|
||||||
|
for (SearchResult sr : res.getCurrentSearchResults()) {
|
||||||
|
if (limit > 0) {
|
||||||
|
rows.add(new QuickSearchListItem(app, sr));
|
||||||
|
}
|
||||||
|
limit--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addressSearchFragment.updateListAdapter(rows, false);
|
||||||
|
}
|
||||||
|
|
||||||
public void reloadHistory() {
|
public void reloadHistory() {
|
||||||
if (app.isApplicationInitializing()) {
|
if (app.isApplicationInitializing()) {
|
||||||
showProgressBar();
|
showProgressBar();
|
||||||
|
@ -1804,14 +1808,19 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
||||||
if (addressSearch) {
|
if (addressSearch) {
|
||||||
startAddressSearch();
|
startAddressSearch();
|
||||||
if (sr.objectType == ObjectType.CITY) {
|
if (sr.objectType == ObjectType.CITY) {
|
||||||
if (sr.relatedObject != null && sr.relatedObject instanceof BinaryMapIndexReader) {
|
if (sr.relatedObject instanceof BinaryMapIndexReader) {
|
||||||
File f = ((BinaryMapIndexReader) sr.relatedObject).getFile();
|
File f = ((BinaryMapIndexReader) sr.relatedObject).getFile();
|
||||||
if (f != null) {
|
if (f != null) {
|
||||||
RegionAddressRepository region = app.getResourceManager().getRegionRepository(f.getName());
|
RegionAddressRepository region = app.getResourceManager().getRegionRepository(f.getName());
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
app.getSettings().setLastSearchedRegion(region.getFileName(), region.getEstimatedRegionCenter());
|
|
||||||
City city = (City) sr.object;
|
City city = (City) sr.object;
|
||||||
app.getSettings().setLastSearchedCity(city.getId(), sr.localeName, city.getLocation());
|
String lastSearchedRegion = app.getSettings().getLastSearchedRegion();
|
||||||
|
long lastCityId = app.getSettings().getLastSearchedCity();
|
||||||
|
if (!lastSearchedRegion.equals(region.getFileName()) || city.getId() != lastCityId) {
|
||||||
|
app.getSettings().setLastSearchedRegion(region.getFileName(), region.getEstimatedRegionCenter());
|
||||||
|
app.getSettings().setLastSearchedCity(city.getId(), sr.localeName, city.getLocation());
|
||||||
|
updateCitiesItems();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue