#3818 Convert SubDepictionListFragment to use Pagination (#3819)

This commit is contained in:
Seán Mac Gillicuddy 2020-06-25 10:08:15 +01:00 committed by GitHub
parent 34ab6f581b
commit 0e5ba98c2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
82 changed files with 474 additions and 1480 deletions

View file

@ -6,7 +6,6 @@ import com.google.gson.Gson;
import fr.free.nrw.commons.achievements.FeaturedImages;
import fr.free.nrw.commons.achievements.FeedbackResponse;
import fr.free.nrw.commons.campaigns.CampaignResponseDTO;
import fr.free.nrw.commons.depictions.subClass.models.SparqlResponse;
import fr.free.nrw.commons.explore.depictions.DepictsClient;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.Place;
@ -210,16 +209,19 @@ public class OkHttpJsonApiClient {
* Get the QIDs of all Wikidata items that are subclasses of the given Wikidata item. Example:
* bridge -> suspended bridge, aqueduct, etc
*/
public Observable<List<DepictedItem>> getChildQIDs(String qid) throws IOException {
return depictedItemsFrom(sparqlQuery(qid, "/queries/subclasses_query.rq"));
public Observable<List<DepictedItem>> getChildDepictions(String qid, int startPosition,
int limit) throws IOException {
return depictedItemsFrom(sparqlQuery(qid, startPosition, limit,"/queries/subclasses_query.rq"));
}
/**
* Get the QIDs of all Wikidata items that are subclasses of the given Wikidata item. Example:
* bridge -> suspended bridge, aqueduct, etc
*/
public Observable<List<DepictedItem>> getParentQIDs(String qid) throws IOException {
return depictedItemsFrom(sparqlQuery(qid, "/queries/parentclasses_query.rq"));
public Observable<List<DepictedItem>> getParentDepictions(String qid, int startPosition,
int limit) throws IOException {
return depictedItemsFrom(sparqlQuery(qid, startPosition, limit,
"/queries/parentclasses_query.rq"));
}
private Observable<List<DepictedItem>> depictedItemsFrom(Request request) {
@ -231,10 +233,12 @@ public class OkHttpJsonApiClient {
}
@NotNull
private Request sparqlQuery(String qid, String fileName) throws IOException {
String query = FileUtils.readFromResource(fileName).
replace("${QID}", qid)
.replace("${LANG}", "\"" + Locale.getDefault().getLanguage() + "\"");
private Request sparqlQuery(String qid, int startPosition, int limit, String fileName) throws IOException {
String query = FileUtils.readFromResource(fileName)
.replace("${QID}", qid)
.replace("${LANG}", "\"" + Locale.getDefault().getLanguage() + "\"")
.replace("${LIMIT}",""+ limit)
.replace("${OFFSET}",""+ startPosition);
HttpUrl.Builder urlBuilder = HttpUrl
.parse(sparqlQueryUrl)
.newBuilder()

View file

@ -0,0 +1,14 @@
package fr.free.nrw.commons.mwapi
data class SparqlResponse(val results: Result)
data class Result(val bindings: List<Binding>)
data class Binding(
val item: SparqInfo
) {
val id: String
get() = item.value.substringAfterLast("/")
}
data class SparqInfo(val type: String, val value: String)