Added settings for wiki search.

master
Tomasz Półgrabia 2016-09-14 21:51:37 +02:00
parent 34e0d698c4
commit 29c2232e25
3 changed files with 36 additions and 28 deletions

View File

@ -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<WikiAppObject> 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();

View File

@ -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<JSONObject>() {
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<JSONObject>() {
@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) {

View File

@ -9,26 +9,6 @@
android:layout_height="wrap_content"
android:text="Location:"/>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wiki_search_radius"/>
<EditText android:id="@+id/wiki_search_radius"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wiki_search_limit"/>
<EditText android:id="@+id/wiki_search_limit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<ListView android:id="@+id/wiki_places"
android:layout_width="match_parent"
android:layout_height="0dp"