Show feed search results as soon as they are available (#7100)
without waiting for episode search results
This commit is contained in:
parent
e9b3cc34fe
commit
2043e71299
|
@ -6,7 +6,6 @@ import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -75,7 +74,8 @@ public class SearchFragment extends Fragment implements EpisodeItemListAdapter.O
|
||||||
|
|
||||||
private EpisodeItemListAdapter adapter;
|
private EpisodeItemListAdapter adapter;
|
||||||
private HorizontalFeedListAdapter adapterFeeds;
|
private HorizontalFeedListAdapter adapterFeeds;
|
||||||
private Disposable disposable;
|
private Disposable disposableFeeds;
|
||||||
|
private Disposable disposableEpisodes;
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
private EmptyViewHandler emptyViewHandler;
|
private EmptyViewHandler emptyViewHandler;
|
||||||
private EpisodeItemListRecyclerView recyclerView;
|
private EpisodeItemListRecyclerView recyclerView;
|
||||||
|
@ -127,8 +127,11 @@ public class SearchFragment extends Fragment implements EpisodeItemListAdapter.O
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
if (disposable != null) {
|
if (disposableFeeds != null) {
|
||||||
disposable.dispose();
|
disposableFeeds.dispose();
|
||||||
|
}
|
||||||
|
if (disposableEpisodes != null) {
|
||||||
|
disposableEpisodes.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,42 +376,43 @@ public class SearchFragment extends Fragment implements EpisodeItemListAdapter.O
|
||||||
}
|
}
|
||||||
|
|
||||||
private void search() {
|
private void search() {
|
||||||
if (disposable != null) {
|
if (disposableFeeds != null) {
|
||||||
disposable.dispose();
|
disposableFeeds.dispose();
|
||||||
|
}
|
||||||
|
if (disposableEpisodes != null) {
|
||||||
|
disposableEpisodes.dispose();
|
||||||
}
|
}
|
||||||
adapterFeeds.setEndButton(R.string.search_online, this::searchOnline);
|
adapterFeeds.setEndButton(R.string.search_online, this::searchOnline);
|
||||||
chip.setVisibility((getArguments().getLong(ARG_FEED, 0) == 0) ? View.GONE : View.VISIBLE);
|
long feed = getArguments().getLong(ARG_FEED, 0);
|
||||||
disposable = Observable.fromCallable(this::performSearch)
|
chip.setVisibility((feed == 0) ? View.GONE : View.VISIBLE);
|
||||||
|
|
||||||
|
String query = searchView.getQuery().toString();
|
||||||
|
if (query.isEmpty()) {
|
||||||
|
emptyViewHandler.setMessage(R.string.type_to_search);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (feed != 0) {
|
||||||
|
// Search within a feed
|
||||||
|
adapterFeeds.updateData(Collections.emptyList());
|
||||||
|
} else {
|
||||||
|
disposableFeeds = Observable.fromCallable(() -> DBReader.searchFeeds(query))
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(results -> {
|
.subscribe(results -> {
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
this.results = results.first;
|
adapterFeeds.updateData(results);
|
||||||
adapter.updateItems(results.first);
|
emptyViewHandler.setMessage(getString(R.string.no_results_for_query, query));
|
||||||
if (getArguments().getLong(ARG_FEED, 0) == 0) {
|
|
||||||
adapterFeeds.updateData(results.second);
|
|
||||||
} else {
|
|
||||||
adapterFeeds.updateData(Collections.emptyList());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (searchView.getQuery().toString().isEmpty()) {
|
|
||||||
emptyViewHandler.setMessage(R.string.type_to_search);
|
|
||||||
} else {
|
|
||||||
emptyViewHandler.setMessage(getString(R.string.no_results_for_query, searchView.getQuery()));
|
|
||||||
}
|
|
||||||
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
||||||
}
|
}
|
||||||
|
disposableEpisodes = Observable.fromCallable(() -> DBReader.searchFeedItems(feed, query))
|
||||||
@NonNull
|
.subscribeOn(Schedulers.io())
|
||||||
private Pair<List<FeedItem>, List<Feed>> performSearch() {
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
String query = searchView.getQuery().toString();
|
.subscribe(results -> {
|
||||||
if (query.isEmpty()) {
|
progressBar.setVisibility(View.GONE);
|
||||||
return new Pair<>(Collections.emptyList(), Collections.emptyList());
|
this.results = results;
|
||||||
}
|
adapter.updateItems(results);
|
||||||
long feed = getArguments().getLong(ARG_FEED);
|
emptyViewHandler.setMessage(getString(R.string.no_results_for_query, searchView.getQuery()));
|
||||||
List<FeedItem> items = DBReader.searchFeedItems(feed, query);
|
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
||||||
List<Feed> feeds = DBReader.searchFeeds(query);
|
|
||||||
return new Pair<>(items, feeds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showInputMethod(View view) {
|
private void showInputMethod(View view) {
|
||||||
|
|
Loading…
Reference in New Issue