Fixes #2337 - Show captions of image in media details (conflicts fixed) (#2933)

* Api call

* added captions

* final commit

* some minor changes

* sigular

* test for captions

* mock fetchCaptionbyFileName

* corrected method name

* * used ? instead of !! (unsafe call on nullable)
* updated unit test for fetchCaptionByFilename()
This commit is contained in:
neslihanturan 2019-05-01 12:38:38 +03:00 committed by Ashish Kumar
parent 047059c490
commit 3c9b7ba7a8
9 changed files with 137 additions and 6 deletions

View file

@ -3,6 +3,7 @@ package fr.free.nrw.commons.mwapi;
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
@ -303,6 +304,26 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
.getString("/api/flow-parsoid-utils/@content"));
}
/**
* fetches the Caption of the file with a given name.
* @param filename title of the file
* @return a single with media caption
*/
@Override
public Single<String> fetchCaptionByFilename(String filename) {
return Single.fromCallable(() -> {
CustomApiResult apiResult = api.action("wbgetentities")
.param("sites", "commonswiki")
.param("titles", filename)
.param("props", "labels")
.param("format", "xml")
.param("languages", Locale.getDefault().getLanguage())
.param("languagefallback", "1")
.get();
return apiResult.getString("/api/entities/entity/labels/label/@value");
});
}
@Override
@NonNull
public Single<MediaResult> fetchMediaByFilename(String filename) {

View file

@ -66,6 +66,8 @@ public interface MediaWikiApi {
Single<String> parseWikicode(String source);
Single<String> fetchCaptionByFilename(String filename);
@NonNull
Single<MediaResult> fetchMediaByFilename(String filename);