From 4409a258d8002a0c65f22b303b55b1dd7c8151cb Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Wed, 3 Aug 2016 12:43:05 +0300 Subject: [PATCH] Fix building history. Fix search after map download. --- .../net/osmand/plus/search/QuickSearchHelper.java | 15 ++++++++++++++- .../plus/search/QuickSearchListFragment.java | 14 ++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index fb65df05f1..7e53ab230c 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -8,6 +8,7 @@ import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.resources.RegionAddressRepository; +import net.osmand.plus.resources.ResourceManager.ResourceListener; import net.osmand.search.SearchUICore; import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.core.ObjectType; @@ -19,7 +20,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -public class QuickSearchHelper { +public class QuickSearchHelper implements ResourceListener { public static final int SEARCH_FAVORITE_API_PRIORITY = 2; public static final int SEARCH_FAVORITE_API_CATEGORY_PRIORITY = 7; @@ -31,13 +32,19 @@ public class QuickSearchHelper { private OsmandApplication app; private SearchUICore core; private SearchResultCollection resultCollection; + private boolean mapsIndexed; public QuickSearchHelper(OsmandApplication app) { this.app = app; core = new SearchUICore(app.getPoiTypes(), app.getSettings().MAP_PREFERRED_LOCALE.get()); + app.getResourceManager().addResourceListener(this); } public SearchUICore getCore() { + if (mapsIndexed) { + mapsIndexed = false; + setRepositoriesForSearchUICore(app); + } return core; } @@ -50,6 +57,7 @@ public class QuickSearchHelper { } public void initSearchUICore() { + mapsIndexed = false; setRepositoriesForSearchUICore(app); core.init(); // Register favorites search api @@ -213,4 +221,9 @@ public class QuickSearchHelper { return SEARCH_HISTORY_API_PRIORITY; } } + + @Override + public void onMapsIndexed() { + mapsIndexed = true; + } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index 10f5923dd2..b8b7b408ef 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -158,7 +158,6 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { String lang = searchResult.requiredSearchPhrase.getSettings().getLang(); PointDescription pointDescription = null; Object object = searchResult.object; - String typeName = null; switch (searchResult.objectType) { case POI: String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType((Amenity) object, lang); @@ -192,25 +191,24 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { pointDescription = fav.getPointDescription(); break; case HOUSE: - String name = searchResult.localeName; + String nm = searchResult.localeName; if (searchResult.relatedObject instanceof City) { - typeName = ((City) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true); + nm = ((City) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true) + " " + nm; } else if (searchResult.relatedObject instanceof Street) { String s = ((Street) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true); String c = ((Street) searchResult.relatedObject).getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true); - name = s + " " + name; - typeName = c; + nm = s + " " + nm + ", " + c; } else if (searchResult.localeRelatedObjectName != null) { - typeName = searchResult.localeRelatedObjectName; + nm = searchResult.localeRelatedObjectName + " " + nm; } - pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeName, name); + pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, nm); break; case LOCATION: LatLon latLon = (LatLon) object; pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude()); break; case STREET_INTERSECTION: - typeName = QuickSearchListItem.getTypeName(app, searchResult); + String typeName = QuickSearchListItem.getTypeName(app, searchResult); if (Algorithms.isEmpty(typeName)) { typeName = null; }