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) {
|
} else if (component.getClass() == FeedItem.class) {
|
||||||
final FeedItem item = (FeedItem) component;
|
final FeedItem item = (FeedItem) component;
|
||||||
holder.title.setText(item.getTitle());
|
holder.title.setText(item.getTitle());
|
||||||
|
holder.subtitle.setVisibility(View.VISIBLE);
|
||||||
holder.subtitle.setText(result.getLocation().getDescription());
|
holder.subtitle.setText(result.getLocation().getDescription());
|
||||||
|
|
||||||
convertView.setAlpha(item.isPlayed() ? 0.5f : 1.0f);
|
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
|
* A runnable which should be used for database queries. The onCompletion
|
||||||
* method is executed on the database executor to handle Cursors correctly.
|
* 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 android.content.Context;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.feed.Chapter;
|
import de.danoeh.antennapod.core.feed.Chapter;
|
||||||
import java.util.ArrayList;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
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.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.feed.SearchResult;
|
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.
|
* 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) {
|
public static List<SearchResult> performSearch(final Context context, final String query, final long selectedFeed) {
|
||||||
final List<SearchResult> result = new ArrayList<>();
|
final List<SearchResult> result = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
FutureTask<List<FeedItem>> searchTask = DBTasks.searchFeedItems(context, selectedFeed, query);
|
FutureTask<List<FeedItem>> itemSearchTask = DBTasks.searchFeedItems(context, selectedFeed, query);
|
||||||
searchTask.run();
|
FutureTask<List<Feed>> feedSearchTask = DBTasks.searchFeeds(context, query);
|
||||||
final List<FeedItem> items = searchTask.get();
|
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) {
|
for (FeedItem item : items) {
|
||||||
SearchLocation location;
|
SearchLocation location;
|
||||||
if (safeContains(item.getTitle(), query)) {
|
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.
|
* 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 SEL_FI_SMALL_STR;
|
||||||
|
private static final String FEED_SEL_STD_STR;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String selFiSmall = Arrays.toString(FEEDITEM_SEL_FI_SMALL);
|
String selFiSmall = Arrays.toString(FEEDITEM_SEL_FI_SMALL);
|
||||||
SEL_FI_SMALL_STR = selFiSmall.substring(1, selFiSmall.length() - 1);
|
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_FEED_ITEMS + "." + KEY_TITLE + " LIKE '%" + preparedQuery + "%' OR "
|
||||||
+ TABLE_NAME_SIMPLECHAPTERS + "." + KEY_TITLE + " LIKE '%" + preparedQuery + "%'"
|
+ TABLE_NAME_SIMPLECHAPTERS + "." + KEY_TITLE + " LIKE '%" + preparedQuery + "%'"
|
||||||
+ ") ORDER BY " + KEY_PUBDATE + " DESC "
|
+ ") 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);
|
return db.rawQuery(query, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue