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..64eaf3a3d 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; @@ -78,7 +79,7 @@ import static androidx.recyclerview.widget.ItemTouchHelper.Callback.makeMovement import static java.util.Arrays.asList; import static org.schabi.newpipe.util.AnimationUtils.animateView; -public class SearchFragment extends BaseListFragment +public class SearchFragment extends BaseListFragment> implements BackPressable { /*////////////////////////////////////////////////////////////////////////// // Search @@ -133,7 +134,6 @@ public class SearchFragment extends BaseListFragment menuItemToFilterName; private StreamingService service; private Page nextPage; - private String contentCountry; private boolean isSuggestionsEnabled = true; private Disposable searchDisposable; @@ -154,6 +154,7 @@ public class SearchFragment extends BaseListFragment 0 && !isLoading.get()) { hideSuggestionsPanel(); @@ -742,6 +734,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<>(); @@ -791,21 +790,23 @@ public class SearchFragment extends BaseListFragment - NavigationHelper.getIntentByLink(activity, streamingService, ss)) + .fromCallable(() -> NavigationHelper.getIntentByLink(activity, + streamingService, theSearchString)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(intent -> { @@ -820,29 +821,27 @@ public class SearchFragment extends BaseListFragment { }, error -> showSnackBarError(error, UserAction.SEARCHED, - NewPipe.getNameOfService(serviceId), ss, 0) - ); - suggestionPublisher.onNext(ss); + NewPipe.getNameOfService(serviceId), theSearchString, 0) + )); + suggestionPublisher.onNext(theSearchString); startLoading(false); } @Override public void startLoading(final boolean forceLoad) { super.startLoading(forceLoad); - if (disposables != null) { - disposables.clear(); - } + disposables.clear(); if (searchDisposable != null) { searchDisposable.dispose(); } @@ -881,8 +880,7 @@ public class SearchFragment extends BaseListFragment cf) { - this.filterItemCheckedId = item.getItemId(); + private void changeContentFilter(final MenuItem item, final List theContentFilter) { + filterItemCheckedId = item.getItemId(); item.setChecked(true); - this.contentFilter = new String[]{cf.get(0)}; + contentFilter = new String[]{theContentFilter.get(0)}; if (!TextUtils.isEmpty(searchString)) { - search(searchString, this.contentFilter, sortFilter); + search(searchString, contentFilter, sortFilter); } } - private void setQuery(final int sid, final String ss, final String[] cf, final String sf) { - this.serviceId = sid; - this.searchString = searchString; - this.contentFilter = cf; - this.sortFilter = sf; + private void setQuery(final int theServiceId, + final String theSearchString, + final String[] theContentFilter, + final String theSortFilter) { + serviceId = theServiceId; + searchString = theSearchString; + contentFilter = theContentFilter; + sortFilter = theSortFilter; } /*////////////////////////////////////////////////////////////////////////// @@ -924,7 +925,7 @@ public class SearchFragment extends BaseListFragment suggestionListAdapter.setItems(suggestions)); - if (errorPanelRoot.getVisibility() == View.VISIBLE) { + if (suggestionsPanelVisible && errorPanelRoot.getVisibility() == View.VISIBLE) { hideLoading(); } } @@ -1027,7 +1028,7 @@ public class SearchFragment extends BaseListFragment result) { showListFooter(false); infoListAdapter.addInfoItemList(result.getItems()); nextPage = result.getNextPage(); @@ -1066,8 +1067,7 @@ public class SearchFragment extends BaseListFragment