Fix mapbox addresses

pull/795/head
Alex Baker 6 years ago
parent 36cbfe65c0
commit ec3debb140

@ -126,6 +126,10 @@ public class Location implements Serializable, Parcelable {
return place.getDisplayName(); return place.getDisplayName();
} }
public String getDisplayAddress() {
return place.getDisplayAddress();
}
public String getGeoUri() { public String getGeoUri() {
return place.getGeoUri(); return place.getGeoUri();
} }

@ -154,16 +154,16 @@ public class Place implements Serializable, Parcelable {
} }
public String getDisplayName() { public String getDisplayName() {
if (Strings.isNullOrEmpty(address)) { if (Strings.isNullOrEmpty(address) || !COORDS.matcher(name).matches()) {
return name; return name;
} }
if (COORDS.matcher(name).matches()) { return address;
return address; }
}
if (address.startsWith(name)) { public String getDisplayAddress() {
return address; return Strings.isNullOrEmpty(address)
} ? null
return name; : address.replace(String.format("%s, ", name), "");
} }
String getGeoUri() { String getGeoUri() {

@ -72,7 +72,7 @@ public class LocationPickerAdapter extends ListAdapter<PlaceUsage, PlaceViewHold
public void bind(PlaceUsage placeUsage) { public void bind(PlaceUsage placeUsage) {
place = placeUsage.place; place = placeUsage.place;
String name = place.getDisplayName(); String name = place.getDisplayName();
String address = place.getAddress(); String address = place.getDisplayAddress();
this.name.setText(name); this.name.setText(name);
if (Strings.isNullOrEmpty(address) || address.equals(name)) { if (Strings.isNullOrEmpty(address) || address.equals(name)) {
this.address.setVisibility(View.GONE); this.address.setVisibility(View.GONE);

@ -80,29 +80,21 @@ public class MapboxSearchProvider implements PlaceSearchProvider {
@Override @Override
public void fetch( public void fetch(
PlaceSearchResult placeSearchResult, Callback<Place> onSuccess, Callback<String> onError) { PlaceSearchResult placeSearchResult, Callback<Place> onSuccess, Callback<String> onError) {
CarmenFeature carmenFeature = (CarmenFeature) placeSearchResult.getTag(); onSuccess.call(placeSearchResult.getPlace());
org.tasks.data.Place place = newPlace();
place.setName(placeSearchResult.getName());
place.setAddress(placeSearchResult.getAddress());
place.setLatitude(carmenFeature.center().latitude());
place.setLongitude(carmenFeature.center().longitude());
onSuccess.call(place);
} }
private PlaceSearchResult toSearchResult(CarmenFeature feature) { private PlaceSearchResult toSearchResult(CarmenFeature feature) {
String name = getName(feature);
String address = feature.placeName(); String address = feature.placeName();
String replace = String.format("%s, ", name);
if (address != null && address.startsWith(replace)) {
address = address.replace(replace, "");
}
return new PlaceSearchResult(feature.id(), name, address, feature);
}
private String getName(CarmenFeature feature) {
List<String> types = feature.placeType(); List<String> types = feature.placeType();
return types != null && types.contains(TYPE_ADDRESS) Place place = newPlace();
? String.format("%s %s", feature.address(), feature.text()) place.setName(
: feature.text(); types != null && types.contains(TYPE_ADDRESS)
? String.format("%s %s", feature.address(), feature.text())
: feature.text());
place.setAddress(address);
place.setLatitude(feature.center().latitude());
place.setLongitude(feature.center().longitude());
return new PlaceSearchResult(
feature.id(), place.getName(), place.getDisplayAddress(), place);
} }
} }

@ -1,21 +1,24 @@
package org.tasks.location; package org.tasks.location;
import org.tasks.data.Place;
public class PlaceSearchResult { public class PlaceSearchResult {
private final String id; private final String id;
private final String name; private final String name;
private final String address; private final String address;
private final Object tag; private final Place place;
@SuppressWarnings("unused")
PlaceSearchResult(String id, String name, String address) { PlaceSearchResult(String id, String name, String address) {
this(id, name, address, null); this(id, name, address, null);
} }
PlaceSearchResult(String id, String name, String address, Object tag) { PlaceSearchResult(String id, String name, String address, Place place) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.address = address; this.address = address;
this.tag = tag; this.place = place;
} }
public String getId() { public String getId() {
@ -30,8 +33,8 @@ public class PlaceSearchResult {
return address; return address;
} }
public Object getTag() { public Place getPlace() {
return tag; return place;
} }
@Override @Override
@ -54,7 +57,7 @@ public class PlaceSearchResult {
if (address != null ? !address.equals(that.address) : that.address != null) { if (address != null ? !address.equals(that.address) : that.address != null) {
return false; return false;
} }
return tag != null ? tag.equals(that.tag) : that.tag == null; return place != null ? place.equals(that.place) : that.place == null;
} }
@Override @Override
@ -62,7 +65,7 @@ public class PlaceSearchResult {
int result = id != null ? id.hashCode() : 0; int result = id != null ? id.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0); result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (address != null ? address.hashCode() : 0); result = 31 * result + (address != null ? address.hashCode() : 0);
result = 31 * result + (tag != null ? tag.hashCode() : 0); result = 31 * result + (place != null ? place.hashCode() : 0);
return result; return result;
} }
@ -78,8 +81,8 @@ public class PlaceSearchResult {
+ ", address='" + ", address='"
+ address + address
+ '\'' + '\''
+ ", tag=" + ", place="
+ tag + place
+ '}'; + '}';
} }
} }

@ -122,7 +122,7 @@ public class LocationControlSet extends TaskEditControlFragment {
? R.drawable.ic_outline_notifications_24px ? R.drawable.ic_outline_notifications_24px
: R.drawable.ic_outline_notifications_off_24px); : R.drawable.ic_outline_notifications_off_24px);
String name = this.location.getDisplayName(); String name = this.location.getDisplayName();
String address = this.location.getAddress(); String address = this.location.getDisplayAddress();
if (!Strings.isNullOrEmpty(address) && !address.equals(name)) { if (!Strings.isNullOrEmpty(address) && !address.equals(name)) {
locationAddress.setText(address); locationAddress.setText(address);
locationAddress.setVisibility(View.VISIBLE); locationAddress.setVisibility(View.VISIBLE);

Loading…
Cancel
Save