Skip to content

Commit ac1258d

Browse files
committed
As per commons-app#3026, migrated CategoryApi to retrofit
1 parent 90d4e49 commit ac1258d

File tree

3 files changed

+47
-109
lines changed

3 files changed

+47
-109
lines changed

app/src/main/java/fr/free/nrw/commons/category/CategoryClient.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
@Singleton
2222
public class CategoryClient {
2323

24-
private final CategoryInterface CategoryInterface;
24+
private final CategoryInterface categoryInterface;
2525

2626
@Inject
2727
public CategoryClient(CategoryInterface CategoryInterface) {
28-
this.CategoryInterface = CategoryInterface;
28+
this.categoryInterface = CategoryInterface;
2929
}
3030

3131
/**
@@ -37,7 +37,7 @@ public CategoryClient(CategoryInterface CategoryInterface) {
3737
* @return
3838
*/
3939
public Observable<String> searchCategories(String filter, int itemLimit, int offset) {
40-
return responseToCategoryName(CategoryInterface.searchCategories(filter, itemLimit, offset));
40+
return responseToCategoryName(categoryInterface.searchCategories(filter, itemLimit, offset));
4141

4242
}
4343

@@ -62,7 +62,7 @@ public Observable<String> searchCategories(String filter, int itemLimit) {
6262
* @return
6363
*/
6464
public Observable<String> searchCategoriesForPrefix(String prefix, int itemLimit, int offset) {
65-
return responseToCategoryName(CategoryInterface.searchCategoriesForPrefix(prefix, itemLimit, offset));
65+
return responseToCategoryName(categoryInterface.searchCategoriesForPrefix(prefix, itemLimit, offset));
6666
}
6767

6868
/**
@@ -85,7 +85,7 @@ public Observable<String> searchCategoriesForPrefix(String prefix, int itemLimit
8585
* @return Observable emitting the categories returned. If our search yielded "Category:Test", "Test" is emitted.
8686
*/
8787
public Observable<String> getSubCategoryList(String categoryName) {
88-
return responseToCategoryName(CategoryInterface.getSubCategoryList(categoryName));
88+
return responseToCategoryName(categoryInterface.getSubCategoryList(categoryName));
8989
}
9090

9191
/**
@@ -97,7 +97,32 @@ public Observable<String> getSubCategoryList(String categoryName) {
9797
*/
9898
@NonNull
9999
public Observable<String> getParentCategoryList(String categoryName) {
100-
return responseToCategoryName(CategoryInterface.getParentCategoryList(categoryName));
100+
return responseToCategoryName(categoryInterface.getParentCategoryList(categoryName));
101+
}
102+
103+
@NonNull
104+
public Observable<String> getGpsCategories(String coords) {
105+
return categoryInterface.getGpsCategories(coords, 10000, coords, 20)
106+
.flatMap(mwQueryResponse -> {
107+
MwQueryResult query;
108+
List<MwQueryPage> pages;
109+
if ((query = mwQueryResponse.query()) == null ||
110+
(pages = query.pages()) == null) {
111+
Timber.d("No files returned.");
112+
return Observable.empty();
113+
} else
114+
return Observable.fromIterable(pages);
115+
})
116+
.flatMap(page -> {
117+
if (page.categories() != null) {
118+
return Observable.fromIterable(page.categories());
119+
}
120+
Timber.d("No categories in file %s", page.title());
121+
return Observable.empty();
122+
})
123+
.map(MwQueryPage.Category::title)
124+
.doOnEach(s -> Timber.d("Category returned: %s", s))
125+
.map(cat -> cat.replace("Category:", ""));
101126
}
102127

103128
/**

app/src/main/java/fr/free/nrw/commons/category/CategoryInterface.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,20 @@ Observable<MwQueryResponse> searchCategoriesForPrefix(@Query("gacprefix") String
4444
+ "&generator=categories&prop=info&gcllimit=500")
4545
Observable<MwQueryResponse> getParentCategoryList(@Query("titles") String categoryName);
4646

47+
/**
48+
* @param searchCoords
49+
* @param radius
50+
* @param centerCoords
51+
* @param limit
52+
* @return
53+
*/
54+
@GET("w/api.php?action=query&format=json&formatversion=2" +
55+
"&generator=geosearch&ggsnamespace=6" +
56+
"&prop=categories|coordinates|pageprops&clshow=!hidden" +
57+
"&coprop=type|name|dim|country|region|globe" +
58+
"&ggsprop=type|name|dim|country|region|globe&ggsprimary=all")
59+
Observable<MwQueryResponse> getGpsCategories(@Query("ggscoord") String searchCoords,
60+
@Query("ggsradius") int radius,
61+
@Query("codistancefrompoint") String centerCoords,
62+
@Query("ggslimit") int limit);
4763
}

app/src/main/java/fr/free/nrw/commons/mwapi/CategoryApi.java

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)