#3772 Convert SearchImagesFragment to use Pagination (#3779)

This commit is contained in:
Seán Mac Gillicuddy 2020-06-16 14:58:48 +01:00 committed by GitHub
parent e4190f3f7d
commit c77ed747fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 386 additions and 419 deletions

View file

@ -124,14 +124,12 @@ public class MediaClient {
* It uses the generator query API to get the images searched using a query, 10 at a time.
*
* @param keyword the search keyword
* @param limit
* @param offset
* @return
*/
public Single<List<Media>> getMediaListFromSearch(String keyword) {
return responseToMediaList(
continuationStore.containsKey("search_" + keyword) && (continuationStore.get("search_" + keyword) != null) ?
mediaInterface.getMediaListFromSearch(keyword, 10, continuationStore.get("search_" + keyword)) : //if true
mediaInterface.getMediaListFromSearch(keyword, 10, Collections.emptyMap()), //if false
"search_" + keyword);
public Single<MwQueryResponse> getMediaListFromSearch(String keyword, int limit, int offset) {
return mediaInterface.getMediaListFromSearch(keyword, limit, offset);
}
@ -270,9 +268,10 @@ public class MediaClient {
}
}
throw new RuntimeException("failed getEntities");
})
.singleOrError();
});
}
public Single<Entities> getEntities(String entityId) {
return mediaDetailInterface.getEntity(entityId);
}
}

View file

@ -1,6 +1,7 @@
package fr.free.nrw.commons.media;
import io.reactivex.Observable;
import io.reactivex.Single;
import org.wikipedia.wikidata.Entities;
import retrofit2.http.GET;
import retrofit2.http.Query;
@ -24,7 +25,7 @@ public interface MediaDetailInterface {
*
*/
@GET("/w/api.php?format=json&action=wbgetentities&props=labels&languagefallback=1")
Observable<Entities> getEntity(@Query("ids") String entityId);
Single<Entities> getEntity(@Query("ids") String entityId);
/**
* Fetches caption using wikibaseIdentifier

View file

@ -2,6 +2,7 @@ package fr.free.nrw.commons.media;
import fr.free.nrw.commons.depictions.models.DepictionResponse;
import io.reactivex.Observable;
import io.reactivex.Single;
import java.util.Map;
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
import retrofit2.http.GET;
@ -65,13 +66,13 @@ public interface MediaInterface {
*
* @param keyword the searched keyword
* @param itemLimit how many images are returned
* @param continuation the continuation string from the previous query
* @param offset the offset in the result set
* @return
*/
@GET("w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
"&generator=search&gsrwhat=text&gsrnamespace=6" + //Search parameters
MEDIA_PARAMS)
Observable<MwQueryResponse> getMediaListFromSearch(@Query("gsrsearch") String keyword, @Query("gsrlimit") int itemLimit, @QueryMap Map<String, String> continuation);
Single<MwQueryResponse> getMediaListFromSearch(@Query("gsrsearch") String keyword, @Query("gsrlimit") int itemLimit, @Query("gsroffset") int offset);
/**
* Fetches Media object from the imageInfo API