diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java index ac10d53f6..8e1aa24e0 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SearchlistAdapter.java @@ -11,6 +11,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; +import com.nineoldandroids.view.ViewHelper; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.Feed; @@ -96,6 +97,8 @@ public class SearchlistAdapter extends BaseAdapter { 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) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java index db57279de..f64b4c20a 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java @@ -182,6 +182,9 @@ public class SearchFragment extends ListFragment { } searchAdapter.notifyDataSetChanged(); setListShown(true); + + String query = getArguments().getString(ARG_QUERY); + setEmptyText(getString(R.string.no_results_for_query, query)); } private final SearchlistAdapter.ItemAccess itemAccess = new SearchlistAdapter.ItemAccess() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java b/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java index b88d774a2..9d136273c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java @@ -21,23 +21,32 @@ public class FeedSearcher { /** - * Performs a search in all feeds or one specific feed. + * 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 performSearch(final Context context, final String query, final long selectedFeed) { - final int values[] = {0, 0, 1, 2}; - final String[] subtitles = {context.getString(R.string.found_in_shownotes_label), - context.getString(R.string.found_in_shownotes_label), + 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_title_label)}; + context.getString(R.string.found_in_shownotes_label), + context.getString(R.string.found_in_shownotes_label)}; List result = new ArrayList<>(); List>> tasks = new ArrayList<>(); - tasks.add(DBTasks.searchFeedItemContentEncoded(context, selectedFeed, query)); - tasks.add(DBTasks.searchFeedItemDescription(context, selectedFeed, query)); - tasks.add(DBTasks.searchFeedItemChapters(context, selectedFeed, query)); 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> task : tasks) { task.run(); } @@ -46,7 +55,9 @@ public class FeedSearcher { FutureTask> task = tasks.get(i); List items = task.get(); for (FeedItem item : items) { - result.add(new SearchResult(item, values[i], subtitles[i])); + if (result.isEmpty() || !isDuplicate(result, item)) { + result.add(new SearchResult(item, values[i], subtitles[i])); + } } } @@ -56,4 +67,20 @@ public class FeedSearcher { Collections.sort(result, new SearchResultValueComparator()); return result; } + + /** + * Determines if the feed item is already in the search result list. + * + * @param result list of search results + * @param item feed item to validate + * @return true if the feed item is already in the results + */ + private static boolean isDuplicate(List result, FeedItem item) { + for (SearchResult resultItem : result) { + if (resultItem.getComponent().getId() == item.getId()) { + return true; + } + } + return false; + } } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index d51062aa3..e243776f5 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -418,12 +418,13 @@ Flattr episode when playback ends - Search for Feeds or Episodes - Found in shownotes + Search for episodes + Found in show notes Found in chapters No results were found Search Found in title + No results were found for \"%1$s\" OPML files allow you to move your podcasts from one podcatcher to another.