From 89373e6e752c7c2220ec15157c34b19ee8b60e2a Mon Sep 17 00:00:00 2001 From: Thompson3142 <115718208+Thompson3142@users.noreply.github.com> Date: Sun, 8 Sep 2024 19:53:39 +0200 Subject: [PATCH 1/4] Cleanup + bug fix with ALL search --- .../fragments/list/search/SearchFragment.java | 64 +++++++++++++------ 1 file changed, 46 insertions(+), 18 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 eef3455ae87..c85c97d53b4 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 @@ -1,6 +1,8 @@ package org.schabi.newpipe.fragments.list.search; import static androidx.recyclerview.widget.ItemTouchHelper.Callback.makeMovementFlags; +import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.ALL; +import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.EXACT; import static org.schabi.newpipe.extractor.utils.Utils.isBlank; import static org.schabi.newpipe.ktx.ViewUtils.animate; import static org.schabi.newpipe.util.ExtractorHelper.showMetaInfoInTextView; @@ -763,14 +765,14 @@ private void initSuggestionObserver() { if (showLocalSuggestions && shallShowRemoteSuggestionsNow) { return Observable.zip( - getLocalSuggestionsObservable(query, 3), - getRemoteSuggestionsObservable(query), - (local, remote) -> { - remote.removeIf(remoteItem -> local.stream().anyMatch( - localItem -> localItem.equals(remoteItem))); - local.addAll(remote); - return local; - }) + getLocalSuggestionsObservable(query, 3), + getRemoteSuggestionsObservable(query), + (local, remote) -> { + remote.removeIf(remoteItem -> local.stream().anyMatch( + localItem -> localItem.equals(remoteItem))); + local.addAll(remote); + return local; + }) .materialize(); } else if (showLocalSuggestions) { return getLocalSuggestionsObservable(query, 25) @@ -845,7 +847,24 @@ private void search(@NonNull final String theSearchString, // prepare search lastSearchedString = this.searchString; - this.searchString = theSearchString; + searchString = theSearchString; + + // Always remove EXACT search initially so it doesn't persist over multiple searches + final List tempContentFilter = new ArrayList<>(Arrays.asList(contentFilter)); + tempContentFilter.remove(EXACT); + contentFilter = tempContentFilter.toArray(new String[0]); + + // If quotes are around the search string EXACT search is enabled + // Overrides ALL and is otherwise appended to existing filters + if (searchString.charAt(0) == '\"' + && searchString.charAt(searchString.length() - 1) == '\"') { + if (contentFilter.length == 0 || contentFilter[0].equals(ALL)) { + contentFilter = new String[]{EXACT}; + } else { + contentFilter = new String[]{contentFilter[0], EXACT}; + } + } + infoListAdapter.clearStreamItemList(); hideSuggestionsPanel(); showMetaInfoInTextView(null, searchBinding.searchMetaInfoTextView, @@ -867,6 +886,15 @@ private void search(@NonNull final String theSearchString, startLoading(false); } + /** + * Adjusts the search string from EXACT searches for queries (removes the surrounding quotes). + * @return The adjusted search string + */ + private String getExactSearchAdjustedString() { + return Arrays.asList(contentFilter).contains(EXACT) + ? searchString.substring(1, searchString.length() - 1) : searchString; + } + @Override public void startLoading(final boolean forceLoad) { super.startLoading(forceLoad); @@ -875,14 +903,13 @@ public void startLoading(final boolean forceLoad) { searchDisposable.dispose(); } searchDisposable = ExtractorHelper.searchFor(serviceId, - searchString, - Arrays.asList(contentFilter), - sortFilter) + getExactSearchAdjustedString(), + Arrays.asList(contentFilter), + sortFilter) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((searchResult, throwable) -> isLoading.set(false)) .subscribe(this::handleResult, this::onItemError); - } @Override @@ -896,17 +923,18 @@ protected void loadMoreItems() { searchDisposable.dispose(); } searchDisposable = ExtractorHelper.getMoreSearchItems( - serviceId, - searchString, - asList(contentFilter), - sortFilter, - nextPage) + serviceId, + getExactSearchAdjustedString(), + asList(contentFilter), + sortFilter, + nextPage) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((nextItemsResult, throwable) -> isLoading.set(false)) .subscribe(this::handleNextItems, this::onItemError); } + @Override protected boolean hasMoreItems() { return Page.isValid(nextPage); From 57a9250b58733565dc6a91147693fe65b5d62de1 Mon Sep 17 00:00:00 2001 From: Thompson3142 <115718208+Thompson3142@users.noreply.github.com> Date: Sun, 8 Sep 2024 20:15:05 +0200 Subject: [PATCH 2/4] No code changes, just visual cleanup --- .../fragments/list/search/SearchFragment.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 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 c85c97d53b4..53221208f5a 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 @@ -765,14 +765,14 @@ private void initSuggestionObserver() { if (showLocalSuggestions && shallShowRemoteSuggestionsNow) { return Observable.zip( - getLocalSuggestionsObservable(query, 3), - getRemoteSuggestionsObservable(query), - (local, remote) -> { - remote.removeIf(remoteItem -> local.stream().anyMatch( - localItem -> localItem.equals(remoteItem))); - local.addAll(remote); - return local; - }) + getLocalSuggestionsObservable(query, 3), + getRemoteSuggestionsObservable(query), + (local, remote) -> { + remote.removeIf(remoteItem -> local.stream().anyMatch( + localItem -> localItem.equals(remoteItem))); + local.addAll(remote); + return local; + }) .materialize(); } else if (showLocalSuggestions) { return getLocalSuggestionsObservable(query, 25) @@ -903,9 +903,9 @@ public void startLoading(final boolean forceLoad) { searchDisposable.dispose(); } searchDisposable = ExtractorHelper.searchFor(serviceId, - getExactSearchAdjustedString(), - Arrays.asList(contentFilter), - sortFilter) + getExactSearchAdjustedString(), + Arrays.asList(contentFilter), + sortFilter) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((searchResult, throwable) -> isLoading.set(false)) @@ -934,7 +934,6 @@ protected void loadMoreItems() { .subscribe(this::handleNextItems, this::onItemError); } - @Override protected boolean hasMoreItems() { return Page.isValid(nextPage); From 39b147e29fa411bcbbc49ea6c44053ce5ba33477 Mon Sep 17 00:00:00 2001 From: Thompson3142 <115718208+Thompson3142@users.noreply.github.com> Date: Sun, 8 Sep 2024 20:16:53 +0200 Subject: [PATCH 3/4] No code changes, just visual cleanup --- .../schabi/newpipe/fragments/list/search/SearchFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 53221208f5a..022d83efe24 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 @@ -769,7 +769,7 @@ private void initSuggestionObserver() { getRemoteSuggestionsObservable(query), (local, remote) -> { remote.removeIf(remoteItem -> local.stream().anyMatch( - localItem -> localItem.equals(remoteItem))); + localItem -> localItem.equals(remoteItem))); local.addAll(remote); return local; }) From ca410b48f52e562ceb6fe7cd537ae2989bc3689d Mon Sep 17 00:00:00 2001 From: Thompson3142 <115718208+Thompson3142@users.noreply.github.com> Date: Sun, 8 Sep 2024 20:18:07 +0200 Subject: [PATCH 4/4] No code changes, just visual cleanup --- .../fragments/list/search/SearchFragment.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 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 022d83efe24..a316ec497e4 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 @@ -903,9 +903,9 @@ public void startLoading(final boolean forceLoad) { searchDisposable.dispose(); } searchDisposable = ExtractorHelper.searchFor(serviceId, - getExactSearchAdjustedString(), - Arrays.asList(contentFilter), - sortFilter) + getExactSearchAdjustedString(), + Arrays.asList(contentFilter), + sortFilter) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((searchResult, throwable) -> isLoading.set(false)) @@ -923,11 +923,11 @@ protected void loadMoreItems() { searchDisposable.dispose(); } searchDisposable = ExtractorHelper.getMoreSearchItems( - serviceId, - getExactSearchAdjustedString(), - asList(contentFilter), - sortFilter, - nextPage) + serviceId, + getExactSearchAdjustedString(), + asList(contentFilter), + sortFilter, + nextPage) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnEvent((nextItemsResult, throwable) -> isLoading.set(false))