21
21
@ Singleton
22
22
public class CategoryClient {
23
23
24
- private final CategoryInterface CategoryInterface ;
24
+ private final CategoryInterface categoryInterface ;
25
25
26
26
@ Inject
27
27
public CategoryClient (CategoryInterface CategoryInterface ) {
28
- this .CategoryInterface = CategoryInterface ;
28
+ this .categoryInterface = CategoryInterface ;
29
29
}
30
30
31
31
/**
@@ -37,7 +37,7 @@ public CategoryClient(CategoryInterface CategoryInterface) {
37
37
* @return
38
38
*/
39
39
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 ));
41
41
42
42
}
43
43
@@ -62,7 +62,7 @@ public Observable<String> searchCategories(String filter, int itemLimit) {
62
62
* @return
63
63
*/
64
64
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 ));
66
66
}
67
67
68
68
/**
@@ -85,7 +85,7 @@ public Observable<String> searchCategoriesForPrefix(String prefix, int itemLimit
85
85
* @return Observable emitting the categories returned. If our search yielded "Category:Test", "Test" is emitted.
86
86
*/
87
87
public Observable <String > getSubCategoryList (String categoryName ) {
88
- return responseToCategoryName (CategoryInterface .getSubCategoryList (categoryName ));
88
+ return responseToCategoryName (categoryInterface .getSubCategoryList (categoryName ));
89
89
}
90
90
91
91
/**
@@ -97,7 +97,32 @@ public Observable<String> getSubCategoryList(String categoryName) {
97
97
*/
98
98
@ NonNull
99
99
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:" , "" ));
101
126
}
102
127
103
128
/**
0 commit comments