use of de.danoeh.antennapod.core.feed.SearchResult in project AntennaPod by AntennaPod.
the class FeedSearcher method performSearch.
/**
* Search through a feed, or all feeds, for episodes that match the query in either the title,
* chapter, or show notes. The search is first performed on titles, then chapters, and finally
* show notes. The list of resulting episodes also describes where the first match occurred
* (title, chapters, or show notes).
*
* @param context
* @param query search query
* @param selectedFeed feed to search, 0 to search through all feeds
* @return list of episodes containing the query
*/
public static List<SearchResult> performSearch(final Context context, final String query, final long selectedFeed) {
final int[] values = { 2, 1, 0, 0 };
final String[] subtitles = { context.getString(R.string.found_in_title_label), context.getString(R.string.found_in_chapters_label), context.getString(R.string.found_in_shownotes_label), context.getString(R.string.found_in_shownotes_label) };
List<SearchResult> result = new ArrayList<>();
List<FutureTask<List<FeedItem>>> tasks = new ArrayList<>();
tasks.add(DBTasks.searchFeedItemTitle(context, selectedFeed, query));
tasks.add(DBTasks.searchFeedItemChapters(context, selectedFeed, query));
tasks.add(DBTasks.searchFeedItemDescription(context, selectedFeed, query));
tasks.add(DBTasks.searchFeedItemContentEncoded(context, selectedFeed, query));
for (FutureTask<List<FeedItem>> task : tasks) {
task.run();
}
try {
for (int i = 0; i < tasks.size(); i++) {
FutureTask<List<FeedItem>> task = tasks.get(i);
List<FeedItem> items = task.get();
for (FeedItem item : items) {
if (result.isEmpty() || !isDuplicate(result, item)) {
result.add(new SearchResult(item, values[i], subtitles[i]));
}
}
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
Collections.sort(result, new SearchResultValueComparator());
return result;
}
use of de.danoeh.antennapod.core.feed.SearchResult in project AntennaPod by AntennaPod.
the class SearchlistAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Holder holder;
SearchResult result = getItem(position);
FeedComponent component = result.getComponent();
// Inflate Layout
if (convertView == null) {
holder = new Holder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.searchlist_item, parent, false);
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
if (Build.VERSION.SDK_INT >= 23) {
holder.title.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL);
}
holder.cover = (ImageView) convertView.findViewById(R.id.imgvFeedimage);
holder.subtitle = (TextView) convertView.findViewById(R.id.txtvSubtitle);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
if (component.getClass() == Feed.class) {
final Feed feed = (Feed) component;
holder.title.setText(feed.getTitle());
holder.subtitle.setVisibility(View.GONE);
Glide.with(context).load(feed.getImageLocation()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(holder.cover);
} else if (component.getClass() == FeedItem.class) {
final FeedItem item = (FeedItem) component;
holder.title.setText(item.getTitle());
if (result.getSubtitle() != null) {
holder.subtitle.setVisibility(View.VISIBLE);
holder.subtitle.setText(result.getSubtitle());
}
ViewHelper.setAlpha(convertView, item.isPlayed() ? 0.5f : 1.0f);
Glide.with(context).load(item.getFeed().getImageLocation()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(holder.cover);
}
return convertView;
}
use of de.danoeh.antennapod.core.feed.SearchResult in project AntennaPod by AntennaPod.
the class SearchFragment method onListItemClick.
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
SearchResult result = (SearchResult) l.getAdapter().getItem(position);
FeedComponent comp = result.getComponent();
if (comp.getClass() == Feed.class) {
((MainActivity) getActivity()).loadFeedFragmentById(comp.getId(), null);
} else {
if (comp.getClass() == FeedItem.class) {
FeedItem item = (FeedItem) comp;
((MainActivity) getActivity()).loadChildFragment(ItemFragment.newInstance(item.getId()));
}
}
}
Aggregations