Skip to content

Fix issue with Nearby item descriptions #1034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static void showYourself(FragmentActivity fragmentActivity, Place place)
NearbyInfoDialog mDialog = new NearbyInfoDialog();
Bundle bundle = new Bundle();
bundle.putString(ARG_TITLE, place.name);
bundle.putString(ARG_DESC, place.getDescription().getText());
bundle.putString(ARG_DESC, place.getLongDescription());
bundle.putDouble(ARG_LATITUDE, place.location.getLatitude());
bundle.putDouble(ARG_LONGITUDE, place.location.getLongitude());
bundle.putParcelable(ARG_SITE_LINK, place.siteLinks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private List<Place> getFromWikidataQuery(LatLng cur,

places.add(new Place(
name,
Place.Description.fromText(type), // list
Place.Label.fromText(type), // list
type, // details
Uri.parse(icon),
new LatLng(latitude, longitude, 0),
Expand Down Expand Up @@ -188,7 +188,7 @@ List<Place> getFromWikiNeedsPictures() {

places.add(new Place(
name,
Place.Description.fromText(type), // list
Place.Label.fromText(type), // list
type, // details
null,
new LatLng(latitude, longitude, 0),
Expand Down
34 changes: 18 additions & 16 deletions app/src/main/java/fr/free/nrw/commons/nearby/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class Place {

public final String name;
private final Description description;
private final Label label;
private final String longDescription;
private final Uri secondaryImageUrl;
public final LatLng location;
Expand All @@ -24,18 +24,22 @@ public class Place {
public final Sitelinks siteLinks;


public Place(String name, Description description, String longDescription,
public Place(String name, Label label, String longDescription,
Uri secondaryImageUrl, LatLng location, Sitelinks siteLinks) {
this.name = name;
this.description = description;
this.label = label;
this.longDescription = longDescription;
this.secondaryImageUrl = secondaryImageUrl;
this.location = location;
this.siteLinks = siteLinks;
}

public Description getDescription() {
return description;
public Label getLabel() {
return label;
}

public String getLongDescription() {
return longDescription;
}

public void setDistance(String distance) {
Expand Down Expand Up @@ -67,10 +71,8 @@ public String toString() {
* 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 {
public enum Label {

BUILDING("building", R.drawable.round_icon_generic_building),
HOUSE("house", R.drawable.round_icon_house),
Expand All @@ -95,19 +97,19 @@ public enum Description {
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);
private static final Map<String, Label> TEXT_TO_DESCRIPTION
= new HashMap<>(Label.values().length);

static {
for (Description description : values()) {
TEXT_TO_DESCRIPTION.put(description.text, description);
for (Label label : values()) {
TEXT_TO_DESCRIPTION.put(label.text, label);
}
}

private final String text;
@DrawableRes private final int icon;

Description(String text, @DrawableRes int icon) {
Label(String text, @DrawableRes int icon) {
this.text = text;
this.icon = icon;
}
Expand All @@ -121,9 +123,9 @@ public int getIcon() {
return icon;
}

public static Description fromText(String text) {
Description description = TEXT_TO_DESCRIPTION.get(text);
return description == null ? UNKNOWN : description;
public static Label fromText(String text) {
Label label = TEXT_TO_DESCRIPTION.get(text);
return label == null ? UNKNOWN : label;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ protected void hookListeners(View view) {
public void render() {
Place place = getContent();
tvName.setText(place.name);
String descriptionText = place.getDescription().getText();
String descriptionText = place.getLongDescription();
if (descriptionText.equals("?")) {
descriptionText = getContext().getString(R.string.no_description_found);
}
tvDesc.setText(descriptionText);
distance.setText(place.distance);
icon.setImageResource(place.getDescription().getIcon());
icon.setImageResource(place.getLabel().getIcon());
}

interface PlaceClickedListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
public class NearbyAdapterFactoryTest {

private static final Place PLACE = new Place("name", Place.Description.AIRPORT,
private static final Place PLACE = new Place("name", Place.Label.AIRPORT,
"desc", null, new LatLng(38.6270, -90.1994, 0), null);
private static final Place UNKNOWN_PLACE = new Place("name", Place.Description.UNKNOWN,
"desc", null, new LatLng(39.7392, -104.9903, 0), null);
private static final Place UNKNOWN_PLACE = new Place("name", Place.Label.UNKNOWN,
"?", null, new LatLng(39.7392, -104.9903, 0), null);
// ^ "?" is a special value for unknown class names from Wikidata query results
private Place clickedPlace;

@Test
Expand Down Expand Up @@ -68,12 +69,13 @@ public void rendererCorrectlyBound() {

RendererViewHolder viewHolder = renderComponent(result);

// test that the values we gave are actually rendered
assertNotNull(viewHolder.itemView.findViewById(R.id.tvName));
assertEquals("name",
assertEquals(PLACE.name,
((TextView) viewHolder.itemView.findViewById(R.id.tvName)).getText().toString());

assertNotNull(viewHolder.itemView.findViewById(R.id.tvDesc));
assertEquals("airport",
assertEquals(PLACE.getLongDescription(),
((TextView) viewHolder.itemView.findViewById(R.id.tvDesc)).getText().toString());

assertNotNull(viewHolder.itemView.findViewById(R.id.distance));
Expand All @@ -94,7 +96,7 @@ public void rendererCorrectlyBoundForUnknownPlace() {
RendererViewHolder viewHolder = renderComponent(result);

assertNotNull(viewHolder.itemView.findViewById(R.id.tvDesc));
assertEquals("no description found",
assertEquals(RuntimeEnvironment.application.getString(R.string.no_description_found),
((TextView) viewHolder.itemView.findViewById(R.id.tvDesc)).getText().toString());

assertNotNull(viewHolder.itemView.findViewById(R.id.icon));
Expand Down