Created external feeditemlist adapters
This commit is contained in:
parent
5221f5f5ec
commit
65d413cbb8
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imgvFeedimage"
|
||||
android:layout_width="@dimen/thumbnail_length"
|
||||
android:layout_height="@dimen/thumbnail_length"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/butAction"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:background="?attr/borderless_button"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:scaleType="fitEnd"
|
||||
android:src="?attr/spinner_button" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_margin="8dp"
|
||||
android:layout_toLeftOf="@id/butAction"
|
||||
android:layout_toRightOf="@id/imgvFeedimage"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/text_size_medium" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -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<FeedItem> {
|
||||
|
||||
private List<FeedItem> objects;
|
||||
|
||||
public AbstractFeedItemlistAdapter(Context context, int textViewResourceId,
|
||||
List<FeedItem> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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<FeedItem> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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<FeedItem> {
|
||||
private FeedItemlistAdapter.Callback callback;
|
||||
public class FeedItemlistAdapter extends AbstractFeedItemlistAdapter {
|
||||
private ActionButtonCallback callback;
|
||||
private boolean showFeedtitle;
|
||||
private int selectedItemIndex;
|
||||
private List<FeedItem> objects;
|
||||
|
||||
public static final int SELECTION_NONE = -1;
|
||||
|
||||
public FeedItemlistAdapter(Context context, int textViewResourceId,
|
||||
List<FeedItem> objects, FeedItemlistAdapter.Callback callback,
|
||||
List<FeedItem> 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<FeedItem> {
|
|||
|
||||
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<FeedItem> {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue