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 ab05f32..4e1070c 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java @@ -8,17 +8,14 @@ import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; - -import android.widget.Button; -import android.widget.ListView; -import android.widget.TextView; -import android.widget.Toast; +import android.widget.*; import pl.tpolgrabia.urbanexplorer.R; import pl.tpolgrabia.urbanexplorer.adapters.WikiLocationsAdapter; import pl.tpolgrabia.urbanexplorer.callbacks.WikiResponseCallback; import pl.tpolgrabia.urbanexplorer.callbacks.WikiStatus; import pl.tpolgrabia.urbanexplorer.dto.WikiResponse; import pl.tpolgrabia.urbanexplorer.utils.LocationUtils; +import pl.tpolgrabia.urbanexplorer.utils.NumberUtils; import pl.tpolgrabia.urbanexplorer.utils.WikiUtils; import static android.content.Context.LOCATION_SERVICE; @@ -61,22 +58,30 @@ public class WikiLocationsFragment extends Fragment { @Override public void onClick(View v) { final Location location = locationService.getLastKnownLocation(LocationUtils.getDefaultLocation(getActivity())); - WikiUtils.fetchNearPlaces(getActivity(), location.getLatitude(), location.getLongitude(), 10L, new WikiResponseCallback() { - @Override - public void callback(WikiStatus status, WikiResponse response) { - // handling here wiki locations - if (status != WikiStatus.SUCCESS) { - Toast.makeText(getActivity(), "Sorry, currently we have problem with interfacing wiki" + - ": " + status + ". Try again later", Toast.LENGTH_SHORT).show(); - return; + WikiUtils.fetchNearPlaces( + getActivity(), + location.getLatitude(), + location.getLongitude(), + NumberUtils.safeParseLong( + ((EditText) inflatedView.findViewById(R.id.wiki_search_limit)).getText()), + NumberUtils.safeParseLong( + ((EditText) inflatedView.findViewById(R.id.wiki_search_radius)).getText()), + new WikiResponseCallback() { + @Override + public void callback(WikiStatus status, WikiResponse response) { + // handling here wiki locations + if (status != WikiStatus.SUCCESS) { + Toast.makeText(getActivity(), "Sorry, currently we have problem with interfacing wiki" + + ": " + status + ". Try again later", Toast.LENGTH_SHORT).show(); + return; + } + + // TODO on success + + ListView locations = (ListView) inflatedView.findViewById(R.id.wiki_places); + locations.setAdapter(new WikiLocationsAdapter(getActivity(), response.getPages())); } - - // TODO on success - - ListView locations = (ListView) inflatedView.findViewById(R.id.wiki_places); - locations.setAdapter(new WikiLocationsAdapter(getActivity(), response.getPages())); - } - }); + }); } }); 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 7e50874..196adf3 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/WikiUtils.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/WikiUtils.java @@ -31,6 +31,7 @@ public class WikiUtils { final double latitude, final double longitude, final long resultsLimit, + final long radiusLimit, final WikiResponseCallback callback) { final AQuery aq = new AQuery(ctx); aq.ajax("TODO", JSONObject.class, new AjaxCallback(){ @@ -47,7 +48,7 @@ public class WikiUtils { "&wbptterms=description" + "&generator=geosearch" + "&ggscoord=" + latitude + "%7C" + longitude + - "&ggsradius=10000" + + "&ggsradius=" + radiusLimit + "&ggslimit=" + resultsLimit + "&format=" + WIKI_FORMAT; aq.ajax(qurl, JSONObject.class, new AjaxCallback() { diff --git a/app/src/main/res/layout/fragment_wiki_locations.xml b/app/src/main/res/layout/fragment_wiki_locations.xml index 93ed334..ec4a16b 100644 --- a/app/src/main/res/layout/fragment_wiki_locations.xml +++ b/app/src/main/res/layout/fragment_wiki_locations.xml @@ -18,6 +18,15 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/> + + + + Location y-range Location x-range Search radius + Search results\' limit