[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.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<QuickSearchListItem> 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<QuickSearchListItem> 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<QuickSearchListItem> 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;

View file

@ -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,

View file

@ -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;
}