Merge pull request #2067 from orelogo/develop
Improve search results: "no results" view, no duplicates, transparent played episodes
This commit is contained in:
commit
44b37fc043
|
@ -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)
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<SearchResult> 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<SearchResult> result = new ArrayList<>();
|
||||
|
||||
List<FutureTask<List<FeedItem>>> 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<List<FeedItem>> task : tasks) {
|
||||
task.run();
|
||||
}
|
||||
|
@ -46,7 +55,9 @@ public class FeedSearcher {
|
|||
FutureTask<List<FeedItem>> task = tasks.get(i);
|
||||
List<FeedItem> 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<SearchResult> result, FeedItem item) {
|
||||
for (SearchResult resultItem : result) {
|
||||
if (resultItem.getComponent().getId() == item.getId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -418,12 +418,13 @@
|
|||
<string name="auto_flattr_ater_end">Flattr episode when playback ends</string>
|
||||
|
||||
<!-- Search -->
|
||||
<string name="search_hint">Search for Feeds or Episodes</string>
|
||||
<string name="found_in_shownotes_label">Found in shownotes</string>
|
||||
<string name="search_hint">Search for episodes</string>
|
||||
<string name="found_in_shownotes_label">Found in show notes</string>
|
||||
<string name="found_in_chapters_label">Found in chapters</string>
|
||||
<string name="search_status_no_results">No results were found</string>
|
||||
<string name="search_label">Search</string>
|
||||
<string name="found_in_title_label">Found in title</string>
|
||||
<string name="no_results_for_query">No results were found for \"%1$s\"</string>
|
||||
|
||||
<!-- OPML import and export -->
|
||||
<string name="opml_import_txtv_button_lable">OPML files allow you to move your podcasts from one podcatcher to another.</string>
|
||||
|
|
Loading…
Reference in New Issue