Fix empty-filter search. Fix repeated suggestions issue. Show "no results found" when appropriate

This commit is contained in:
Mikel 2017-08-07 16:37:12 +01:00
parent ef1fc0c9d9
commit 3793516d57

View file

@ -194,15 +194,11 @@ public class CategorizationFragment extends Fragment {
.concatWith(
searchAll(filter)
.mergeWith(searchCategories(filter))
.filter(categoryItem -> !selectedCategories.contains(categoryItem))
.switchIfEmpty(
gpsCategories()
.concatWith(titleCategories())
.concatWith(recentCategories())
.filter(categoryItem -> !selectedCategories.contains(categoryItem))
)
.concatWith( TextUtils.isEmpty(filter)
? defaultCategories() : Observable.empty())
)
.filter(categoryItem -> !containsYear(categoryItem.getName()))
.distinct()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
s -> categoriesAdapter.add(s),
@ -211,11 +207,13 @@ public class CategorizationFragment extends Fragment {
categoriesAdapter.notifyDataSetChanged();
categoriesSearchInProgress.setVisibility(View.GONE);
if (categoriesAdapter.getItemCount() == 0) {
if (categoriesAdapter.getItemCount() == selectedCategories.size()) {
// There are no suggestions
if (TextUtils.isEmpty(filter)) {
// If we found no recent cats, show the skip message!
// Allow to send image with no categories
categoriesSkip.setVisibility(View.VISIBLE);
} else {
// Inform the user that the searched term matches no category
categoriesNotFoundView.setText(getString(R.string.categories_not_found, filter));
categoriesNotFoundView.setVisibility(View.VISIBLE);
}
@ -232,6 +230,12 @@ public class CategorizationFragment extends Fragment {
return output;
}
private Observable<CategoryItem> defaultCategories() {
return gpsCategories()
.concatWith(titleCategories())
.concatWith(recentCategories());
}
private Observable<CategoryItem> gpsCategories() {
return Observable.fromIterable(
MwVolleyApi.GpsCatExists.getGpsCatExists()