Implemented episode filter
This commit is contained in:
parent
d3d2debfb6
commit
18e4625e9a
|
@ -82,7 +82,7 @@ public class FeedlistAdapter extends ArrayAdapter<Feed> {
|
|||
.getTime(), System.currentTimeMillis(),
|
||||
DateFormat.SHORT, DateFormat.SHORT));
|
||||
}
|
||||
holder.numberOfEpisodes.setText(feed.getItems().size()
|
||||
holder.numberOfEpisodes.setText(feed.getNumOfItems()
|
||||
+ convertView.getResources()
|
||||
.getString(R.string.episodes_suffix));
|
||||
int newItems = feed.getNumOfNewItems();
|
||||
|
|
|
@ -3,6 +3,10 @@ package de.danoeh.antennapod.feed;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import de.danoeh.antennapod.PodcastApp;
|
||||
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
/**
|
||||
* Data Object for a whole feed
|
||||
*
|
||||
|
@ -12,7 +16,7 @@ import java.util.Date;
|
|||
public class Feed extends FeedFile {
|
||||
public static final String TYPE_RSS2 = "rss";
|
||||
public static final String TYPE_ATOM1 = "atom";
|
||||
|
||||
|
||||
private String title;
|
||||
/** Link to the website. */
|
||||
private String link;
|
||||
|
@ -39,14 +43,42 @@ public class Feed extends FeedFile {
|
|||
this(lastUpdate);
|
||||
this.download_url = url;
|
||||
}
|
||||
|
||||
/** Returns the number of FeedItems where 'read' is false. */
|
||||
|
||||
/**
|
||||
* Returns the number of FeedItems where 'read' is false. If the 'display
|
||||
* only episodes' - preference is set to true, this method will only count
|
||||
* items with episodes.
|
||||
* */
|
||||
public int getNumOfNewItems() {
|
||||
int count = 0;
|
||||
boolean displayOnlyEpisodes = PreferenceManager
|
||||
.getDefaultSharedPreferences(PodcastApp.getInstance())
|
||||
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
|
||||
|
||||
for (FeedItem item : items) {
|
||||
if (!item.isRead()) {
|
||||
if (!displayOnlyEpisodes || item.getMedia() != null) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of FeedItems. If the 'display only episodes' -
|
||||
* preference is set to true, this method will only count items with
|
||||
* episodes.
|
||||
* */
|
||||
public int getNumOfItems() {
|
||||
int count = 0;
|
||||
boolean displayOnlyEpisodes = PreferenceManager
|
||||
.getDefaultSharedPreferences(PodcastApp.getInstance())
|
||||
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
|
||||
for (FeedItem item : items) {
|
||||
if (!displayOnlyEpisodes || item.getMedia() != null) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
@ -106,7 +138,7 @@ public class Feed extends FeedFile {
|
|||
public void setLastUpdate(Date lastUpdate) {
|
||||
this.lastUpdate = lastUpdate;
|
||||
}
|
||||
|
||||
|
||||
public String getPaymentLink() {
|
||||
return paymentLink;
|
||||
}
|
||||
|
@ -138,7 +170,5 @@ public class Feed extends FeedFile {
|
|||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -28,8 +29,10 @@ import de.danoeh.antennapod.feed.FeedItem;
|
|||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
import de.danoeh.antennapod.service.DownloadService;
|
||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.util.EpisodeFilter;
|
||||
import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler;
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.PodcastApp;
|
||||
import de.danoeh.antennapod.R;
|
||||
|
||||
/** Displays a list of FeedItems. */
|
||||
|
@ -99,6 +102,14 @@ public class ItemlistFragment extends SherlockListFragment implements
|
|||
feed = FeedManager.getInstance().getFeed(feedId);
|
||||
items = feed.getItems();
|
||||
}
|
||||
|
||||
boolean displayOnlyEpisodes = PreferenceManager
|
||||
.getDefaultSharedPreferences(PodcastApp.getInstance())
|
||||
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
|
||||
if (displayOnlyEpisodes) {
|
||||
items = EpisodeFilter.getEpisodeList(items);
|
||||
}
|
||||
|
||||
fila = new FeedItemlistAdapter(getActivity(), 0, items,
|
||||
onButActionClicked, showFeedtitle);
|
||||
setListAdapter(fila);
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package de.danoeh.antennapod.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.feed.FeedItem;
|
||||
|
||||
public class EpisodeFilter {
|
||||
private EpisodeFilter() {
|
||||
|
||||
}
|
||||
|
||||
/** Return a copy of the itemlist without items which have no media. */
|
||||
public static ArrayList<FeedItem> getEpisodeList(List<FeedItem> items) {
|
||||
ArrayList<FeedItem> episodes = new ArrayList<FeedItem>(items);
|
||||
for (FeedItem item : items) {
|
||||
if (item.getMedia() == null) {
|
||||
episodes.remove(item);
|
||||
}
|
||||
}
|
||||
return episodes;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue