mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Updated API to get Author name too
This commit is contained in:
parent
f12f1d50a3
commit
c93bcda6f6
2 changed files with 21 additions and 15 deletions
|
|
@ -65,11 +65,11 @@ class SearchImagesRenderer extends Renderer<Media> {
|
|||
*/
|
||||
private void setAuthorView(Media item, TextView author) {
|
||||
if (item.getCreator() != null && !item.getCreator().equals("")) {
|
||||
author.setVisibility(View.GONE);
|
||||
author.setVisibility(View.VISIBLE);
|
||||
String uploadedByTemplate = getContext().getString(R.string.image_uploaded_by);
|
||||
author.setText(String.format(uploadedByTemplate, item.getCreator()));
|
||||
} else {
|
||||
author.setVisibility(View.VISIBLE);
|
||||
author.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -736,17 +736,21 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
@NonNull
|
||||
public List<Media> searchImages(String query, int offset) {
|
||||
List<CustomApiResult> imageNodes = null;
|
||||
List<CustomApiResult> authorNodes = null;
|
||||
CustomApiResult customApiResult;
|
||||
try {
|
||||
imageNodes = api.action("query")
|
||||
customApiResult= api.action("query")
|
||||
.param("format", "xml")
|
||||
.param("list", "search")
|
||||
.param("srwhat", "text")
|
||||
.param("srnamespace", "6")
|
||||
.param("srlimit", "25")
|
||||
.param("sroffset",offset)
|
||||
.param("srsearch", query)
|
||||
.get()
|
||||
.getNodes("/api/query/search/p/@title");
|
||||
.param("generator", "search")
|
||||
.param("gsrwhat", "text")
|
||||
.param("gsrnamespace", "6")
|
||||
.param("gsrlimit", "25")
|
||||
.param("gsroffset",offset)
|
||||
.param("gsrsearch", query)
|
||||
.param("prop", "imageinfo")
|
||||
.get();
|
||||
imageNodes= customApiResult.getNodes("/api/query/pages/page/@title");
|
||||
authorNodes= customApiResult.getNodes("/api/query/pages/page/imageinfo/ii/@user");
|
||||
} catch (IOException e) {
|
||||
Timber.e("Failed to obtain searchImages", e);
|
||||
}
|
||||
|
|
@ -756,11 +760,13 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
}
|
||||
|
||||
List<Media> images = new ArrayList<>();
|
||||
for (CustomApiResult imageNode : imageNodes) {
|
||||
String imgName = imageNode.getDocument().getTextContent();
|
||||
images.add(new Media(imgName));
|
||||
}
|
||||
|
||||
for (int i=0; i< imageNodes.size();i++){
|
||||
String imgName = imageNodes.get(i).getDocument().getTextContent();
|
||||
Media media = new Media(imgName);
|
||||
media.setCreator(authorNodes.get(i).getDocument().getTextContent());
|
||||
images.add(media);
|
||||
}
|
||||
return images;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue