Add feature to Browse commons via app (#1716)

* Search activity, image search fragment added

* Removed explore icon xml

* Updated Javadocs for search Activity and Navigation Base Activity

* SearchImageItem class updated

* Javadocs added for search activity

* removed redundant code and added javadocs for search image modules

* Javadocs added for updateImageList  method

* Rename featuredImage to explore

* Fixed null query issue

* changed cisibility to gone in case of successful Fetch

* Consolidate the networking libraries - drop volley in favor of OkHttp

* Extracted a few networking related items into a new Dagger module and finished the process of mocking the main component for tests.

* Refactoring to extract GpsCategoryModel and ensure single-responsibility-principle is maintained in CategoryApi.

* fixed featured image back bug

* Localisation updates from https://translatewiki.net.

* Javadocs added

* Add option to set image as wallpaper (#1535)

* Add option to set image as wallpaper

* Added java docs

* Toast message on setting the wallpaper successfully

* Localisation updates from https://translatewiki.net.

* SearchHistory Fragment added

* Search History Item added

* Content Provider, RecentSearchesDao added

* Database version changed to 7 and added methods for find, save ,..

* Delete icon deleted

* Reverted changes in gradle files

* Reverted changes in gradle files 2

* Optimized Improts

* reverted refractor for container name

* Refactored packagename, changed name to query in POJO class.

* Updated lastUsed to lastSearched

* Javadocs updated

* Check if user has been in search page for 5 seconds if yes then save it to history

* If else indentation updated

* added import in test

* edittext replaced with Searchview

* RxSearchview added

* Added support for API 21+

* Snackbar removed on success

* Improved code

* Pagination added

* Removed unnecessary toast

* Comment added in method

* Support for landscape mode added

* Fixed screen rotation issue on Explore and Search activity

* Clear focus added

* Delete all function added in Content Provider and called from fragment

* Scrollbar Recyclerview added

* Share Icon changed to 32 dp and back button added in explore, search activity.

* Removed unnecessary code

* Wrote and run tests for Recent Searches
 (creating db, migrating from versions, deletion, finding,..

* Category Search Fragment added

* Adapter factory added

* Renderer added

* Improvements

* Viewpager adapter added

* Updated XML

* Improvements in category card design

* tabs colors changed

* renamed images to media

* Java docs improved

* Javadoc added for setTabs

* JavaDoc for ViewPagerAdapter added

* Refreshed listview after delete

* Added mediaContainer

* Fixed ghost issue in image search fragment

* Ghost issue for categories fixed

* Removed Calling API call onback press

* Category Details activity added

* Menu added in category details activity

* back button added

* back button bugs

* Improvements in category images fragment

* JavaDoc added for some methods

* trimming added, Tab layout hided, recent searches refreshed

* SubCategory list fragment added, API added to extract subCategory Details

* API params updated to get more precise results

* Javadocs added for MWAPI method

* Pagination removed

* Fix API for fetching images inside category

* Parent category API added

* Fix #1704

* Fix #1704 corrected

* Fix #1702

* Fix #1702 and #1704

* added try catch statements

* Optimimzed imports

* loops replaced with Functions

* Javadocs for various methods added

* Fix java docs for Dao

* Javadocs for various methods added

* Fix java docs for Dao

* More javadocs added for explore Feature

* Javadocs added

* Javadocs added

* Improvements in indentation (#1739)
This commit is contained in:
Ujjwal Agrawal 2018-07-24 12:47:24 +05:30 committed by neslihanturan
parent 2171b6846d
commit 86878fb62d
70 changed files with 3030 additions and 78 deletions

View file

@ -35,6 +35,7 @@ import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@ -570,6 +571,89 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
return NotificationUtils.getNotificationsFromList(context, childNodes);
}
/**
* The method takes categoryName as input and returns a List of Subcategories
* It uses the generator query API to get the subcategories in a category, 500 at a time.
* Uses the query continue values for fetching paginated responses
* @param categoryName Category name as defined on commons
* @return
*/
@Override
@NonNull
public List<String> getSubCategoryList(String categoryName) {
ApiResult apiResult = null;
try {
MWApi.RequestBuilder requestBuilder = api.action("query")
.param("generator", "categorymembers")
.param("format", "xml")
.param("gcmtype","subcat")
.param("gcmtitle", categoryName)
.param("prop", "info")
.param("gcmlimit", "500")
.param("iiprop", "url|extmetadata");
apiResult = requestBuilder.get();
} catch (IOException e) {
Timber.e("Failed to obtain searchCategories", e);
}
if (apiResult == null) {
return new ArrayList<>();
}
ApiResult categoryImagesNode = apiResult.getNode("/api/query/pages");
if (categoryImagesNode == null
|| categoryImagesNode.getDocument() == null
|| categoryImagesNode.getDocument().getChildNodes() == null
|| categoryImagesNode.getDocument().getChildNodes().getLength() == 0) {
return new ArrayList<>();
}
NodeList childNodes = categoryImagesNode.getDocument().getChildNodes();
return CategoryImageUtils.getSubCategoryList(childNodes);
}
/**
* The method takes categoryName as input and returns a List of parent categories
* It uses the generator query API to get the parent categories of a category, 500 at a time.
* @param categoryName Category name as defined on commons
* @return
*/
@Override
@NonNull
public List<String> getParentCategoryList(String categoryName) {
ApiResult apiResult = null;
try {
MWApi.RequestBuilder requestBuilder = api.action("query")
.param("generator", "categories")
.param("format", "xml")
.param("titles", categoryName)
.param("prop", "info")
.param("cllimit", "500")
.param("iiprop", "url|extmetadata");
apiResult = requestBuilder.get();
} catch (IOException e) {
Timber.e("Failed to obtain parent Categories", e);
}
if (apiResult == null) {
return new ArrayList<>();
}
ApiResult categoryImagesNode = apiResult.getNode("/api/query/pages");
if (categoryImagesNode == null
|| categoryImagesNode.getDocument() == null
|| categoryImagesNode.getDocument().getChildNodes() == null
|| categoryImagesNode.getDocument().getChildNodes().getLength() == 0) {
return new ArrayList<>();
}
NodeList childNodes = categoryImagesNode.getDocument().getChildNodes();
return CategoryImageUtils.getSubCategoryList(childNodes);
}
/**
* The method takes categoryName as input and returns a List of Media objects
* It uses the generator query API to get the images in a category, 10 at a time.
@ -598,7 +682,6 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
requestBuilder.param("continue", queryContinueValues.getContinueParam());
requestBuilder.param("gcmcontinue", queryContinueValues.getGcmContinueParam());
}
apiResult = requestBuilder.get();
} catch (IOException e) {
Timber.e("Failed to obtain searchCategories", e);
@ -616,13 +699,93 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
return new ArrayList<>();
}
QueryContinue queryContinue = getQueryContinue(apiResult.getNode("/api/continue").getDocument());
setQueryContinueValues(categoryName, queryContinue);
if (apiResult.getNode("/api/continue").getDocument()==null){
setQueryContinueValues(categoryName, null);
}else {
QueryContinue queryContinue = getQueryContinue(apiResult.getNode("/api/continue").getDocument());
setQueryContinueValues(categoryName, queryContinue);
}
NodeList childNodes = categoryImagesNode.getDocument().getChildNodes();
return CategoryImageUtils.getMediaList(childNodes);
}
/**
* This method takes search keyword as input and returns a list of Media objects filtered using search query
* It uses the generator query API to get the images searched using a query, 25 at a time.
* @param query keyword to search images on commons
* @return
*/
@Override
@NonNull
public List<Media> searchImages(String query, int offset) {
List<ApiResult> imageNodes = null;
try {
imageNodes = 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");
} catch (IOException e) {
Timber.e("Failed to obtain searchImages", e);
}
if (imageNodes == null) {
return new ArrayList<Media>();
}
List<Media> images = new ArrayList<>();
for (ApiResult imageNode : imageNodes) {
String imgName = imageNode.getDocument().getTextContent();
images.add(new Media(imgName));
}
return images;
}
/**
* This method takes search keyword as input and returns a list of categories objects filtered using search query
* It uses the generator query API to get the categories searched using a query, 25 at a time.
* @param query keyword to search categories on commons
* @return
*/
@Override
@NonNull
public List<String> searchCategory(String query, int offset) {
List<ApiResult> categoryNodes = null;
try {
categoryNodes = api.action("query")
.param("format", "xml")
.param("list", "search")
.param("srwhat", "text")
.param("srnamespace", "14")
.param("srlimit", "25")
.param("sroffset",offset)
.param("srsearch", query)
.get()
.getNodes("/api/query/search/p/@title");
} catch (IOException e) {
Timber.e("Failed to obtain searchCategories", e);
}
if (categoryNodes == null) {
return new ArrayList<String>();
}
List<String> categories = new ArrayList<>();
for (ApiResult categoryNode : categoryNodes) {
String catName = categoryNode.getDocument().getTextContent();
categories.add(catName);
}
return categories;
}
/**
* For APIs that return paginated responses, MediaWiki APIs uses the QueryContinue to facilitate fetching of subsequent pages
* https://www.mediawiki.org/wiki/API:Raw_query_continue

View file

@ -41,6 +41,16 @@ public interface MediaWikiApi {
List<Media> getCategoryImages(String categoryName);
List<String> getSubCategoryList(String categoryName);
List<String> getParentCategoryList(String categoryName);
@NonNull
List<Media> searchImages(String title, int offset);
@NonNull
List<String> searchCategory(String title, int offset);
@NonNull
UploadResult uploadFile(String filename, InputStream file, long dataLength, String pageContents, String editSummary, ProgressListener progressListener) throws IOException;