Rename Description to Label to prevent misunderstandings

This commit is contained in:
misaochan 2017-12-31 02:34:36 +10:00
parent b27163906b
commit dd9976cfff
5 changed files with 21 additions and 22 deletions

View file

@ -374,7 +374,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
commonsButton.setEnabled(place.hasCommonsLink()); commonsButton.setEnabled(place.hasCommonsLink());
commonsButton.setOnClickListener(view -> openWebView(place.siteLinks.getCommonsLink())); commonsButton.setOnClickListener(view -> openWebView(place.siteLinks.getCommonsLink()));
icon.setImageResource(place.getDescription().getIcon()); icon.setImageResource(place.getLabel().getIcon());
description.setText(place.getLongDescription()); description.setText(place.getLongDescription());
title.setText(place.name.toString()); title.setText(place.name.toString());

View file

@ -126,7 +126,7 @@ public class NearbyPlaces {
places.add(new Place( places.add(new Place(
name, name,
Place.Description.fromText(type), // list Place.Label.fromText(type), // list
type, // details type, // details
Uri.parse(icon), Uri.parse(icon),
new LatLng(latitude, longitude, 0), new LatLng(latitude, longitude, 0),
@ -188,7 +188,7 @@ public class NearbyPlaces {
places.add(new Place( places.add(new Place(
name, name,
Place.Description.fromText(type), // list Place.Label.fromText(type), // list
type, // details type, // details
null, null,
new LatLng(latitude, longitude, 0), new LatLng(latitude, longitude, 0),

View file

@ -13,7 +13,7 @@ import fr.free.nrw.commons.location.LatLng;
public class Place { public class Place {
public final String name; public final String name;
private final Description description; private final Label label;
private final String longDescription; private final String longDescription;
private final Uri secondaryImageUrl; private final Uri secondaryImageUrl;
public final LatLng location; public final LatLng location;
@ -24,10 +24,10 @@ public class Place {
public final Sitelinks siteLinks; 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) { Uri secondaryImageUrl, LatLng location, Sitelinks siteLinks) {
this.name = name; this.name = name;
this.description = description; this.label = label;
this.longDescription = longDescription; this.longDescription = longDescription;
this.secondaryImageUrl = secondaryImageUrl; this.secondaryImageUrl = secondaryImageUrl;
this.location = location; this.location = location;
@ -36,8 +36,8 @@ public class Place {
public String getName() { return name; } public String getName() { return name; }
public Description getDescription() { public Label getLabel() {
return description; return label;
} }
public String getLongDescription() { return longDescription; } public String getLongDescription() { return longDescription; }
@ -86,7 +86,7 @@ public class Place {
* *
* TODO Give a more accurate class name (see issue #742). * TODO Give a more accurate class name (see issue #742).
*/ */
public enum Description { public enum Label {
BUILDING("building", R.drawable.round_icon_generic_building), BUILDING("building", R.drawable.round_icon_generic_building),
HOUSE("house", R.drawable.round_icon_house), HOUSE("house", R.drawable.round_icon_house),
@ -111,19 +111,19 @@ public class Place {
WATERFALL("waterfall", R.drawable.round_icon_waterfall), WATERFALL("waterfall", R.drawable.round_icon_waterfall),
UNKNOWN("?", R.drawable.round_icon_unknown); UNKNOWN("?", R.drawable.round_icon_unknown);
private static final Map<String, Description> TEXT_TO_DESCRIPTION private static final Map<String, Label> TEXT_TO_DESCRIPTION
= new HashMap<>(Description.values().length); = new HashMap<>(Label.values().length);
static { static {
for (Description description : values()) { for (Label label : values()) {
TEXT_TO_DESCRIPTION.put(description.text, description); TEXT_TO_DESCRIPTION.put(label.text, label);
} }
} }
private final String text; private final String text;
@DrawableRes private final int icon; @DrawableRes private final int icon;
Description(String text, @DrawableRes int icon) { Label(String text, @DrawableRes int icon) {
this.text = text; this.text = text;
this.icon = icon; this.icon = icon;
} }
@ -137,9 +137,9 @@ public class Place {
return icon; return icon;
} }
public static Description fromText(String text) { public static Label fromText(String text) {
Description description = TEXT_TO_DESCRIPTION.get(text); Label label = TEXT_TO_DESCRIPTION.get(text);
return description == null ? UNKNOWN : description; return label == null ? UNKNOWN : label;
} }
} }
} }

View file

@ -13,7 +13,6 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.pedrogomez.renderers.Renderer; import com.pedrogomez.renderers.Renderer;
import java.util.ArrayList; import java.util.ArrayList;
@ -96,13 +95,13 @@ class PlaceRenderer extends Renderer<Place> {
public void render() { public void render() {
place = getContent(); place = getContent();
tvName.setText(place.name); tvName.setText(place.name);
String descriptionText = place.getDescription().getText(); String descriptionText = place.getLabel().getText();
if (descriptionText.equals("?")) { if (descriptionText.equals("?")) {
descriptionText = getContext().getString(R.string.no_description_found); descriptionText = getContext().getString(R.string.no_description_found);
} }
tvDesc.setText(descriptionText); tvDesc.setText(descriptionText);
distance.setText(place.distance); distance.setText(place.distance);
icon.setImageResource(place.getDescription().getIcon()); icon.setImageResource(place.getLabel().getIcon());
directionsButton.setOnClickListener(view -> { directionsButton.setOnClickListener(view -> {
//Open map app at given position //Open map app at given position

View file

@ -30,9 +30,9 @@ import static org.junit.Assert.assertNotNull;
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class) @Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
public class NearbyAdapterFactoryTest { 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); "desc", null, new LatLng(38.6270, -90.1994, 0), null);
private static final Place UNKNOWN_PLACE = new Place("name", Place.Description.UNKNOWN, private static final Place UNKNOWN_PLACE = new Place("name", Place.Label.UNKNOWN,
"desc", null, new LatLng(39.7392, -104.9903, 0), null); "desc", null, new LatLng(39.7392, -104.9903, 0), null);
private Place clickedPlace; private Place clickedPlace;