From f8de72f59f42da7f57a13d5552e25e3675060a24 Mon Sep 17 00:00:00 2001 From: Stypox Date: Fri, 31 Jul 2020 11:28:22 +0200 Subject: [PATCH] Improve search suggestion experience when remote ones can't be fetched Do not show anything in case of network error (it can simply be ignored). Show a snackbar otherwise, which still allows writing things into the search box. --- .../fragments/list/search/SearchFragment.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index 6817e4595..cae4975a4 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -52,6 +52,7 @@ import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.DeviceUtils; import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.Constants; +import org.schabi.newpipe.util.ExceptionUtils; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ServiceHelper; @@ -154,6 +155,7 @@ public class SearchFragment extends BaseListFragment 0 && !isLoading.get()) { hideSuggestionsPanel(); @@ -742,6 +746,13 @@ public class SearchFragment extends BaseListFragment> network = ExtractorHelper .suggestionsFor(serviceId, query) + .onErrorReturn(throwable -> { + if (!ExceptionUtils.isNetworkRelated(throwable)) { + showSnackBarError(throwable, UserAction.GET_SUGGESTIONS, + NewPipe.getNameOfService(serviceId), searchString, 0); + } + return new ArrayList<>(); + }) .toObservable() .map(strings -> { final List result = new ArrayList<>(); @@ -924,7 +935,7 @@ public class SearchFragment extends BaseListFragment suggestionListAdapter.setItems(suggestions)); - if (errorPanelRoot.getVisibility() == View.VISIBLE) { + if (suggestionsPanelVisible && errorPanelRoot.getVisibility() == View.VISIBLE) { hideLoading(); } }