From 3793516d57ae31d9bf6095c60b6735b2e682c313 Mon Sep 17 00:00:00 2001 From: Mikel Date: Mon, 7 Aug 2017 16:37:12 +0100 Subject: [PATCH] Fix empty-filter search. Fix repeated suggestions issue. Show "no results found" when appropriate --- .../category/CategorizationFragment.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java b/app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java index 63532afb8..b281a6c1b 100644 --- a/app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java @@ -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 defaultCategories() { + return gpsCategories() + .concatWith(titleCategories()) + .concatWith(recentCategories()); + } + private Observable gpsCategories() { return Observable.fromIterable( MwVolleyApi.GpsCatExists.getGpsCatExists()