From 78c648e8405eca5b4bfa82a02082275979f28f4f Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Thu, 21 Jul 2016 10:19:14 +0300 Subject: [PATCH] [Quick search] fixes --- .../search/QuickSearchDialogFragment.java | 20 ++++--- .../plus/search/QuickSearchListItem.java | 52 ++++++++++++------- .../plus/search/QuickSearchMoreListItem.java | 2 +- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 36253255ff..dfc80ac122 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -30,10 +30,13 @@ import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.ResultMatcher; import net.osmand.binary.BinaryMapIndexReader; +import net.osmand.data.Amenity; +import net.osmand.data.Building; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; @@ -376,7 +379,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC List rows = new ArrayList<>(); OsmandApplication app = getMyApplication(); for (SearchResult sr : history) { - rows.add(new QuickSearchListItem(app, sr, sp.getSettings().getLang())); + rows.add(new QuickSearchListItem(app, sr)); } searchListFragment.updateListAdapter(rows, false); } @@ -411,7 +414,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC List rows = new ArrayList<>(); OsmandApplication app = getMyApplication(); for (SearchResult sr : amenityTypes) { - rows.add(new QuickSearchListItem(app, sr, sp.getSettings().getLang())); + rows.add(new QuickSearchListItem(app, sr)); } searchListFragment.updateListAdapter(rows, false); } @@ -566,7 +569,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC List rows = new ArrayList<>(); if (res.getCurrentSearchResults().size() > 0) { for (final SearchResult sr : res.getCurrentSearchResults()) { - rows.add(new QuickSearchListItem(app, sr, searchUICore.getPhrase().getSettings().getLang())); + rows.add(new QuickSearchListItem(app, sr)); } } if (mainSearchFragment != null) { @@ -846,11 +849,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC private void showOnMap(SearchResult searchResult) { if (searchResult.location != null) { + OsmandApplication app = getMyApplication(); PointDescription pointDescription = null; Object object = searchResult.object; switch (searchResult.objectType) { case POI: - pointDescription = getMapActivity().getMapLayers().getPoiMapLayer().getObjectName(object); + String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType( + (Amenity) object, searchResult.requiredSearchPhrase.getSettings().getLang()); + pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat); break; case RECENT_OBJ: HistoryEntry entry = (HistoryEntry) object; @@ -861,14 +867,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC pointDescription = fav.getPointDescription(); break; case HOUSE: - pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, ""); + pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, + QuickSearchListItem.getName(app, searchResult) + ", " + QuickSearchListItem.getTypeName(app, searchResult)); break; case LOCATION: LatLon latLon = (LatLon) object; pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude()); break; case STREET_INTERSECTION: - pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, ""); + pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, + QuickSearchListItem.getName(app, searchResult)); break; case WPT: WptPt wpt = (WptPt) object; diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListItem.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListItem.java index e2b39754d1..390cbad0d6 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListItem.java @@ -1,5 +1,6 @@ package net.osmand.plus.search; +import android.content.Context; import android.graphics.drawable.Drawable; import net.osmand.binary.BinaryMapIndexReader; @@ -27,40 +28,42 @@ public class QuickSearchListItem { protected OsmandApplication app; private SearchResult searchResult; - private String lang; - public QuickSearchListItem(OsmandApplication app, SearchResult searchResult, String lang) { + public QuickSearchListItem(OsmandApplication app, SearchResult searchResult) { this.app = app; this.searchResult = searchResult; - this.lang = lang; } public SearchResult getSearchResult() { return searchResult; } - private String getCityTypeStr(CityType type) { + public static String getCityTypeStr(Context ctx, CityType type) { switch (type) { case CITY: - return app.getString(R.string.city_type_city); + return ctx.getString(R.string.city_type_city); case TOWN: - return app.getString(R.string.city_type_town); + return ctx.getString(R.string.city_type_town); case VILLAGE: - return app.getString(R.string.city_type_village); + return ctx.getString(R.string.city_type_village); case HAMLET: - return app.getString(R.string.city_type_hamlet); + return ctx.getString(R.string.city_type_hamlet); case SUBURB: - return app.getString(R.string.city_type_suburb); + return ctx.getString(R.string.city_type_suburb); case DISTRICT: - return app.getString(R.string.city_type_district); + return ctx.getString(R.string.city_type_district); case NEIGHBOURHOOD: - return app.getString(R.string.city_type_neighbourhood); + return ctx.getString(R.string.city_type_neighbourhood); default: - return app.getString(R.string.city_type_city); + return ctx.getString(R.string.city_type_city); } } public String getName() { + return getName(app, searchResult); + } + + public static String getName(OsmandApplication app, SearchResult searchResult) { switch (searchResult.objectType) { case STREET_INTERSECTION: if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) { @@ -76,28 +79,32 @@ public class QuickSearchListItem { } public String getTypeName() { + return getTypeName(app, searchResult); + } + + public static String getTypeName(OsmandApplication app, SearchResult searchResult) { switch (searchResult.objectType) { case CITY: City city = (City) searchResult.object; - return getCityTypeStr(city.getType()); + return getCityTypeStr(app, city.getType()); case POSTCODE: return app.getString(R.string.postcode); case VILLAGE: city = (City) searchResult.object; if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) { if (searchResult.distRelatedObjectName > 0) { - return getCityTypeStr(city.getType()) + return getCityTypeStr(app, city.getType()) + " • " + OsmAndFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app) + " " + app.getString(R.string.shared_string_from) + " " + searchResult.localeRelatedObjectName; } else { - return getCityTypeStr(city.getType()) + return getCityTypeStr(app, city.getType()) + ", " + searchResult.localeRelatedObjectName; } } else { - return getCityTypeStr(city.getType()); + return getCityTypeStr(app, city.getType()); } case STREET: if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) { @@ -108,7 +115,8 @@ public class QuickSearchListItem { if (searchResult.relatedObject != null) { Street relatedStreet = (Street) searchResult.relatedObject; if (relatedStreet.getCity() != null) { - return searchResult.localeRelatedObjectName + ", " + relatedStreet.getCity().getName(lang, true); + return searchResult.localeRelatedObjectName + ", " + + relatedStreet.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true); } else { return searchResult.localeRelatedObjectName; } @@ -117,7 +125,7 @@ public class QuickSearchListItem { case STREET_INTERSECTION: Street street = (Street) searchResult.object; if (street.getCity() != null) { - return street.getCity().getName(lang, true); + return street.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true); } return ""; case POI_TYPE: @@ -180,6 +188,10 @@ public class QuickSearchListItem { } public Drawable getTypeIcon() { + return getTypeIcon(app, searchResult); + } + + public static Drawable getTypeIcon(OsmandApplication app, SearchResult searchResult) { switch (searchResult.objectType) { case FAVORITE: return app.getIconsCache().getThemedIcon(R.drawable.ic_small_group); @@ -196,6 +208,10 @@ public class QuickSearchListItem { } public Drawable getIcon() { + return getIcon(app, searchResult); + } + + public static Drawable getIcon(OsmandApplication app, SearchResult searchResult) { switch (searchResult.objectType) { case CITY: return app.getIconsCache().getIcon(R.drawable.ic_action_building_number, diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchMoreListItem.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchMoreListItem.java index ca239e0017..9a7fbebcc8 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchMoreListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchMoreListItem.java @@ -10,7 +10,7 @@ public class QuickSearchMoreListItem extends QuickSearchListItem { private OnClickListener onClickListener; public QuickSearchMoreListItem(OsmandApplication app, String name, OnClickListener onClickListener) { - super(app, null, null); + super(app, null); this.name = name; this.onClickListener = onClickListener; }