mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-03 08:13:55 +01:00
With option for associating image with wikipedia article (#3783)
This commit is contained in:
parent
a4379fde02
commit
e4190f3f7d
28 changed files with 979 additions and 479 deletions
|
|
@ -28,6 +28,7 @@ import timber.log.Timber;
|
|||
public class MediaClient {
|
||||
|
||||
private final MediaInterface mediaInterface;
|
||||
private final PageMediaInterface pageMediaInterface;
|
||||
private final MediaDetailInterface mediaDetailInterface;
|
||||
|
||||
//OkHttpJsonApiClient used JsonKvStore for this. I don't know why.
|
||||
|
|
@ -37,8 +38,11 @@ public class MediaClient {
|
|||
private static final String NO_DEPICTION = "No depiction";
|
||||
|
||||
@Inject
|
||||
public MediaClient(MediaInterface mediaInterface, MediaDetailInterface mediaDetailInterface) {
|
||||
public MediaClient(MediaInterface mediaInterface,
|
||||
PageMediaInterface pageMediaInterface,
|
||||
MediaDetailInterface mediaDetailInterface) {
|
||||
this.mediaInterface = mediaInterface;
|
||||
this.pageMediaInterface = pageMediaInterface;
|
||||
this.mediaDetailInterface = mediaDetailInterface;
|
||||
this.continuationStore = new HashMap<>();
|
||||
this.continuationExists = new HashMap<>();
|
||||
|
|
@ -222,6 +226,13 @@ public class MediaClient {
|
|||
.singleOrError();
|
||||
}
|
||||
|
||||
public Single<Boolean> doesPageContainMedia(String title) {
|
||||
return pageMediaInterface.getMediaList(title)
|
||||
.map(pageMediaListResponse -> {
|
||||
return pageMediaListResponse.getItems().size() > 0;
|
||||
}).singleOrError();
|
||||
}
|
||||
|
||||
private boolean isSuccess(Entities response) {
|
||||
return response != null && response.getSuccess() == 1 && response.entities() != null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package fr.free.nrw.commons.media
|
||||
|
||||
import fr.free.nrw.commons.media.model.PageMediaListResponse
|
||||
import io.reactivex.Observable
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Path
|
||||
|
||||
/**
|
||||
* Interface for MediaWiki Page REST APIs
|
||||
*/
|
||||
interface PageMediaInterface {
|
||||
/**
|
||||
* Get a list of media used on a page
|
||||
*
|
||||
* @param title the title of the page
|
||||
*/
|
||||
@GET("api/rest_v1/page/media-list/{title}")
|
||||
fun getMediaList(@Path("title") title: String?): Observable<PageMediaListResponse?>?
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package fr.free.nrw.commons.media.model
|
||||
|
||||
data class PageMediaListResponse(
|
||||
val revision: String,
|
||||
val tid: String,
|
||||
val items: List<PageMediaListItem>
|
||||
)
|
||||
|
||||
data class PageMediaListItem(val title: String)
|
||||
Loading…
Add table
Add a link
Reference in a new issue