mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2024-12-25 08:21:59 +01:00
Search for feeds separately
This commit is contained in:
parent
50dd85276c
commit
8d23571bba
@ -93,6 +93,7 @@ public class SearchlistAdapter extends BaseAdapter {
|
||||
} else if (component.getClass() == FeedItem.class) {
|
||||
final FeedItem item = (FeedItem) component;
|
||||
holder.title.setText(item.getTitle());
|
||||
holder.subtitle.setVisibility(View.VISIBLE);
|
||||
holder.subtitle.setText(result.getLocation().getDescription());
|
||||
|
||||
convertView.setAlpha(item.isPlayed() ? 0.5f : 1.0f);
|
||||
|
@ -553,6 +553,23 @@ public final class DBTasks {
|
||||
});
|
||||
}
|
||||
|
||||
public static FutureTask<List<Feed>> searchFeeds(final Context context, final String query) {
|
||||
return new FutureTask<>(new QueryTask<List<Feed>>(context) {
|
||||
@Override
|
||||
public void execute(PodDBAdapter adapter) {
|
||||
Cursor cursor = adapter.searchFeeds(query);
|
||||
List<Feed> items = new ArrayList<>();
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
items.add(Feed.fromCursor(cursor));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
setResult(items);
|
||||
cursor.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A runnable which should be used for database queries. The onCompletion
|
||||
* method is executed on the database executor to handle Cursors correctly.
|
||||
|
@ -2,20 +2,15 @@ package de.danoeh.antennapod.core.storage;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import de.danoeh.antennapod.core.feed.Chapter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import de.danoeh.antennapod.core.R;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.SearchResult;
|
||||
import de.danoeh.antennapod.core.util.comparator.InReverseChronologicalOrder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
/**
|
||||
* Performs search on Feeds and FeedItems.
|
||||
@ -40,9 +35,17 @@ public class FeedSearcher {
|
||||
public static List<SearchResult> performSearch(final Context context, final String query, final long selectedFeed) {
|
||||
final List<SearchResult> result = new ArrayList<>();
|
||||
try {
|
||||
FutureTask<List<FeedItem>> searchTask = DBTasks.searchFeedItems(context, selectedFeed, query);
|
||||
searchTask.run();
|
||||
final List<FeedItem> items = searchTask.get();
|
||||
FutureTask<List<FeedItem>> itemSearchTask = DBTasks.searchFeedItems(context, selectedFeed, query);
|
||||
FutureTask<List<Feed>> feedSearchTask = DBTasks.searchFeeds(context, query);
|
||||
itemSearchTask.run();
|
||||
feedSearchTask.run();
|
||||
|
||||
final List<Feed> feeds = feedSearchTask.get();
|
||||
for (Feed item : feeds) {
|
||||
result.add(new SearchResult(item, null));
|
||||
}
|
||||
|
||||
final List<FeedItem> items = itemSearchTask.get();
|
||||
for (FeedItem item : items) {
|
||||
SearchLocation location;
|
||||
if (safeContains(item.getTitle(), query)) {
|
||||
|
@ -284,10 +284,13 @@ public class PodDBAdapter {
|
||||
* Contains FEEDITEM_SEL_FI_SMALL as comma-separated list. Useful for raw queries.
|
||||
*/
|
||||
private static final String SEL_FI_SMALL_STR;
|
||||
private static final String FEED_SEL_STD_STR;
|
||||
|
||||
static {
|
||||
String selFiSmall = Arrays.toString(FEEDITEM_SEL_FI_SMALL);
|
||||
SEL_FI_SMALL_STR = selFiSmall.substring(1, selFiSmall.length() - 1);
|
||||
String selFeedSmall = Arrays.toString(FEED_SEL_STD);
|
||||
FEED_SEL_STD_STR = selFeedSmall.substring(1, selFeedSmall.length() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1283,7 +1286,24 @@ public class PodDBAdapter {
|
||||
+ TABLE_NAME_FEED_ITEMS + "." + KEY_TITLE + " LIKE '%" + preparedQuery + "%' OR "
|
||||
+ TABLE_NAME_SIMPLECHAPTERS + "." + KEY_TITLE + " LIKE '%" + preparedQuery + "%'"
|
||||
+ ") ORDER BY " + KEY_PUBDATE + " DESC "
|
||||
+ "LIMIT 500";
|
||||
+ "LIMIT 300";
|
||||
return db.rawQuery(query, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the given query in various values of all feeds.
|
||||
*
|
||||
* @return A cursor with all search results in SEL_FI_EXTRA selection.
|
||||
*/
|
||||
public Cursor searchFeeds(String searchQuery) {
|
||||
String preparedQuery = prepareSearchQuery(searchQuery);
|
||||
String query = "SELECT " + FEED_SEL_STD_STR + " FROM " + TABLE_NAME_FEEDS + " WHERE "
|
||||
+ KEY_TITLE + " LIKE '%" + preparedQuery + "%' OR "
|
||||
+ KEY_CUSTOM_TITLE + " LIKE '%" + preparedQuery + "%' OR "
|
||||
+ KEY_AUTHOR + " LIKE '%" + preparedQuery + "%' OR "
|
||||
+ KEY_DESCRIPTION + " LIKE '%" + preparedQuery + "%' "
|
||||
+ "ORDER BY " + KEY_TITLE + " ASC "
|
||||
+ "LIMIT 300";
|
||||
return db.rawQuery(query, null);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user