mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Use Single to get firstRevision
This commit is contained in:
parent
342a768f5f
commit
82a6a1a686
4 changed files with 29 additions and 17 deletions
|
|
@ -607,16 +607,19 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
public Revision firstRevisionOfFile(String filename) throws IOException {
|
||||
ApiResult res = api.action("query")
|
||||
.param("prop", "revisions")
|
||||
.param("rvprop", "timestamp|ids|user")
|
||||
.param("titles", filename)
|
||||
.param("rvdir", "newer")
|
||||
.param("rvlimit", "1")
|
||||
.get();
|
||||
return new Revision(res.getString("/api/query/pages/page/revisions/rev/@revid"),
|
||||
res.getString("/api/query/pages/page/revisions/rev/@user"));
|
||||
public Single<Revision> firstRevisionOfFile(String filename) {
|
||||
return Single.fromCallable(() -> {
|
||||
ApiResult res = api.action("query")
|
||||
.param("prop", "revisions")
|
||||
.param("rvprop", "timestamp|ids|user")
|
||||
.param("titles", filename)
|
||||
.param("rvdir", "newer")
|
||||
.param("rvlimit", "1")
|
||||
.get();
|
||||
return new Revision(
|
||||
res.getString("/api/query/pages/page/revisions/rev/@revid"),
|
||||
res.getString("/api/query/pages/page/revisions/rev/@user"));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ public interface MediaWikiApi {
|
|||
|
||||
boolean thank(String editToken, String revision) throws IOException;
|
||||
|
||||
Revision firstRevisionOfFile(String filename) throws IOException;
|
||||
Single<Revision> firstRevisionOfFile(String filename);
|
||||
|
||||
interface ProgressListener {
|
||||
void onProgress(long transferred, long total);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ import java.util.ArrayList;
|
|||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.delete.DeleteTask;
|
||||
import fr.free.nrw.commons.mwapi.Revision;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by nes on 19.05.2018.
|
||||
|
|
@ -15,6 +18,7 @@ import fr.free.nrw.commons.delete.DeleteTask;
|
|||
|
||||
public class ReviewController {
|
||||
public static String fileName;
|
||||
public static Revision firstRevision; // TODO: maybe we can expand this class to include fileName
|
||||
protected static ArrayList<String> categories;
|
||||
ReviewPagerAdapter reviewPagerAdapter;
|
||||
ViewPager viewPager;
|
||||
|
|
@ -29,6 +33,12 @@ public class ReviewController {
|
|||
public void onImageRefreshed(String fileName) {
|
||||
ReviewController.fileName = fileName;
|
||||
ReviewController.categories = new ArrayList<>();
|
||||
|
||||
reviewActivity.mwApi.firstRevisionOfFile("File:" + fileName).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(revision -> {
|
||||
ReviewController.firstRevision = revision;
|
||||
});
|
||||
}
|
||||
|
||||
public void onCategoriesRefreshed(ArrayList<String> categories) {
|
||||
|
|
@ -64,7 +74,7 @@ public class ReviewController {
|
|||
}
|
||||
|
||||
public void sendThanks() {
|
||||
new SendThankTask(reviewActivity, new Media("File:"+fileName)).execute();
|
||||
new SendThankTask(reviewActivity, new Media("File:"+fileName), firstRevision).execute();
|
||||
swipeToNext();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ import android.support.v4.app.NotificationCompat;
|
|||
import android.view.Gravity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import fr.free.nrw.commons.Media;
|
||||
|
|
@ -17,6 +15,8 @@ import fr.free.nrw.commons.auth.SessionManager;
|
|||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import fr.free.nrw.commons.mwapi.Revision;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.support.v4.app.NotificationCompat.DEFAULT_ALL;
|
||||
|
|
@ -48,10 +48,10 @@ public class SendThankTask extends AsyncTask<Void, Integer, Boolean> {
|
|||
private Media media;
|
||||
private Revision revision;
|
||||
|
||||
public SendThankTask(Context context, Media media){
|
||||
public SendThankTask(Context context, Media media, Revision revision){
|
||||
this.context = context;
|
||||
this.media = media;
|
||||
|
||||
this.revision = revision;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -80,7 +80,6 @@ public class SendThankTask extends AsyncTask<Void, Integer, Boolean> {
|
|||
mwApi.setAuthCookie(authCookie);
|
||||
|
||||
try {
|
||||
revision = mwApi.firstRevisionOfFile(media.getFilename());
|
||||
editToken = mwApi.getEditToken();
|
||||
if (editToken.equals("+\\")) {
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue