diff --git a/res/layout/external_itemlist_item.xml b/res/layout/external_itemlist_item.xml new file mode 100644 index 000000000..b03113ed1 --- /dev/null +++ b/res/layout/external_itemlist_item.xml @@ -0,0 +1,40 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/de/danoeh/antennapod/adapter/AbstractFeedItemlistAdapter.java b/src/de/danoeh/antennapod/adapter/AbstractFeedItemlistAdapter.java new file mode 100644 index 000000000..39908b5d8 --- /dev/null +++ b/src/de/danoeh/antennapod/adapter/AbstractFeedItemlistAdapter.java @@ -0,0 +1,38 @@ +package de.danoeh.antennapod.adapter; + +import java.util.List; + +import de.danoeh.antennapod.PodcastApp; +import de.danoeh.antennapod.feed.FeedItem; +import de.danoeh.antennapod.util.EpisodeFilter; +import android.content.Context; +import android.widget.ArrayAdapter; + +public abstract class AbstractFeedItemlistAdapter extends ArrayAdapter { + + private List objects; + + public AbstractFeedItemlistAdapter(Context context, int textViewResourceId, + List objects) { + super(context, textViewResourceId, objects); + this.objects = objects; + } + + @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); + } + } +} diff --git a/src/de/danoeh/antennapod/adapter/ActionButtonCallback.java b/src/de/danoeh/antennapod/adapter/ActionButtonCallback.java new file mode 100644 index 000000000..3ea83f377 --- /dev/null +++ b/src/de/danoeh/antennapod/adapter/ActionButtonCallback.java @@ -0,0 +1,6 @@ +package de.danoeh.antennapod.adapter; + +public interface ActionButtonCallback { + /** Is called when the action button of a list item has been pressed. */ + abstract void onActionButtonPressed(int position); +} diff --git a/src/de/danoeh/antennapod/adapter/ExternalFeedItemlistAdapter.java b/src/de/danoeh/antennapod/adapter/ExternalFeedItemlistAdapter.java new file mode 100644 index 000000000..58181152f --- /dev/null +++ b/src/de/danoeh/antennapod/adapter/ExternalFeedItemlistAdapter.java @@ -0,0 +1,80 @@ +package de.danoeh.antennapod.adapter; + +import java.util.List; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.asynctask.FeedImageLoader; +import de.danoeh.antennapod.feed.FeedItem; + +/** + * Array adapter that should be used to display a list of FeedItems from several + * different feeds. + */ +public class ExternalFeedItemlistAdapter extends AbstractFeedItemlistAdapter { + + ActionButtonCallback callback; + + public ExternalFeedItemlistAdapter(Context context, int textViewResourceId, + List objects, + ActionButtonCallback callback) { + super(context, textViewResourceId, objects); + this.callback = callback; + } + + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + Holder holder; + FeedItem item = getItem(position); + + if (convertView == null) { + holder = new Holder(); + LayoutInflater inflater = (LayoutInflater) getContext() + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + convertView = inflater.inflate(R.layout.external_itemlist_item, null); + holder.title = (TextView) convertView + .findViewById(R.id.txtvTitle); + holder.feedImage = (ImageView) convertView + .findViewById(R.id.imgvFeedimage); + holder.butAction = (ImageButton) convertView + .findViewById(R.id.butAction); + convertView.setTag(holder); + } else { + holder = (Holder) convertView.getTag(); + } + + holder.title.setText(item.getTitle()); + holder.feedImage.setTag(item.getFeed().getImage()); + FeedImageLoader.getInstance().loadThumbnailBitmap( + item.getFeed().getImage(), + holder.feedImage, + (int) convertView.getResources().getDimension( + R.dimen.thumbnail_length)); + holder.butAction.setFocusable(false); + holder.butAction.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + callback.onActionButtonPressed(position); + } + }); + + return convertView; + + } + + static class Holder { + TextView title; + ImageView feedImage; + ImageButton butAction; + } + + +} diff --git a/src/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java b/src/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java index 7e9388ce3..052ff8f9c 100644 --- a/src/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java +++ b/src/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java @@ -3,7 +3,6 @@ package de.danoeh.antennapod.adapter; import java.text.DateFormat; import java.util.List; - import android.content.Context; import android.content.res.TypedArray; import android.graphics.Typeface; @@ -32,19 +31,17 @@ import de.danoeh.antennapod.util.Converter; import de.danoeh.antennapod.util.EpisodeFilter; import de.danoeh.antennapod.util.ThemeUtils; -public class FeedItemlistAdapter extends ArrayAdapter { - private FeedItemlistAdapter.Callback callback; +public class FeedItemlistAdapter extends AbstractFeedItemlistAdapter { + private ActionButtonCallback callback; private boolean showFeedtitle; private int selectedItemIndex; - private List objects; public static final int SELECTION_NONE = -1; public FeedItemlistAdapter(Context context, int textViewResourceId, - List objects, FeedItemlistAdapter.Callback callback, + List objects, ActionButtonCallback callback, boolean showFeedtitle) { super(context, textViewResourceId, objects); - this.objects = objects; this.callback = callback; this.showFeedtitle = showFeedtitle; this.selectedItemIndex = SELECTION_NONE; @@ -185,13 +182,13 @@ public class FeedItemlistAdapter extends ArrayAdapter { holder.butAction.setFocusable(false); holder.butAction.setOnClickListener(new OnClickListener() { - + @Override public void onClick(View v) { callback.onActionButtonPressed(position); } }); - + } else { convertView.setVisibility(View.GONE); } @@ -221,27 +218,4 @@ public class FeedItemlistAdapter extends ArrayAdapter { 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); - } - } - - public interface Callback { - /** Is called when the action button of a list item has been pressed. */ - abstract void onActionButtonPressed(int position); - } - } diff --git a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java index f04fc3824..315abd1d3 100644 --- a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -29,6 +29,8 @@ import com.actionbarsherlock.view.MenuItem; import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.ItemviewActivity; +import de.danoeh.antennapod.adapter.AbstractFeedItemlistAdapter; +import de.danoeh.antennapod.adapter.ActionButtonCallback; import de.danoeh.antennapod.adapter.FeedItemlistAdapter; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.feed.Feed; @@ -45,7 +47,7 @@ public class ItemlistFragment extends SherlockListFragment { private static final String TAG = "ItemlistFragment"; public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.danoeh.antennapod.activity.selected_feeditem"; public static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id"; - protected FeedItemlistAdapter fila; + protected AbstractFeedItemlistAdapter fila; protected FeedManager manager; protected DownloadRequester requester; @@ -107,10 +109,14 @@ public class ItemlistFragment extends SherlockListFragment { items = feed.getItems(); } - fila = new FeedItemlistAdapter(getActivity(), 0, items, - adapterCallback, showFeedtitle); + fila = createListAdapter(); setListAdapter(fila); } + + protected AbstractFeedItemlistAdapter createListAdapter() { + return new FeedItemlistAdapter(getActivity(), 0, items, + adapterCallback, showFeedtitle); + } @Override public void onPause() { @@ -188,7 +194,7 @@ public class ItemlistFragment extends SherlockListFragment { } } - private FeedItemlistAdapter.Callback adapterCallback = new FeedItemlistAdapter.Callback() { + protected ActionButtonCallback adapterCallback = new ActionButtonCallback() { @Override public void onActionButtonPressed(int position) { @@ -263,7 +269,7 @@ public class ItemlistFragment extends SherlockListFragment { return handled; } - public FeedItemlistAdapter getListAdapter() { + public AbstractFeedItemlistAdapter getListAdapter() { return fila; } diff --git a/src/de/danoeh/antennapod/fragment/QueueFragment.java b/src/de/danoeh/antennapod/fragment/QueueFragment.java index c3647c383..ba3999731 100644 --- a/src/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/src/de/danoeh/antennapod/fragment/QueueFragment.java @@ -8,6 +8,9 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.adapter.AbstractFeedItemlistAdapter; +import de.danoeh.antennapod.adapter.ExternalFeedItemlistAdapter; +import de.danoeh.antennapod.adapter.FeedItemlistAdapter; import de.danoeh.antennapod.feed.FeedManager; public class QueueFragment extends ItemlistFragment { @@ -23,6 +26,11 @@ public class QueueFragment extends ItemlistFragment { setHasOptionsMenu(true); } + protected AbstractFeedItemlistAdapter createListAdapter() { + return new ExternalFeedItemlistAdapter(getActivity(), 0, items, + adapterCallback); + } + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); diff --git a/src/de/danoeh/antennapod/fragment/UnreadItemlistFragment.java b/src/de/danoeh/antennapod/fragment/UnreadItemlistFragment.java index b37d1f09e..22b03b582 100644 --- a/src/de/danoeh/antennapod/fragment/UnreadItemlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/UnreadItemlistFragment.java @@ -7,6 +7,8 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.adapter.AbstractFeedItemlistAdapter; +import de.danoeh.antennapod.adapter.ExternalFeedItemlistAdapter; import de.danoeh.antennapod.feed.FeedManager; /** Contains all unread items. */ @@ -23,6 +25,11 @@ public class UnreadItemlistFragment extends ItemlistFragment { setHasOptionsMenu(true); } + protected AbstractFeedItemlistAdapter createListAdapter() { + return new ExternalFeedItemlistAdapter(getActivity(), 0, items, + adapterCallback); + } + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater);