diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2014-08-12 17:43:29 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2014-08-12 17:45:26 +0200 |
| commit | 60b4fb63eaf44509629d0230f65a9558a6c095d3 (patch) | |
| tree | 88d3525de726ab7fcd548365cae530532766c821 | |
| parent | 6e7ed201b6f8502f48b830aac6f6a7b8ca07e2f7 (diff) | |
| download | cgeo-60b4fb63eaf44509629d0230f65a9558a6c095d3.zip cgeo-60b4fb63eaf44509629d0230f65a9558a6c095d3.tar.gz cgeo-60b4fb63eaf44509629d0230f65a9558a6c095d3.tar.bz2 | |
Never block when building a cache/waypoint details creator
Blocking on the UI thread may prevent other looper threads from
executing, including the ones in charge of receiving the location
updates. This may lead to deadlocks when, for example, starting cgeo
from a cache URL if cgeo has not been started before.
| -rw-r--r-- | main/src/cgeo/geocaching/CgeoApplication.java | 7 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CacheDetailsCreator.java | 17 |
2 files changed, 9 insertions, 15 deletions
diff --git a/main/src/cgeo/geocaching/CgeoApplication.java b/main/src/cgeo/geocaching/CgeoApplication.java index 863dcdd..6eb1235 100644 --- a/main/src/cgeo/geocaching/CgeoApplication.java +++ b/main/src/cgeo/geocaching/CgeoApplication.java @@ -108,6 +108,13 @@ public class CgeoApplication extends Application { return currentGeo != null ? currentGeo : geoDataObservable().toBlocking().first(); } + public Float distanceNonBlocking(final ICoordinates target) { + if (currentGeo == null || target.getCoords() == null) { + return null; + } + return currentGeo.getCoords().distanceTo(target); + } + public float currentDirection() { return currentDirection; } diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java index 78e1dec..40cd726 100644 --- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java +++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java @@ -7,7 +7,6 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.R; import cgeo.geocaching.Waypoint; import cgeo.geocaching.connector.ConnectorFactory; -import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Units; import cgeo.geocaching.utils.Formatter; @@ -152,13 +151,7 @@ public final class CacheDetailsCreator { } public void addDistance(final Geocache cache, final TextView cacheDistanceView) { - Float distance = null; - if (cache.getCoords() != null) { - final Geopoint currentCoords = CgeoApplication.getInstance().currentGeo().getCoords(); - if (currentCoords != null) { - distance = currentCoords.distanceTo(cache); - } - } + Float distance = CgeoApplication.getInstance().distanceNonBlocking(cache); if (distance == null) { if (cache.getDistance() != null) { distance = cache.getDistance(); @@ -177,13 +170,7 @@ public final class CacheDetailsCreator { } public void addDistance(final Waypoint wpt, final TextView waypointDistanceView) { - Float distance = null; - if (wpt.getCoords() != null) { - final Geopoint currentCoords = CgeoApplication.getInstance().currentGeo().getCoords(); - if (currentCoords != null) { - distance = currentCoords.distanceTo(wpt); - } - } + Float distance = CgeoApplication.getInstance().distanceNonBlocking(wpt); String text = "--"; if (distance != null) { text = Units.getDistanceFromKilometers(distance); |
