Adding limit.

master
Tomasz Półgrabia 2016-09-01 22:32:08 +02:00
parent 920e1543fe
commit f3fc8622e8
4 changed files with 37 additions and 21 deletions

View File

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

View File

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

View File

@ -18,6 +18,15 @@
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"

View File

@ -14,4 +14,5 @@
<string name="location_yrange">Location y-range</string>
<string name="location_xrange">Location x-range</string>
<string name="wiki_search_radius">Search radius</string>
<string name="wiki_search_limit">Search results\' limit</string>
</resources>