Move new Http query together with other ApacheHttpRequests

This commit is contained in:
Mikel 2017-07-28 14:38:54 +01:00
parent 3b17d96bae
commit 6412e15f20
4 changed files with 29 additions and 31 deletions

View file

@ -273,7 +273,8 @@ public class ContributionsActivity
CommonsApplication application = CommonsApplication.getInstance();
compositeDisposable.add(
RxJava2Tasks.getUploadCount(application.getCurrentAccount().name)
CommonsApplication.getInstance().getMWApi()
.getUploadCount(application.getCurrentAccount().name)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(

View file

@ -1,30 +0,0 @@
package fr.free.nrw.commons.contributions;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Locale;
import fr.free.nrw.commons.PageTitle;
import io.reactivex.Single;
class RxJava2Tasks {
private static final String UPLOAD_COUNT_URL_TEMPLATE =
"https://tools.wmflabs.org/urbanecmbot/uploadsbyuser/uploadsbyuser.py?user=%s";
static Single<Integer> getUploadCount(String userName) {
return Single.fromCallable(() -> {
URL url = new URL(String.format(Locale.ENGLISH, UPLOAD_COUNT_URL_TEMPLATE,
new PageTitle(userName).getText()));
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(urlConnection.getInputStream()));
String uploadCount = bufferedReader.readLine();
bufferedReader.close();
urlConnection.disconnect();
return Integer.parseInt(uploadCount);
});
}
}