Fix mapbox addresses

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

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

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

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

@ -80,29 +80,21 @@ public class MapboxSearchProvider implements PlaceSearchProvider {
@Override
public void fetch(
PlaceSearchResult placeSearchResult, Callback<Place> onSuccess, Callback<String> onError) {
CarmenFeature carmenFeature = (CarmenFeature) placeSearchResult.getTag();
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);
onSuccess.call(placeSearchResult.getPlace());
}
private PlaceSearchResult toSearchResult(CarmenFeature feature) {
String name = getName(feature);
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();
return types != null && types.contains(TYPE_ADDRESS)
? String.format("%s %s", feature.address(), feature.text())
: feature.text();
Place place = newPlace();
place.setName(
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;
import org.tasks.data.Place;
public class PlaceSearchResult {
private final String id;
private final String name;
private final String address;
private final Object tag;
private final Place place;
@SuppressWarnings("unused")
PlaceSearchResult(String id, String name, String address) {
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.name = name;
this.address = address;
this.tag = tag;
this.place = place;
}
public String getId() {
@ -30,8 +33,8 @@ public class PlaceSearchResult {
return address;
}
public Object getTag() {
return tag;
public Place getPlace() {
return place;
}
@Override
@ -54,7 +57,7 @@ public class PlaceSearchResult {
if (address != null ? !address.equals(that.address) : that.address != null) {
return false;
}
return tag != null ? tag.equals(that.tag) : that.tag == null;
return place != null ? place.equals(that.place) : that.place == null;
}
@Override
@ -62,7 +65,7 @@ public class PlaceSearchResult {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (name != null ? name.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;
}
@ -78,8 +81,8 @@ public class PlaceSearchResult {
+ ", address='"
+ address
+ '\''
+ ", tag="
+ tag
+ ", place="
+ place
+ '}';
}
}

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

Loading…
Cancel
Save