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

@ -38,6 +38,8 @@ public class PodcastApp extends Application implements
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,6 +127,9 @@ 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);
} }
} }
@ -131,6 +137,10 @@ public class PodcastApp extends Application implements
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,10 +80,11 @@ 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) { if (position == selectedItemIndex) {
convertView.setBackgroundColor(convertView.getResources().getColor( convertView.setBackgroundColor(convertView.getResources()
R.color.selection_background)); .getColor(R.color.selection_background));
} else { } else {
convertView.setBackgroundResource(0); convertView.setBackgroundResource(0);
} }
@ -110,15 +116,17 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
holder.inPlaylist.setVisibility(View.GONE); holder.inPlaylist.setVisibility(View.GONE);
} }
if (item.getMedia().isDownloaded()) { if (item.getMedia().isDownloaded()) {
holder.lenSize.setText(convertView.getResources().getString( holder.lenSize.setText(convertView.getResources()
R.string.length_prefix) .getString(R.string.length_prefix)
+ Converter.getDurationStringLong(item.getMedia() + Converter.getDurationStringLong(item.getMedia()
.getDuration())); .getDuration()));
holder.downloaded.setVisibility(View.VISIBLE); holder.downloaded.setVisibility(View.VISIBLE);
} else { } else {
holder.lenSize.setText(convertView.getResources().getString( holder.lenSize
.setText(convertView.getResources().getString(
R.string.size_prefix) R.string.size_prefix)
+ Converter.byteToString(item.getMedia().getSize())); + Converter.byteToString(item.getMedia()
.getSize()));
holder.downloaded.setVisibility(View.GONE); holder.downloaded.setVisibility(View.GONE);
} }
@ -142,7 +150,9 @@ public class FeedItemlistAdapter extends ArrayAdapter<FeedItem> {
holder.butAction.setFocusable(false); holder.butAction.setFocusable(false);
holder.butAction.setOnClickListener(onButActionClicked); holder.butAction.setOnClickListener(onButActionClicked);
} else {
convertView.setVisibility(View.GONE);
}
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

@ -103,13 +103,6 @@ public class ItemlistFragment extends SherlockListFragment implements
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,16 +163,9 @@ public class ItemlistFragment extends SherlockListFragment implements
DownloadRequester.ACTION_DOWNLOAD_QUEUED)) { DownloadRequester.ACTION_DOWNLOAD_QUEUED)) {
updateProgressBarVisibility(); updateProgressBarVisibility();
} else { } else {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
fila.notifyDataSetChanged(); fila.notifyDataSetChanged();
updateProgressBarVisibility(); updateProgressBarVisibility();
} }
});
}
} }
}; };

View File

@ -15,6 +15,7 @@ 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

@ -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;
}
} }