diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2015-09-03 09:22:38 +0200 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2015-09-03 09:22:38 +0200 |
commit | cc51d0b52143195b4a6c565b6294cebecc74ac6e (patch) | |
tree | 4ccb28eea7ad8857404fb212f9905c8483634071 | |
parent | bb53896df7007dcf7fee020ec4201d661f72898c (diff) | |
parent | 1b383b1d39c410c0862ced058e9819528a185496 (diff) | |
download | cgeo-cc51d0b52143195b4a6c565b6294cebecc74ac6e.zip cgeo-cc51d0b52143195b4a6c565b6294cebecc74ac6e.tar.gz cgeo-cc51d0b52143195b4a6c565b6294cebecc74ac6e.tar.bz2 |
Merge branch 'release' into upstream
-rw-r--r-- | main/src/cgeo/geocaching/AddressListActivity.java | 4 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/location/GCGeocoder.java | 65 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/location/GeocoderTest.java | 4 |
3 files changed, 1 insertions, 72 deletions
diff --git a/main/src/cgeo/geocaching/AddressListActivity.java b/main/src/cgeo/geocaching/AddressListActivity.java index 4ff48f6..fe8b988 100644 --- a/main/src/cgeo/geocaching/AddressListActivity.java +++ b/main/src/cgeo/geocaching/AddressListActivity.java @@ -2,7 +2,6 @@ package cgeo.geocaching; import cgeo.geocaching.activity.AbstractListActivity; import cgeo.geocaching.location.AndroidGeocoder; -import cgeo.geocaching.location.GCGeocoder; import cgeo.geocaching.location.MapQuestGeocoder; import cgeo.geocaching.ui.AddressListAdapter; @@ -34,8 +33,7 @@ public class AddressListActivity extends AbstractListActivity { private void lookupAddressInBackground(final String keyword, final AddressListAdapter adapter, final ProgressDialog waitDialog) { final Observable<Address> geocoderObservable = new AndroidGeocoder(this).getFromLocationName(keyword) - .onErrorResumeNext(MapQuestGeocoder.getFromLocationName(keyword)) - .onErrorResumeNext(GCGeocoder.getFromLocationName(keyword)); + .onErrorResumeNext(MapQuestGeocoder.getFromLocationName(keyword)); AppObservable.bindActivity(this, geocoderObservable.toList()).subscribe(new Action1<List<Address>>() { @Override public void call(final List<Address> addresses) { diff --git a/main/src/cgeo/geocaching/location/GCGeocoder.java b/main/src/cgeo/geocaching/location/GCGeocoder.java deleted file mode 100644 index 549044f..0000000 --- a/main/src/cgeo/geocaching/location/GCGeocoder.java +++ /dev/null @@ -1,65 +0,0 @@ -package cgeo.geocaching.location; - -import cgeo.geocaching.network.Network; -import cgeo.geocaching.network.Parameters; -import cgeo.geocaching.settings.Settings; -import cgeo.geocaching.utils.Log; -import cgeo.geocaching.utils.RxUtils; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.annotation.NonNull; - -import rx.Observable; -import rx.functions.Func0; - -import android.location.Address; - -import java.util.Locale; - -public class GCGeocoder { - - private GCGeocoder() { - // Do not instantiate - } - - /** - * Retrieve addresses from a textual location using geocaching.com geocoding API. The work happens on the network - * scheduler. - * - * @param address - * the location - * @return an observable containing zero or more locations - * - * @see android.location.Geocoder#getFromLocationName(String, int) - */ - public static Observable<Address> getFromLocationName(@NonNull final String address) { - return Observable.defer(new Func0<Observable<Address>>() { - @Override - public Observable<Address> call() { - if (!Settings.isGCConnectorActive()) { - return Observable.error(new RuntimeException("geocaching.com connector is not active")); - } - final ObjectNode response = Network.requestJSON("https://www.geocaching.com/api/geocode", new Parameters("q", address)); - if (response == null || !StringUtils.equalsIgnoreCase(response.path("status").asText(), "success")) { - return Observable.error(new RuntimeException("unable to use geocaching.com geocoder")); - } - - final JsonNode data = response.path("data"); - final Address geocodedAddress = new Address(Locale.getDefault()); - try { - geocodedAddress.setLatitude(data.get("lat").asDouble()); - geocodedAddress.setLongitude(data.get("lng").asDouble()); - geocodedAddress.setAddressLine(0, address); - return Observable.just(geocodedAddress); - } catch (final Exception e) { - Log.e("unable to decode answer from geocaching.com geocoder", e); - return Observable.error(e); - } - } - }).subscribeOn(RxUtils.networkScheduler); - } - -} diff --git a/tests/src/cgeo/geocaching/location/GeocoderTest.java b/tests/src/cgeo/geocaching/location/GeocoderTest.java index b7f10a3..a1d2239 100644 --- a/tests/src/cgeo/geocaching/location/GeocoderTest.java +++ b/tests/src/cgeo/geocaching/location/GeocoderTest.java @@ -41,10 +41,6 @@ public class GeocoderTest extends CGeoTestCase { } } - public static void testGCGeocoder() { - testGeocoder(GCGeocoder.getFromLocationName(TEST_ADDRESS), "GC", false); - } - public static void testMapQuestGeocoder() { final Locale locale = Locale.getDefault(); try { |