mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Move new Http query together with other ApacheHttpRequests
This commit is contained in:
parent
3b17d96bae
commit
6412e15f20
4 changed files with 29 additions and 31 deletions
|
|
@ -273,7 +273,8 @@ public class ContributionsActivity
|
||||||
CommonsApplication application = CommonsApplication.getInstance();
|
CommonsApplication application = CommonsApplication.getInstance();
|
||||||
|
|
||||||
compositeDisposable.add(
|
compositeDisposable.add(
|
||||||
RxJava2Tasks.getUploadCount(application.getCurrentAccount().name)
|
CommonsApplication.getInstance().getMWApi()
|
||||||
|
.getUploadCount(application.getCurrentAccount().name)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(
|
.subscribe(
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -17,6 +17,7 @@ import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.CoreProtocolPNames;
|
import org.apache.http.params.CoreProtocolPNames;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.mediawiki.api.ApiResult;
|
import org.mediawiki.api.ApiResult;
|
||||||
import org.mediawiki.api.MWApi;
|
import org.mediawiki.api.MWApi;
|
||||||
|
|
||||||
|
|
@ -27,10 +28,13 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import fr.free.nrw.commons.BuildConfig;
|
import fr.free.nrw.commons.BuildConfig;
|
||||||
|
import fr.free.nrw.commons.PageTitle;
|
||||||
import fr.free.nrw.commons.Utils;
|
import fr.free.nrw.commons.Utils;
|
||||||
import in.yuvi.http.fluent.Http;
|
import in.yuvi.http.fluent.Http;
|
||||||
|
import io.reactivex.Single;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -366,4 +370,22 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
||||||
return new UploadResult(resultStatus, dateUploaded, canonicalFilename, imageUrl);
|
return new UploadResult(resultStatus, dateUploaded, canonicalFilename, imageUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public Single<Integer> getUploadCount(String userName) {
|
||||||
|
final String UPLOAD_COUNT_URL_TEMPLATE =
|
||||||
|
"https://tools.wmflabs.org/urbanecmbot/uploadsbyuser/uploadsbyuser.py?user=%s";
|
||||||
|
|
||||||
|
return Single.fromCallable(() -> {
|
||||||
|
String url = String.format(
|
||||||
|
Locale.ENGLISH,
|
||||||
|
UPLOAD_COUNT_URL_TEMPLATE,
|
||||||
|
new PageTitle(userName).getText());
|
||||||
|
HttpResponse response = Http.get(url).use(httpClient).asResponse();
|
||||||
|
String uploadCount = EntityUtils.toString(response.getEntity()).trim();
|
||||||
|
return Integer.parseInt(uploadCount);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.reactivex.Single;
|
||||||
|
|
||||||
public interface MediaWikiApi {
|
public interface MediaWikiApi {
|
||||||
String getAuthCookie();
|
String getAuthCookie();
|
||||||
|
|
||||||
|
|
@ -52,6 +54,9 @@ public interface MediaWikiApi {
|
||||||
@NonNull
|
@NonNull
|
||||||
LogEventResult logEvents(String user, String lastModified, String queryContinue, int limit) throws IOException;
|
LogEventResult logEvents(String user, String lastModified, String queryContinue, int limit) throws IOException;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
Single<Integer> getUploadCount(String userName);
|
||||||
|
|
||||||
interface ProgressListener {
|
interface ProgressListener {
|
||||||
void onProgress(long transferred, long total);
|
void onProgress(long transferred, long total);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue