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