Preparation for cleaning wiki utils (conversion to retrofit).

master
Tomasz Półgrabia 2016-10-27 22:45:35 +02:00
parent ccca8f803c
commit f8ed253c20
3 changed files with 86 additions and 0 deletions

View File

@ -37,4 +37,7 @@ dependencies {
exclude group: 'com.google.android', module: 'android'
}
compile project(':urbanexplorerutils')
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
}

View File

@ -0,0 +1,40 @@
package pl.tpolgrabia.wikibinding;
import pl.tpolgrabia.wikibinding.dto.geosearch.WikiGeoResponse;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
/**
* Created by tpolgrabia on 27.10.16.
*/
public interface WikiService {
@GET("api.php?action=query&list=geosearch&format=json")
Call<WikiGeoResponse> fetchGeoSearch(
@Query("gscoord") String gscoord,
@Query("gsradius") Double radius,
@Query("gslimit") Long limit);
@GET("api.php" +
"?action=query" +
"&prop=coordinates%7Cpageimages%7Cpageterms" +
"&colimit=50" +
"&piprop=thumbnail" +
"&pithumbsize=144" +
"&pilimit=50" +
"&wbptterms=description" +
"&format=json")
Call<String> fetchPageInfos(
@Query("pageids") String pageIds);
// aq.ajax("https://" + countryCode + ".wikipedia.org/w/api.php" +
// "?action=query" +
// "&prop=coordinates%7Cpageimages%7Cpageterms" +
// "&colimit=50" +
// "&piprop=thumbnail" +
// "&pithumbsize=144" +
// "&pilimit=50" +
// "&wbptterms=description" +
// "&pageids=" + StringUtils.join(pageIds, "|") +
// "&format=json", JSONObject.class, new AjaxCallback<JSONObject>() {
}

View File

@ -6,6 +6,7 @@ import android.widget.Toast;
import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
import com.androidquery.callback.AjaxStatus;
import okhttp3.OkHttpClient;
import org.apache.commons.lang3.StringUtils;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
@ -17,6 +18,7 @@ import pl.tpolgrabia.urbanexplorerutils.events.DataLoadingFinishEvent;
import pl.tpolgrabia.urbanexplorerutils.utils.LocationUtils;
import pl.tpolgrabia.urbanexplorerutils.utils.NetUtils;
import pl.tpolgrabia.urbanexplorerutils.utils.SettingsUtils;
import pl.tpolgrabia.wikibinding.WikiService;
import pl.tpolgrabia.wikibinding.callback.WikiAppResponseCallback;
import pl.tpolgrabia.wikibinding.callback.WikiResponseCallback;
import pl.tpolgrabia.wikibinding.callback.WikiStatus;
@ -28,7 +30,11 @@ import pl.tpolgrabia.wikibinding.dto.generator.WikiThumbnail;
import pl.tpolgrabia.wikibinding.dto.geosearch.WikiGeoObject;
import pl.tpolgrabia.wikibinding.dto.geosearch.WikiGeoResponse;
import pl.tpolgrabia.wikibinding.dto.geosearch.WikiGeoResponseCallback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import java.io.IOException;
import java.util.*;
/**
@ -121,6 +127,26 @@ public class WikiUtils {
return wikiLocation;
}
public Response<WikiGeoResponse> fetchGeoSearchWikiMetadata2(Double latitude,
Double longitude,
Double radius,
Long limit) throws IOException {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
// TODO httpClient.addInterceptor(new RetrofitDebugInterceptor());
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + countryCode + ".wikipedia.org/w/")
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
return retrofit.create(WikiService.class).fetchGeoSearch(
String.format("%s%7C%s", latitude, longitude),
radius,
limit
).execute();
}
public void fetchGeoSearchWikiMetadata(Context ctx,
Double latitude,
Double longitude,
@ -280,6 +306,23 @@ public class WikiUtils {
}
public Response<String> fetchPageInfos2(List<Long> pageIds) throws IOException {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
// TODO httpClient.addInterceptor(new RetrofitDebugInterceptor());
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + countryCode + ".wikipedia.org/w/")
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
return retrofit.create(WikiService.class)
.fetchPageInfos(StringUtils.join(pageIds, "|"))
.execute();
}
public void fetchPageInfos(List<Long> pageIds, final WikiResponseCallback callback) {
AQuery aq = NetUtils.createProxyAQueryInstance(ctx);
aq.ajax("https://" + countryCode + ".wikipedia.org/w/api.php" +