Itemlists were not updating their content properly if "Display only

episodes'-preference was enabled
This commit is contained in:
daniel oeh 2012-08-19 16:27:37 +02:00
parent c772471268
commit 9513099a10
5 changed files with 136 additions and 85 deletions

View File

@ -37,6 +37,8 @@ public class PodcastApp extends Application implements
private static float LOGICAL_DENSITY; private static float LOGICAL_DENSITY;
private static PodcastApp singleton; private static PodcastApp singleton;
private boolean displayOnlyEpisodes;
public static PodcastApp getInstance() { public static PodcastApp getInstance() {
return singleton; return singleton;
@ -49,6 +51,7 @@ public class PodcastApp extends Application implements
LOGICAL_DENSITY = getResources().getDisplayMetrics().density; LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
SharedPreferences prefs = PreferenceManager SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this); .getDefaultSharedPreferences(this);
displayOnlyEpisodes = prefs.getBoolean(PREF_DISPLAY_ONLY_EPISODES, false);
createImportDirectory(); createImportDirectory();
createNoMediaFile(); createNoMediaFile();
prefs.registerOnSharedPreferenceChangeListener(this); prefs.registerOnSharedPreferenceChangeListener(this);
@ -124,12 +127,19 @@ public class PodcastApp extends Application implements
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Automatic update was deactivated"); Log.d(TAG, "Automatic update was deactivated");
} }
} else if (key.equals(PREF_DISPLAY_ONLY_EPISODES)) {
if (AppConfig.DEBUG) Log.d(TAG, "PREF_DISPLAY_ONLY_EPISODES changed");
displayOnlyEpisodes = sharedPreferences.getBoolean(PREF_DISPLAY_ONLY_EPISODES, false);
} }
} }
public static float getLogicalDensity() { public static float getLogicalDensity() {
return LOGICAL_DENSITY; return LOGICAL_DENSITY;
} }
public boolean displayOnlyEpisodes() {
return displayOnlyEpisodes;
}
public boolean isLargeScreen() { public boolean isLargeScreen() {
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE; return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;

View File

@ -7,7 +7,10 @@ import de.danoeh.antennapod.feed.FeedItem;
import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.storage.DownloadRequester; import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.Converter; import de.danoeh.antennapod.util.Converter;
import de.danoeh.antennapod.util.EpisodeFilter;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import android.widget.Adapter;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
@ -27,6 +30,7 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
private OnClickListener onButActionClicked; private OnClickListener onButActionClicked;
private boolean showFeedtitle; private boolean showFeedtitle;
private int selectedItemIndex; private int selectedItemIndex;
private List<FeedItem> objects;
public static final int SELECTION_NONE = -1; public static final int SELECTION_NONE = -1;
@ -34,6 +38,7 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
List<FeedItem> objects, OnClickListener onButActionClicked, List<FeedItem> objects, OnClickListener onButActionClicked,
boolean showFeedtitle) { boolean showFeedtitle) {
super(context, textViewResourceId, objects); super(context, textViewResourceId, objects);
this.objects = objects;
this.onButActionClicked = onButActionClicked; this.onButActionClicked = onButActionClicked;
this.showFeedtitle = showFeedtitle; this.showFeedtitle = showFeedtitle;
this.selectedItemIndex = SELECTION_NONE; this.selectedItemIndex = SELECTION_NONE;
@ -75,74 +80,79 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
} else { } else {
holder = (Holder) convertView.getTag(); holder = (Holder) convertView.getTag();
} }
if (!(getItemViewType(position) == Adapter.IGNORE_ITEM_VIEW_TYPE)) {
convertView.setVisibility(View.VISIBLE);
if (position == selectedItemIndex) {
convertView.setBackgroundColor(convertView.getResources()
.getColor(R.color.selection_background));
} else {
convertView.setBackgroundResource(0);
}
if (position == selectedItemIndex) { holder.title.setText(item.getTitle());
convertView.setBackgroundColor(convertView.getResources().getColor( if (showFeedtitle) {
R.color.selection_background)); holder.feedtitle.setVisibility(View.VISIBLE);
holder.feedtitle.setText(item.getFeed().getTitle());
}
if (!item.isRead()) {
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
} else {
holder.title.setTypeface(Typeface.DEFAULT);
}
holder.published.setText(convertView.getResources().getString(
R.string.published_prefix)
+ DateUtils.formatSameDayTime(item.getPubDate().getTime(),
System.currentTimeMillis(), DateFormat.SHORT,
DateFormat.SHORT));
if (item.getMedia() == null) {
holder.encInfo.setVisibility(View.GONE);
} else {
holder.encInfo.setVisibility(View.VISIBLE);
if (FeedManager.getInstance().isInQueue(item)) {
holder.inPlaylist.setVisibility(View.VISIBLE);
} else {
holder.inPlaylist.setVisibility(View.GONE);
}
if (item.getMedia().isDownloaded()) {
holder.lenSize.setText(convertView.getResources()
.getString(R.string.length_prefix)
+ Converter.getDurationStringLong(item.getMedia()
.getDuration()));
holder.downloaded.setVisibility(View.VISIBLE);
} else {
holder.lenSize
.setText(convertView.getResources().getString(
R.string.size_prefix)
+ Converter.byteToString(item.getMedia()
.getSize()));
holder.downloaded.setVisibility(View.GONE);
}
if (DownloadRequester.getInstance().isDownloadingFile(
item.getMedia())) {
holder.downloading.setVisibility(View.VISIBLE);
} else {
holder.downloading.setVisibility(View.GONE);
}
String type = item.getMedia().getMime_type();
if (type.startsWith("audio")) {
holder.type.setImageResource(R.drawable.type_audio);
} else if (type.startsWith("video")) {
holder.type.setImageResource(R.drawable.type_video);
} else {
holder.type.setImageBitmap(null);
}
}
holder.butAction.setFocusable(false);
holder.butAction.setOnClickListener(onButActionClicked);
} else { } else {
convertView.setBackgroundResource(0); convertView.setVisibility(View.GONE);
} }
holder.title.setText(item.getTitle());
if (showFeedtitle) {
holder.feedtitle.setVisibility(View.VISIBLE);
holder.feedtitle.setText(item.getFeed().getTitle());
}
if (!item.isRead()) {
holder.title.setTypeface(Typeface.DEFAULT_BOLD);
} else {
holder.title.setTypeface(Typeface.DEFAULT);
}
holder.published.setText(convertView.getResources().getString(
R.string.published_prefix)
+ DateUtils.formatSameDayTime(item.getPubDate().getTime(),
System.currentTimeMillis(), DateFormat.SHORT,
DateFormat.SHORT));
if (item.getMedia() == null) {
holder.encInfo.setVisibility(View.GONE);
} else {
holder.encInfo.setVisibility(View.VISIBLE);
if (FeedManager.getInstance().isInQueue(item)) {
holder.inPlaylist.setVisibility(View.VISIBLE);
} else {
holder.inPlaylist.setVisibility(View.GONE);
}
if (item.getMedia().isDownloaded()) {
holder.lenSize.setText(convertView.getResources().getString(
R.string.length_prefix)
+ Converter.getDurationStringLong(item.getMedia()
.getDuration()));
holder.downloaded.setVisibility(View.VISIBLE);
} else {
holder.lenSize.setText(convertView.getResources().getString(
R.string.size_prefix)
+ Converter.byteToString(item.getMedia().getSize()));
holder.downloaded.setVisibility(View.GONE);
}
if (DownloadRequester.getInstance().isDownloadingFile(
item.getMedia())) {
holder.downloading.setVisibility(View.VISIBLE);
} else {
holder.downloading.setVisibility(View.GONE);
}
String type = item.getMedia().getMime_type();
if (type.startsWith("audio")) {
holder.type.setImageResource(R.drawable.type_audio);
} else if (type.startsWith("video")) {
holder.type.setImageResource(R.drawable.type_video);
} else {
holder.type.setImageBitmap(null);
}
}
holder.butAction.setFocusable(false);
holder.butAction.setOnClickListener(onButActionClicked);
return convertView; return convertView;
} }
@ -169,4 +179,22 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
notifyDataSetChanged(); notifyDataSetChanged();
} }
@Override
public int getCount() {
if (PodcastApp.getInstance().displayOnlyEpisodes()) {
return EpisodeFilter.countItemsWithEpisodes(objects);
} else {
return super.getCount();
}
}
@Override
public FeedItem getItem(int position) {
if (PodcastApp.getInstance().displayOnlyEpisodes()) {
return EpisodeFilter.accessEpisodeByIndex(objects, position);
} else {
return super.getItem(position);
}
}
} }

