Improve code around PassLocation
This commit is contained in:
parent
13af2cce7e
commit
6d9fd3b13e
5 changed files with 27 additions and 30 deletions
|
@ -1,21 +0,0 @@
|
|||
package org.ligi.passandroid.model.pass;
|
||||
|
||||
public class PassLocation {
|
||||
|
||||
private String name;
|
||||
public double lat;
|
||||
public double lon;
|
||||
|
||||
public String getName(Pass pass) {
|
||||
if (name == null) {
|
||||
// fallback for passes with locations without description - e.g. AirBerlin
|
||||
return pass.getDescription();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package org.ligi.passandroid.model.pass
|
||||
|
||||
class PassLocation {
|
||||
|
||||
var name: String? = null
|
||||
|
||||
var lat: Double = 0.toDouble()
|
||||
var lon: Double = 0.toDouble()
|
||||
|
||||
fun getNameWithFallback(pass: Pass): String? {
|
||||
if (name == null || name!!.isEmpty()) {
|
||||
// fallback for passes with locations without description - e.g. AirBerlin
|
||||
return pass.description
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
}
|
|
@ -141,7 +141,7 @@ object AppleStylePassReader {
|
|||
location.lon = obj.getDouble("longitude")
|
||||
|
||||
if (obj.has("relevantText")) {
|
||||
location.setName(translation.translate(obj.getString("relevantText")))
|
||||
location.name = translation.translate(obj.getString("relevantText"))
|
||||
}
|
||||
|
||||
locations.add(location)
|
||||
|
|
|
@ -29,7 +29,7 @@ public class NavigateToLocationsDialog {
|
|||
|
||||
int i = 0;
|
||||
for (PassLocation loc : locations) {
|
||||
locationDescriptions[i++] = loc.getName(pass);
|
||||
locationDescriptions[i++] = loc.getNameWithFallback(pass);
|
||||
}
|
||||
new AlertDialog.Builder(activity).setTitle(activity.getString(R.string.choose_location))
|
||||
.setItems(locationDescriptions, new DialogInterface.OnClickListener() {
|
||||
|
@ -55,12 +55,12 @@ public class NavigateToLocationsDialog {
|
|||
|
||||
final String description = getEncodedDescription(location, pass);
|
||||
|
||||
final String latAndLonStr = location.lat + "," + location.lon;
|
||||
final String latAndLonStr = location.getLat() + "," + location.getLon();
|
||||
i.setData(Uri.parse("geo:" + latAndLonStr + "?q=" + latAndLonStr + "(" + description + ")"));
|
||||
try {
|
||||
activity.startActivity(i);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
i.setData(Uri.parse("http://maps.google.com/?q=" + description + "@" + location.lat + "," + location.lon));
|
||||
i.setData(Uri.parse("http://maps.google.com/?q=" + description + "@" + location.getLat() + "," + location.getLon()));
|
||||
activity.startActivity(i);
|
||||
// TODO also the browser could not be found -> handle
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class NavigateToLocationsDialog {
|
|||
|
||||
private static String getEncodedDescription(final PassLocation location, @Nonnull final Pass pass) {
|
||||
try {
|
||||
return URLEncoder.encode(location.getName(pass), "UTF-8");
|
||||
return URLEncoder.encode(location.getNameWithFallback(pass), "UTF-8");
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
// OK - no description
|
||||
return "";
|
||||
|
|
|
@ -57,10 +57,10 @@ public class LocationsMapFragment extends SupportMapFragment {
|
|||
for (PassLocation l : locations) {
|
||||
|
||||
// yea that looks stupid but need to split LatLng free/nonfree - google play services ^^
|
||||
final LatLng latLng = new LatLng(l.lat, l.lon);
|
||||
map.addMarker(new MarkerOptions().position(latLng).title(l.getName(base_activity.currentPass))
|
||||
//.icon(BitmapDescriptorFactory.fromBitmap(base_activity.passbook.getIconBitmap())));
|
||||
);
|
||||
final LatLng latLng = new LatLng(l.getLat(), l.getLon());
|
||||
final MarkerOptions marker = new MarkerOptions().position(latLng).title(l.getNameWithFallback(base_activity.currentPass));
|
||||
map.addMarker(marker);
|
||||
|
||||
|
||||
boundBuilder = boundBuilder.include(latLng);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue