Fix building history. Fix search after map download.

This commit is contained in:
Alexey Kulish 2016-08-03 12:43:05 +03:00
parent a6c0dc2b08
commit 4409a258d8
2 changed files with 20 additions and 9 deletions

View file

@ -8,6 +8,7 @@ import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.plus.resources.ResourceManager.ResourceListener;
import net.osmand.search.SearchUICore; import net.osmand.search.SearchUICore;
import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.SearchUICore.SearchResultCollection;
import net.osmand.search.core.ObjectType; import net.osmand.search.core.ObjectType;
@ -19,7 +20,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; 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_PRIORITY = 2;
public static final int SEARCH_FAVORITE_API_CATEGORY_PRIORITY = 7; public static final int SEARCH_FAVORITE_API_CATEGORY_PRIORITY = 7;
@ -31,13 +32,19 @@ public class QuickSearchHelper {
private OsmandApplication app; private OsmandApplication app;
private SearchUICore core; private SearchUICore core;
private SearchResultCollection resultCollection; private SearchResultCollection resultCollection;
private boolean mapsIndexed;
public QuickSearchHelper(OsmandApplication app) { public QuickSearchHelper(OsmandApplication app) {
this.app = app; this.app = app;
core = new SearchUICore(app.getPoiTypes(), app.getSettings().MAP_PREFERRED_LOCALE.get()); core = new SearchUICore(app.getPoiTypes(), app.getSettings().MAP_PREFERRED_LOCALE.get());
app.getResourceManager().addResourceListener(this);
} }
public SearchUICore getCore() { public SearchUICore getCore() {
if (mapsIndexed) {
mapsIndexed = false;
setRepositoriesForSearchUICore(app);
}
return core; return core;
} }
@ -50,6 +57,7 @@ public class QuickSearchHelper {
} }
public void initSearchUICore() { public void initSearchUICore() {
mapsIndexed = false;
setRepositoriesForSearchUICore(app); setRepositoriesForSearchUICore(app);
core.init(); core.init();
// Register favorites search api // Register favorites search api
@ -213,4 +221,9 @@ public class QuickSearchHelper {
return SEARCH_HISTORY_API_PRIORITY; return SEARCH_HISTORY_API_PRIORITY;
} }
} }
@Override
public void onMapsIndexed() {
mapsIndexed = true;
}
} }

View file

@ -158,7 +158,6 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
String lang = searchResult.requiredSearchPhrase.getSettings().getLang(); String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
PointDescription pointDescription = null; PointDescription pointDescription = null;
Object object = searchResult.object; Object object = searchResult.object;
String typeName = null;
switch (searchResult.objectType) { switch (searchResult.objectType) {
case POI: case POI:
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType((Amenity) object, lang); String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType((Amenity) object, lang);
@ -192,25 +191,24 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
pointDescription = fav.getPointDescription(); pointDescription = fav.getPointDescription();
break; break;
case HOUSE: case HOUSE:
String name = searchResult.localeName; String nm = searchResult.localeName;
if (searchResult.relatedObject instanceof City) { 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) { } else if (searchResult.relatedObject instanceof Street) {
String s = ((Street) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true); String s = ((Street) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
String c = ((Street) searchResult.relatedObject).getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true); String c = ((Street) searchResult.relatedObject).getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
name = s + " " + name; nm = s + " " + nm + ", " + c;
typeName = c;
} else if (searchResult.localeRelatedObjectName != null) { } 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; break;
case LOCATION: case LOCATION:
LatLon latLon = (LatLon) object; LatLon latLon = (LatLon) object;
pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude()); pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
break; break;
case STREET_INTERSECTION: case STREET_INTERSECTION:
typeName = QuickSearchListItem.getTypeName(app, searchResult); String typeName = QuickSearchListItem.getTypeName(app, searchResult);
if (Algorithms.isEmpty(typeName)) { if (Algorithms.isEmpty(typeName)) {
typeName = null; typeName = null;
} }