From f7a0addf86090648a0587381404ec1e07a7ca6c1 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 27 Sep 2018 15:42:53 +0300 Subject: [PATCH 1/3] Fix lastSearchedCity update --- OsmAnd/res/values/strings.xml | 2 + .../search/QuickSearchDialogFragment.java | 289 +++++++++--------- 2 files changed, 151 insertions(+), 140 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 4859a4db21..71a4425554 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,8 @@ Thx - Hardy --> + Search street + Start search from city There is more transport on this stop. Please give OsmAnd permission for location to continue. Thank you for feedback diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 66aa655d35..287cecb896 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -1255,149 +1255,153 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC @Override public boolean searchFinished(SearchPhrase phrase) { - SearchResultCollection res = getResultCollection(); - if (SearchUICore.isDebugMode()) { - LOG.info("UI >> Nearest cities found: " + getSearchResultCollectionFormattedSize(res)); - } - - final OsmandSettings settings = app.getSettings(); - List 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()) { - LOG.info("UI >> Nearest cities loaded"); - } + updateCitiesItems(); return true; } }); restoreSearch(); } + private void updateCitiesItems() { + SearchResultCollection res = getResultCollection(); + if (SearchUICore.isDebugMode()) { + LOG.info("UI >> Nearest cities found: " + getSearchResultCollectionFormattedSize(res)); + } + + final OsmandSettings settings = app.getSettings(); + List 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); + if (SearchUICore.isDebugMode()) { + LOG.info("UI >> Nearest cities loaded"); + } + } + public void reloadHistory() { if (app.isApplicationInitializing()) { showProgressBar(); @@ -1804,14 +1808,19 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC if (addressSearch) { startAddressSearch(); if (sr.objectType == ObjectType.CITY) { - if (sr.relatedObject != null && sr.relatedObject instanceof BinaryMapIndexReader) { + if (sr.relatedObject instanceof BinaryMapIndexReader) { File f = ((BinaryMapIndexReader) sr.relatedObject).getFile(); if (f != null) { RegionAddressRepository region = app.getResourceManager().getRegionRepository(f.getName()); if (region != null) { - app.getSettings().setLastSearchedRegion(region.getFileName(), region.getEstimatedRegionCenter()); 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(); + } } } } From c80a7386e45e322e31d9a55919c9bb8c16a93426 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 27 Sep 2018 17:26:05 +0300 Subject: [PATCH 2/3] Move log nearest cities found back to searchFinished --- .../net/osmand/plus/search/QuickSearchDialogFragment.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 287cecb896..d50d37088d 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -1255,6 +1255,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC @Override public boolean searchFinished(SearchPhrase phrase) { + if (SearchUICore.isDebugMode()) { + LOG.info("UI >> Nearest cities found: " + getSearchResultCollectionFormattedSize(getResultCollection())); + } updateCitiesItems(); return true; } @@ -1264,9 +1267,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC private void updateCitiesItems() { SearchResultCollection res = getResultCollection(); - if (SearchUICore.isDebugMode()) { - LOG.info("UI >> Nearest cities found: " + getSearchResultCollectionFormattedSize(res)); - } final OsmandSettings settings = app.getSettings(); List rows = new ArrayList<>(); From 347640cf401d7d79ddb3bbd5bcc075e7c54b6d16 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 27 Sep 2018 17:32:13 +0300 Subject: [PATCH 3/3] Move log nearest cities loaded back to searchFinished --- .../net/osmand/plus/search/QuickSearchDialogFragment.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index d50d37088d..4062cd1834 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -1259,6 +1259,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC LOG.info("UI >> Nearest cities found: " + getSearchResultCollectionFormattedSize(getResultCollection())); } updateCitiesItems(); + if (SearchUICore.isDebugMode()) { + LOG.info("UI >> Nearest cities loaded"); + } return true; } }); @@ -1397,9 +1400,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } } addressSearchFragment.updateListAdapter(rows, false); - if (SearchUICore.isDebugMode()) { - LOG.info("UI >> Nearest cities loaded"); - } } public void reloadHistory() {