View File

@ -102,14 +102,7 @@ public class ItemlistFragment extends SherlockListFragment implements
feed = FeedManager.getInstance().getFeed(feedId); feed = FeedManager.getInstance().getFeed(feedId);
items = feed.getItems(); 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, fila = new FeedItemlistAdapter(getActivity(), 0, items,
onButActionClicked, showFeedtitle); onButActionClicked, showFeedtitle);
setListAdapter(fila); setListAdapter(fila);
@ -170,15 +163,8 @@ public class ItemlistFragment extends SherlockListFragment implements
DownloadRequester.ACTION_DOWNLOAD_QUEUED)) { DownloadRequester.ACTION_DOWNLOAD_QUEUED)) {
updateProgressBarVisibility(); updateProgressBarVisibility();
} else { } else {
getActivity().runOnUiThread(new Runnable() { fila.notifyDataSetChanged();
updateProgressBarVisibility();
@Override
public void run() {
fila.notifyDataSetChanged();
updateProgressBarVisibility();
}
});
} }
} }
}; };

View File

@ -15,7 +15,8 @@ import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
public class QueueFragment extends ItemlistFragment { public class QueueFragment extends ItemlistFragment {
private static final String TAG = "QueueFragment";
public QueueFragment() { public QueueFragment() {
super(FeedManager.getInstance().getQueue(), true); super(FeedManager.getInstance().getQueue(), true);
} }

View File

@ -7,9 +7,9 @@ import de.danoeh.antennapod.feed.FeedItem;
public class EpisodeFilter { public class EpisodeFilter {
private EpisodeFilter() { private EpisodeFilter() {
} }
/** Return a copy of the itemlist without items which have no media. */ /** Return a copy of the itemlist without items which have no media. */
public static ArrayList<FeedItem> getEpisodeList(List<FeedItem> items) { public static ArrayList<FeedItem> getEpisodeList(List<FeedItem> items) {
ArrayList<FeedItem> episodes = new ArrayList<FeedItem>(items); ArrayList<FeedItem> episodes = new ArrayList<FeedItem>(items);
@ -20,4 +20,30 @@ public class EpisodeFilter {
} }
return episodes; return episodes;
} }
public static int countItemsWithEpisodes(List<FeedItem> items) {
int count = 0;
for (FeedItem item : items) {
if (item.getMedia() != null) {
count++;
}
}
return count;
}
public static FeedItem accessEpisodeByIndex(List<FeedItem> items,
int position) {
int count = 0;
for (FeedItem item : items) {
if (item.getMedia() != null) {
if (count == position) {
return item;
} else {
count++;
}
}
}
return null;
}
} }