mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Use an enum for the place description
This commit is contained in:
parent
1b2c327116
commit
5d6bada4c8
5 changed files with 84 additions and 101 deletions
|
|
@ -121,7 +121,7 @@ public class NearbyInfoDialog extends OverlayDialog {
|
||||||
NearbyInfoDialog mDialog = new NearbyInfoDialog();
|
NearbyInfoDialog mDialog = new NearbyInfoDialog();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(ARG_TITLE, place.name);
|
bundle.putString(ARG_TITLE, place.name);
|
||||||
bundle.putString(ARG_DESC, place.description);
|
bundle.putString(ARG_DESC, place.getDescription().getText());
|
||||||
bundle.putDouble(ARG_LATITUDE, place.location.getLatitude());
|
bundle.putDouble(ARG_LATITUDE, place.location.getLatitude());
|
||||||
bundle.putDouble(ARG_LONGITUDE, place.location.getLongitude());
|
bundle.putDouble(ARG_LONGITUDE, place.location.getLongitude());
|
||||||
bundle.putParcelable(ARG_SITE_LINK, place.siteLinks);
|
bundle.putParcelable(ARG_SITE_LINK, place.siteLinks);
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ public class NearbyPlaces {
|
||||||
|
|
||||||
places.add(new Place(
|
places.add(new Place(
|
||||||
name,
|
name,
|
||||||
type, // list
|
Place.Description.fromText(type), // list
|
||||||
type, // details
|
type, // details
|
||||||
Uri.parse(icon),
|
Uri.parse(icon),
|
||||||
new LatLng(latitude, longitude, 0),
|
new LatLng(latitude, longitude, 0),
|
||||||
|
|
@ -184,7 +184,7 @@ public class NearbyPlaces {
|
||||||
|
|
||||||
places.add(new Place(
|
places.add(new Place(
|
||||||
name,
|
name,
|
||||||
type, // list
|
Place.Description.fromText(type), // list
|
||||||
type, // details
|
type, // details
|
||||||
null,
|
null,
|
||||||
new LatLng(latitude, longitude, 0),
|
new LatLng(latitude, longitude, 0),
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.ViewHolder;
|
import fr.free.nrw.commons.ViewHolder;
|
||||||
import fr.free.nrw.commons.utils.ResourceUtils;
|
|
||||||
|
|
||||||
public class NearbyViewHolder implements ViewHolder<Place> {
|
public class NearbyViewHolder implements ViewHolder<Place> {
|
||||||
@BindView(R.id.tvName) TextView tvName;
|
@BindView(R.id.tvName) TextView tvName;
|
||||||
|
|
@ -25,12 +24,12 @@ public class NearbyViewHolder implements ViewHolder<Place> {
|
||||||
public void bindModel(Context context, Place place) {
|
public void bindModel(Context context, Place place) {
|
||||||
// Populate the data into the template view using the data object
|
// Populate the data into the template view using the data object
|
||||||
tvName.setText(place.name);
|
tvName.setText(place.name);
|
||||||
String description = place.description;
|
String descriptionText = place.getDescription().getText();
|
||||||
if ( description == null || description.isEmpty() || description.equals("?")) {
|
if (descriptionText.equals("?")) {
|
||||||
description = context.getString(R.string.no_description_found);
|
descriptionText = context.getString(R.string.no_description_found);
|
||||||
}
|
}
|
||||||
tvDesc.setText(description);
|
tvDesc.setText(descriptionText);
|
||||||
distance.setText(place.distance);
|
distance.setText(place.distance);
|
||||||
icon.setImageResource(ResourceUtils.getDescriptionIcon(place.description));
|
icon.setImageResource(place.getDescription().getIcon());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,18 @@ package fr.free.nrw.commons.nearby;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.location.LatLng;
|
||||||
|
|
||||||
public class Place {
|
public class Place {
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String description;
|
private final Description description;
|
||||||
public final String longDescription;
|
public final String longDescription;
|
||||||
public final Uri secondaryImageUrl;
|
public final Uri secondaryImageUrl;
|
||||||
public final LatLng location;
|
public final LatLng location;
|
||||||
|
|
@ -19,7 +24,7 @@ public class Place {
|
||||||
public Sitelinks siteLinks;
|
public Sitelinks siteLinks;
|
||||||
|
|
||||||
|
|
||||||
public Place(String name, String description, String longDescription,
|
public Place(String name, Description description, String longDescription,
|
||||||
Uri secondaryImageUrl, LatLng location, Sitelinks siteLinks) {
|
Uri secondaryImageUrl, LatLng location, Sitelinks siteLinks) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
|
@ -29,6 +34,10 @@ public class Place {
|
||||||
this.siteLinks = siteLinks;
|
this.siteLinks = siteLinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Description getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
public void setDistance(String distance) {
|
public void setDistance(String distance) {
|
||||||
this.distance = distance;
|
this.distance = distance;
|
||||||
}
|
}
|
||||||
|
|
@ -53,4 +62,68 @@ public class Place {
|
||||||
return String.format("Place(%s@%s)", name, location);
|
return String.format("Place(%s@%s)", name, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See https://github.com/commons-app/apps-android-commons/issues/250
|
||||||
|
* Most common types of desc: building, house, cottage, farmhouse,
|
||||||
|
* village, civil parish, church, railway station,
|
||||||
|
* gatehouse, milestone, inn, secondary school, hotel
|
||||||
|
*
|
||||||
|
* TODO Give a more accurate class name (see issue #742).
|
||||||
|
*/
|
||||||
|
public enum Description {
|
||||||
|
|
||||||
|
BUILDING("building", R.drawable.round_icon_generic_building),
|
||||||
|
HOUSE("house", R.drawable.round_icon_house),
|
||||||
|
COTTAGE("cottage", R.drawable.round_icon_house),
|
||||||
|
FARMHOUSE("farmhouse", R.drawable.round_icon_house),
|
||||||
|
CHURCH("church", R.drawable.round_icon_church),
|
||||||
|
RAILWAY_STATION("railway station", R.drawable.round_icon_railway_station),
|
||||||
|
GATEHOUSE("gatehouse", R.drawable.round_icon_gatehouse),
|
||||||
|
MILESTONE("milestone", R.drawable.round_icon_milestone),
|
||||||
|
INN("inn", R.drawable.round_icon_house),
|
||||||
|
CITY("city", R.drawable.round_icon_city),
|
||||||
|
SECONDARY_SCHOOL("secondary school", R.drawable.round_icon_school),
|
||||||
|
EDU("edu", R.drawable.round_icon_school),
|
||||||
|
ISLE("isle", R.drawable.round_icon_island),
|
||||||
|
MOUNTAIN("mountain", R.drawable.round_icon_mountain),
|
||||||
|
AIRPORT("airport", R.drawable.round_icon_airport),
|
||||||
|
BRIDGE("bridge", R.drawable.round_icon_bridge),
|
||||||
|
ROAD("road", R.drawable.round_icon_road),
|
||||||
|
FOREST("forest", R.drawable.round_icon_forest),
|
||||||
|
PARK("park", R.drawable.round_icon_park),
|
||||||
|
RIVER("river", R.drawable.round_icon_river),
|
||||||
|
WATERFALL("waterfall", R.drawable.round_icon_waterfall),
|
||||||
|
UNKNOWN("?", R.drawable.round_icon_unknown);
|
||||||
|
|
||||||
|
private static final Map<String, Description> TEXT_TO_DESCRIPTION
|
||||||
|
= new HashMap<>(Description.values().length);
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (Description description : values()) {
|
||||||
|
TEXT_TO_DESCRIPTION.put(description.text, description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String text;
|
||||||
|
@DrawableRes private final int icon;
|
||||||
|
|
||||||
|
Description(String text, @DrawableRes int icon) {
|
||||||
|
this.text = text;
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DrawableRes
|
||||||
|
public int getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Description fromText(String text) {
|
||||||
|
Description description = TEXT_TO_DESCRIPTION.get(text);
|
||||||
|
return description == null ? UNKNOWN : description;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
package fr.free.nrw.commons.utils;
|
|
||||||
|
|
||||||
import android.support.annotation.DrawableRes;
|
|
||||||
|
|
||||||
import fr.free.nrw.commons.R;
|
|
||||||
|
|
||||||
public class ResourceUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See https://github.com/commons-app/apps-android-commons/issues/250
|
|
||||||
* Most common types of desc: building, house, cottage, farmhouse,
|
|
||||||
* village, civil parish, church, railway station,
|
|
||||||
* gatehouse, milestone, inn, secondary school, hotel
|
|
||||||
* @param description Place description
|
|
||||||
* @return icon res id
|
|
||||||
*/
|
|
||||||
@DrawableRes
|
|
||||||
public static int getDescriptionIcon(String description) {
|
|
||||||
int resourceId;
|
|
||||||
switch (description) {
|
|
||||||
case "building":
|
|
||||||
resourceId = R.drawable.round_icon_generic_building;
|
|
||||||
break;
|
|
||||||
case "house":
|
|
||||||
resourceId = R.drawable.round_icon_house;
|
|
||||||
break;
|
|
||||||
case "cottage":
|
|
||||||
resourceId = R.drawable.round_icon_house;
|
|
||||||
break;
|
|
||||||
case "farmhouse":
|
|
||||||
resourceId = R.drawable.round_icon_house;
|
|
||||||
break;
|
|
||||||
case "church":
|
|
||||||
resourceId = R.drawable.round_icon_church;
|
|
||||||
break;
|
|
||||||
case "railway station":
|
|
||||||
resourceId = R.drawable.round_icon_railway_station;
|
|
||||||
break;
|
|
||||||
case "gatehouse":
|
|
||||||
resourceId = R.drawable.round_icon_gatehouse;
|
|
||||||
break;
|
|
||||||
case "milestone":
|
|
||||||
resourceId = R.drawable.round_icon_milestone;
|
|
||||||
break;
|
|
||||||
case "inn":
|
|
||||||
resourceId = R.drawable.round_icon_house;
|
|
||||||
break;
|
|
||||||
case "city":
|
|
||||||
resourceId = R.drawable.round_icon_city;
|
|
||||||
break;
|
|
||||||
case "secondary school":
|
|
||||||
resourceId = R.drawable.round_icon_school;
|
|
||||||
break;
|
|
||||||
case "edu":
|
|
||||||
resourceId = R.drawable.round_icon_school;
|
|
||||||
break;
|
|
||||||
case "isle":
|
|
||||||
resourceId = R.drawable.round_icon_island;
|
|
||||||
break;
|
|
||||||
case "mountain":
|
|
||||||
resourceId = R.drawable.round_icon_mountain;
|
|
||||||
break;
|
|
||||||
case "airport":
|
|
||||||
resourceId = R.drawable.round_icon_airport;
|
|
||||||
break;
|
|
||||||
case "bridge":
|
|
||||||
resourceId = R.drawable.round_icon_bridge;
|
|
||||||
break;
|
|
||||||
case "road":
|
|
||||||
resourceId = R.drawable.round_icon_road;
|
|
||||||
break;
|
|
||||||
case "forest":
|
|
||||||
resourceId = R.drawable.round_icon_forest;
|
|
||||||
break;
|
|
||||||
case "park":
|
|
||||||
resourceId = R.drawable.round_icon_park;
|
|
||||||
break;
|
|
||||||
case "river":
|
|
||||||
resourceId = R.drawable.round_icon_river;
|
|
||||||
break;
|
|
||||||
case "waterfall":
|
|
||||||
resourceId = R.drawable.round_icon_waterfall;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
resourceId = R.drawable.round_icon_unknown;
|
|
||||||
}
|
|
||||||
return resourceId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue