[Quick search] fixes

This commit is contained in:
Alexey Kulish 2016-07-21 10:19:14 +03:00
parent 0ff32e6819
commit 78c648e840
3 changed files with 49 additions and 25 deletions

View file

@ -30,10 +30,13 @@ import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.Amenity;
import net.osmand.data.Building;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -376,7 +379,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
List<QuickSearchListItem> rows = new ArrayList<>(); List<QuickSearchListItem> rows = new ArrayList<>();
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
for (SearchResult sr : history) { for (SearchResult sr : history) {
rows.add(new QuickSearchListItem(app, sr, sp.getSettings().getLang())); rows.add(new QuickSearchListItem(app, sr));
} }
searchListFragment.updateListAdapter(rows, false); searchListFragment.updateListAdapter(rows, false);
} }
@ -411,7 +414,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
List<QuickSearchListItem> rows = new ArrayList<>(); List<QuickSearchListItem> rows = new ArrayList<>();
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
for (SearchResult sr : amenityTypes) { for (SearchResult sr : amenityTypes) {
rows.add(new QuickSearchListItem(app, sr, sp.getSettings().getLang())); rows.add(new QuickSearchListItem(app, sr));
} }
searchListFragment.updateListAdapter(rows, false); searchListFragment.updateListAdapter(rows, false);
} }
@ -566,7 +569,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
List<QuickSearchListItem> rows = new ArrayList<>(); List<QuickSearchListItem> rows = new ArrayList<>();
if (res.getCurrentSearchResults().size() > 0) { if (res.getCurrentSearchResults().size() > 0) {
for (final SearchResult sr : res.getCurrentSearchResults()) { 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) { if (mainSearchFragment != null) {
@ -846,11 +849,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private void showOnMap(SearchResult searchResult) { private void showOnMap(SearchResult searchResult) {
if (searchResult.location != null) { if (searchResult.location != null) {
OsmandApplication app = getMyApplication();
PointDescription pointDescription = null; PointDescription pointDescription = null;
Object object = searchResult.object; Object object = searchResult.object;
switch (searchResult.objectType) { switch (searchResult.objectType) {
case POI: 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; break;
case RECENT_OBJ: case RECENT_OBJ:
HistoryEntry entry = (HistoryEntry) object; HistoryEntry entry = (HistoryEntry) object;
@ -861,14 +867,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
pointDescription = fav.getPointDescription(); pointDescription = fav.getPointDescription();
break; break;
case HOUSE: 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; 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:
pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, ""); pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS,
QuickSearchListItem.getName(app, searchResult));
break; break;
case WPT: case WPT:
WptPt wpt = (WptPt) object; WptPt wpt = (WptPt) object;

View file

@ -1,5 +1,6 @@
package net.osmand.plus.search; package net.osmand.plus.search;
import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
@ -27,40 +28,42 @@ public class QuickSearchListItem {
protected OsmandApplication app; protected OsmandApplication app;
private SearchResult searchResult; private SearchResult searchResult;
private String lang;
public QuickSearchListItem(OsmandApplication app, SearchResult searchResult, String lang) { public QuickSearchListItem(OsmandApplication app, SearchResult searchResult) {
this.app = app; this.app = app;
this.searchResult = searchResult; this.searchResult = searchResult;
this.lang = lang;
} }
public SearchResult getSearchResult() { public SearchResult getSearchResult() {
return searchResult; return searchResult;
} }
private String getCityTypeStr(CityType type) { public static String getCityTypeStr(Context ctx, CityType type) {
switch (type) { switch (type) {
case CITY: case CITY:
return app.getString(R.string.city_type_city); return ctx.getString(R.string.city_type_city);
case TOWN: case TOWN:
return app.getString(R.string.city_type_town); return ctx.getString(R.string.city_type_town);
case VILLAGE: case VILLAGE:
return app.getString(R.string.city_type_village); return ctx.getString(R.string.city_type_village);
case HAMLET: case HAMLET:
return app.getString(R.string.city_type_hamlet); return ctx.getString(R.string.city_type_hamlet);
case SUBURB: case SUBURB:
return app.getString(R.string.city_type_suburb); return ctx.getString(R.string.city_type_suburb);
case DISTRICT: case DISTRICT:
return app.getString(R.string.city_type_district); return ctx.getString(R.string.city_type_district);
case NEIGHBOURHOOD: case NEIGHBOURHOOD:
return app.getString(R.string.city_type_neighbourhood); return ctx.getString(R.string.city_type_neighbourhood);
default: default:
return app.getString(R.string.city_type_city); return ctx.getString(R.string.city_type_city);
} }
} }
public String getName() { public String getName() {
return getName(app, searchResult);
}
public static String getName(OsmandApplication app, SearchResult searchResult) {
switch (searchResult.objectType) { switch (searchResult.objectType) {
case STREET_INTERSECTION: case STREET_INTERSECTION:
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) { if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
@ -76,28 +79,32 @@ public class QuickSearchListItem {
} }
public String getTypeName() { public String getTypeName() {
return getTypeName(app, searchResult);
}
public static String getTypeName(OsmandApplication app, SearchResult searchResult) {
switch (searchResult.objectType) { switch (searchResult.objectType) {
case CITY: case CITY:
City city = (City) searchResult.object; City city = (City) searchResult.object;
return getCityTypeStr(city.getType()); return getCityTypeStr(app, city.getType());
case POSTCODE: case POSTCODE:
return app.getString(R.string.postcode); return app.getString(R.string.postcode);
case VILLAGE: case VILLAGE:
city = (City) searchResult.object; city = (City) searchResult.object;
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) { if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
if (searchResult.distRelatedObjectName > 0) { if (searchResult.distRelatedObjectName > 0) {
return getCityTypeStr(city.getType()) return getCityTypeStr(app, city.getType())
+ "" + ""
+ OsmAndFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app) + OsmAndFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app)
+ " " + app.getString(R.string.shared_string_from) + " " + " " + app.getString(R.string.shared_string_from) + " "
+ searchResult.localeRelatedObjectName; + searchResult.localeRelatedObjectName;
} else { } else {
return getCityTypeStr(city.getType()) return getCityTypeStr(app, city.getType())
+ ", " + ", "
+ searchResult.localeRelatedObjectName; + searchResult.localeRelatedObjectName;
} }
} else { } else {
return getCityTypeStr(city.getType()); return getCityTypeStr(app, city.getType());
} }
case STREET: case STREET:
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) { if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
@ -108,7 +115,8 @@ public class QuickSearchListItem {
if (searchResult.relatedObject != null) { if (searchResult.relatedObject != null) {
Street relatedStreet = (Street) searchResult.relatedObject; Street relatedStreet = (Street) searchResult.relatedObject;
if (relatedStreet.getCity() != null) { if (relatedStreet.getCity() != null) {
return searchResult.localeRelatedObjectName + ", " + relatedStreet.getCity().getName(lang, true); return searchResult.localeRelatedObjectName + ", "
+ relatedStreet.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
} else { } else {
return searchResult.localeRelatedObjectName; return searchResult.localeRelatedObjectName;
} }
@ -117,7 +125,7 @@ public class QuickSearchListItem {
case STREET_INTERSECTION: case STREET_INTERSECTION:
Street street = (Street) searchResult.object; Street street = (Street) searchResult.object;
if (street.getCity() != null) { if (street.getCity() != null) {
return street.getCity().getName(lang, true); return street.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
} }
return ""; return "";
case POI_TYPE: case POI_TYPE:
@ -180,6 +188,10 @@ public class QuickSearchListItem {
} }
public Drawable getTypeIcon() { public Drawable getTypeIcon() {
return getTypeIcon(app, searchResult);
}
public static Drawable getTypeIcon(OsmandApplication app, SearchResult searchResult) {
switch (searchResult.objectType) { switch (searchResult.objectType) {
case FAVORITE: case FAVORITE:
return app.getIconsCache().getThemedIcon(R.drawable.ic_small_group); return app.getIconsCache().getThemedIcon(R.drawable.ic_small_group);
@ -196,6 +208,10 @@ public class QuickSearchListItem {
} }
public Drawable getIcon() { public Drawable getIcon() {
return getIcon(app, searchResult);
}
public static Drawable getIcon(OsmandApplication app, SearchResult searchResult) {
switch (searchResult.objectType) { switch (searchResult.objectType) {
case CITY: case CITY:
return app.getIconsCache().getIcon(R.drawable.ic_action_building_number, return app.getIconsCache().getIcon(R.drawable.ic_action_building_number,

View file

@ -10,7 +10,7 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
private OnClickListener onClickListener; private OnClickListener onClickListener;
public QuickSearchMoreListItem(OsmandApplication app, String name, OnClickListener onClickListener) { public QuickSearchMoreListItem(OsmandApplication app, String name, OnClickListener onClickListener) {
super(app, null, null); super(app, null);
this.name = name; this.name = name;
this.onClickListener = onClickListener; this.onClickListener = onClickListener;
} }