diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java index f642247..b781faa 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java @@ -2,9 +2,11 @@ package pl.tpolgrabia.urbanexplorer.fragments; import android.content.Context; +import android.content.SharedPreferences; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.text.Editable; import android.util.Log; @@ -38,6 +40,8 @@ public class WikiLocationsFragment extends Fragment { private static final String CLASS_TAG = WikiLocationsFragment.class.getSimpleName(); + private static final double WIKI_DEF_RADIUS = 10000.0; + private static final long WIKI_DEF_LIMIT = 100; private LocationManager locationService; private TextView currentLocation; @@ -81,16 +85,11 @@ public class WikiLocationsFragment extends Fragment { return; } - Editable search_limit = ((EditText) getView().findViewById(R.id.wiki_search_limit)).getText(); - Editable radius_limit = ((EditText) getView().findViewById(R.id.wiki_search_radius)).getText(); - - WikiUtils.fetchAppData(getActivity(), location.getLatitude(), location.getLongitude(), - NumberUtils.safeParseDouble(search_limit != null ? search_limit.toString() : null), - NumberUtils.safeParseLong( - radius_limit != null ? radius_limit.toString() : null), + fetchRadiusLimit(), + fetchSearchLimit(), new WikiAppResponseCallback() { @Override public void callback(WikiStatus status, final List appObjects) { @@ -111,6 +110,19 @@ public class WikiLocationsFragment extends Fragment { ); } + private Double fetchRadiusLimit() { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); + final String prefWikiRadius = sharedPreferences.getString("pref_wiki_radius", String.valueOf(WIKI_DEF_RADIUS)); + Log.d(CLASS_TAG, "Pref wiki radius limit " + prefWikiRadius); + return NumberUtils.safeParseDouble(prefWikiRadius)*1000.0; // in m, settings are in km unit + } + private Long fetchSearchLimit() { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); + final String prefWikiResultsLimit = sharedPreferences.getString("pref_wiki_limit", String.valueOf(WIKI_DEF_LIMIT)); + Log.d(CLASS_TAG, "Pref wiki search results limit " + prefWikiResultsLimit); + return NumberUtils.safeParseLong(prefWikiResultsLimit); + } + @Override public void onResume() { super.onResume(); diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/WikiUtils.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/WikiUtils.java index 48d9321..b5ab8f7 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/WikiUtils.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/WikiUtils.java @@ -161,6 +161,11 @@ public class WikiUtils { Long limit, final WikiGeoResponseCallback callback) { + Log.d(CLASS_TAG, "Latitude: " + latitude + + ", longitude: " + longitude + + ", radius: " + radius + + ", limit: " + limit); + if (radius == null) { radius = WIKI_STD_RADIUS; } @@ -170,7 +175,13 @@ public class WikiUtils { } AQuery aq = new AQuery(ctx); - aq.ajax("https://en.wikipedia.org/w/api.php?action=query&list=geosearch&gscoord=" + latitude + "%7C" + longitude + "&gsradius=10000&gslimit=" + limit + "&format=json", JSONObject.class, new AjaxCallback() { + aq.ajax("https://en.wikipedia.org/w/api.php" + + "?action=query" + + "&list=geosearch" + + "&gscoord=" + latitude + "%7C" + longitude + + "&gsradius=" + radius + + "&gslimit=" + limit + + "&format=json", JSONObject.class, new AjaxCallback() { @Override public void callback(String url, JSONObject object, AjaxStatus status) { Log.v(CLASS_TAG, "Finished waiting for " + url @@ -231,6 +242,11 @@ public class WikiUtils { final Long limit, final WikiAppResponseCallback callback) { + Log.d(CLASS_TAG, "Latitude: " + latitude + + ", longitude: " + longitude + + ", radius: " + radius + + ", limit: " + limit); + fetchGeoSearchWikiMetadata(ctx, latitude, longitude, radius, limit, new WikiGeoResponseCallback() { @Override public void callback(WikiStatus status, WikiGeoResponse response) { diff --git a/app/src/main/res/layout/fragment_wiki_locations.xml b/app/src/main/res/layout/fragment_wiki_locations.xml index ae8befd..0f0aa8a 100644 --- a/app/src/main/res/layout/fragment_wiki_locations.xml +++ b/app/src/main/res/layout/fragment_wiki_locations.xml @@ -9,26 +9,6 @@ android:layout_height="wrap_content" android:text="Location:"/> - - - - - - - - - -