Added default getView() implementation for itemlistadapter
This commit is contained in:
parent
8bab080a5a
commit
faa23de4de
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:paddingLeft="4dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvItemname"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/text_size_medium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvPublished"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/txtvItemname"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="@dimen/text_size_micro" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imgvType"
|
||||
android:layout_width="@dimen/enc_icons_size"
|
||||
android:layout_height="@dimen/enc_icons_size"
|
||||
android:layout_below="@id/txtvPublished"
|
||||
android:padding="2dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvLenSize"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/txtvPublished"
|
||||
android:maxLines="2"
|
||||
android:textColor="?android:attr/textColorTertiary"
|
||||
android:textSize="@dimen/text_size_micro" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -1,39 +0,0 @@
|
|||
package de.danoeh.antennapod.adapter;
|
||||
|
||||
import android.widget.BaseAdapter;
|
||||
import de.danoeh.antennapod.feed.FeedItem;
|
||||
|
||||
public abstract class AbstractFeedItemlistAdapter extends BaseAdapter {
|
||||
|
||||
ItemAccess itemAccess;
|
||||
|
||||
public AbstractFeedItemlistAdapter(ItemAccess itemAccess) {
|
||||
super();
|
||||
if (itemAccess == null) {
|
||||
throw new IllegalArgumentException("itemAccess must not be null");
|
||||
}
|
||||
this.itemAccess = itemAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return itemAccess.getCount();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeedItem getItem(int position) {
|
||||
return itemAccess.getItem(position);
|
||||
}
|
||||
|
||||
public static interface ItemAccess {
|
||||
int getCount();
|
||||
|
||||
FeedItem getItem(int position);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
package de.danoeh.antennapod.adapter;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Adapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.adapter.InternalFeedItemlistAdapter.Holder;
|
||||
import de.danoeh.antennapod.feed.FeedItem;
|
||||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
import de.danoeh.antennapod.feed.MediaType;
|
||||
import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.util.Converter;
|
||||
import de.danoeh.antennapod.util.ThemeUtils;
|
||||
|
||||
public class DefaultFeedItemlistAdapter extends BaseAdapter {
|
||||
|
||||
ItemAccess itemAccess;
|
||||
private Context context;
|
||||
|
||||
public DefaultFeedItemlistAdapter(Context context, ItemAccess itemAccess) {
|
||||
super();
|
||||
this.context = context;
|
||||
if (itemAccess == null) {
|
||||
throw new IllegalArgumentException("itemAccess must not be null");
|
||||
}
|
||||
this.itemAccess = itemAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return itemAccess.getCount();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeedItem getItem(int position) {
|
||||
return itemAccess.getItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Holder holder;
|
||||
final FeedItem item = getItem(position);
|
||||
|
||||
if (convertView == null) {
|
||||
holder = new Holder();
|
||||
LayoutInflater inflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.default_feeditemlist_item, null);
|
||||
holder.title = (TextView) convertView
|
||||
.findViewById(R.id.txtvItemname);
|
||||
holder.lenSize = (TextView) convertView
|
||||
.findViewById(R.id.txtvLenSize);
|
||||
|
||||
holder.published = (TextView) convertView
|
||||
.findViewById(R.id.txtvPublished);
|
||||
holder.type = (ImageView) convertView.findViewById(R.id.imgvType);
|
||||
convertView.setTag(holder);
|
||||
|
||||
} else {
|
||||
holder = (Holder) convertView.getTag();
|
||||
}
|
||||
if (!(getItemViewType(position) == Adapter.IGNORE_ITEM_VIEW_TYPE)) {
|
||||
convertView.setVisibility(View.VISIBLE);
|
||||
holder.title.setText(item.getTitle());
|
||||
holder.published.setText(convertView.getResources().getString(
|
||||
R.string.published_prefix)
|
||||
+ DateUtils.formatSameDayTime(item.getPubDate().getTime(),
|
||||
System.currentTimeMillis(), DateFormat.MEDIUM,
|
||||
DateFormat.SHORT));
|
||||
|
||||
if (item.getMedia() == null) {
|
||||
holder.type.setVisibility(View.GONE);
|
||||
holder.lenSize.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.lenSize.setVisibility(View.VISIBLE);
|
||||
holder.lenSize.setText(convertView.getResources().getString(
|
||||
R.string.size_prefix)
|
||||
+ Converter.byteToString(item.getMedia().getSize()));
|
||||
|
||||
TypedArray typeDrawables = context
|
||||
.obtainStyledAttributes(new int[] { R.attr.type_audio,
|
||||
R.attr.type_video });
|
||||
MediaType mediaType = item.getMedia().getMediaType();
|
||||
if (mediaType == MediaType.AUDIO) {
|
||||
holder.type.setImageDrawable(typeDrawables.getDrawable(0));
|
||||
holder.type.setVisibility(View.VISIBLE);
|
||||
} else if (mediaType == MediaType.VIDEO) {
|
||||
holder.type.setImageDrawable(typeDrawables.getDrawable(1));
|
||||
holder.type.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.type.setImageBitmap(null);
|
||||
holder.type.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
convertView.setVisibility(View.GONE);
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
protected static class Holder {
|
||||
TextView title;
|
||||
TextView published;
|
||||
TextView lenSize;
|
||||
ImageView type;
|
||||
|
||||
}
|
||||
|
||||
public static interface ItemAccess {
|
||||
int getCount();
|
||||
|
||||
FeedItem getItem(int position);
|
||||
}
|
||||
|
||||
protected Context getContext() {
|
||||
return context;
|
||||
}
|
||||
}
|
|
@ -21,21 +21,19 @@ import de.danoeh.antennapod.storage.DownloadRequester;
|
|||
import de.danoeh.antennapod.util.Converter;
|
||||
import de.danoeh.antennapod.util.ThemeUtils;
|
||||
|
||||
public class FeedItemlistAdapter extends AbstractFeedItemlistAdapter {
|
||||
|
||||
private Context context;
|
||||
|
||||
/** List adapter for items of feeds that the user has already subscribed to. */
|
||||
public class InternalFeedItemlistAdapter extends DefaultFeedItemlistAdapter {
|
||||
|
||||
private ActionButtonCallback callback;
|
||||
private boolean showFeedtitle;
|
||||
private int selectedItemIndex;
|
||||
|
||||
public static final int SELECTION_NONE = -1;
|
||||
|
||||
public FeedItemlistAdapter(Context context,
|
||||
AbstractFeedItemlistAdapter.ItemAccess itemAccess,
|
||||
public InternalFeedItemlistAdapter(Context context,
|
||||
DefaultFeedItemlistAdapter.ItemAccess itemAccess,
|
||||
ActionButtonCallback callback, boolean showFeedtitle) {
|
||||
super(itemAccess);
|
||||
this.context = context;
|
||||
super(context, itemAccess);
|
||||
this.callback = callback;
|
||||
this.showFeedtitle = showFeedtitle;
|
||||
this.selectedItemIndex = SELECTION_NONE;
|
||||
|
@ -48,7 +46,7 @@ public class FeedItemlistAdapter extends AbstractFeedItemlistAdapter {
|
|||
|
||||
if (convertView == null) {
|
||||
holder = new Holder();
|
||||
LayoutInflater inflater = (LayoutInflater) context
|
||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.feeditemlist_item, null);
|
||||
holder.title = (TextView) convertView
|
||||
|
@ -163,7 +161,7 @@ public class FeedItemlistAdapter extends AbstractFeedItemlistAdapter {
|
|||
holder.downloading.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
TypedArray typeDrawables = context.obtainStyledAttributes(
|
||||
TypedArray typeDrawables = getContext().obtainStyledAttributes(
|
||||
new int[] { R.attr.type_audio, R.attr.type_video });
|
||||
MediaType mediaType = item.getMedia().getMediaType();
|
||||
if (mediaType == MediaType.AUDIO) {
|
||||
|
@ -194,14 +192,10 @@ public class FeedItemlistAdapter extends AbstractFeedItemlistAdapter {
|
|||
|
||||
}
|
||||
|
||||
static class Holder {
|
||||
TextView title;
|
||||
static class Holder extends DefaultFeedItemlistAdapter.Holder {
|
||||
TextView feedtitle;
|
||||
TextView published;
|
||||
TextView lenSize;
|
||||
ImageView inPlaylist;
|
||||
ImageView downloaded;
|
||||
ImageView type;
|
||||
ImageView downloading;
|
||||
ImageButton butAction;
|
||||
View statusUnread;
|
|
@ -17,9 +17,9 @@ import com.actionbarsherlock.app.SherlockListFragment;
|
|||
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.DefaultFeedItemlistAdapter;
|
||||
import de.danoeh.antennapod.adapter.ActionButtonCallback;
|
||||
import de.danoeh.antennapod.adapter.FeedItemlistAdapter;
|
||||
import de.danoeh.antennapod.adapter.InternalFeedItemlistAdapter;
|
||||
import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
|
||||
import de.danoeh.antennapod.feed.EventDistributor;
|
||||
import de.danoeh.antennapod.feed.Feed;
|
||||
|
@ -42,11 +42,11 @@ public class ItemlistFragment extends SherlockListFragment {
|
|||
|
||||
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 AbstractFeedItemlistAdapter fila;
|
||||
protected InternalFeedItemlistAdapter fila;
|
||||
protected FeedManager manager = FeedManager.getInstance();
|
||||
protected DownloadRequester requester = DownloadRequester.getInstance();
|
||||
|
||||
private AbstractFeedItemlistAdapter.ItemAccess itemAccess;
|
||||
private DefaultFeedItemlistAdapter.ItemAccess itemAccess;
|
||||
|
||||
private Feed feed;
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class ItemlistFragment extends SherlockListFragment {
|
|||
/** Argument for FeeditemlistAdapter */
|
||||
protected boolean showFeedtitle;
|
||||
|
||||
public ItemlistFragment(AbstractFeedItemlistAdapter.ItemAccess itemAccess,
|
||||
public ItemlistFragment(DefaultFeedItemlistAdapter.ItemAccess itemAccess,
|
||||
boolean showFeedtitle) {
|
||||
super();
|
||||
this.itemAccess = itemAccess;
|
||||
|
@ -96,7 +96,7 @@ public class ItemlistFragment extends SherlockListFragment {
|
|||
long feedId = getArguments().getLong(ARGUMENT_FEED_ID);
|
||||
final Feed feed = FeedManager.getInstance().getFeed(feedId);
|
||||
this.feed = feed;
|
||||
itemAccess = new AbstractFeedItemlistAdapter.ItemAccess() {
|
||||
itemAccess = new DefaultFeedItemlistAdapter.ItemAccess() {
|
||||
|
||||
@Override
|
||||
public FeedItem getItem(int position) {
|
||||
|
@ -111,8 +111,8 @@ public class ItemlistFragment extends SherlockListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
protected AbstractFeedItemlistAdapter createListAdapter() {
|
||||
return new FeedItemlistAdapter(getActivity(), itemAccess,
|
||||
protected InternalFeedItemlistAdapter createListAdapter() {
|
||||
return new InternalFeedItemlistAdapter(getActivity(), itemAccess,
|
||||
adapterCallback, showFeedtitle);
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ public class ItemlistFragment extends SherlockListFragment {
|
|||
return handled;
|
||||
}
|
||||
|
||||
public AbstractFeedItemlistAdapter getListAdapter() {
|
||||
public InternalFeedItemlistAdapter getListAdapter() {
|
||||
return fila;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@ package de.danoeh.antennapod.fragment;
|
|||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.adapter.AbstractFeedItemlistAdapter;
|
||||
import de.danoeh.antennapod.adapter.DefaultFeedItemlistAdapter;
|
||||
import de.danoeh.antennapod.adapter.InternalFeedItemlistAdapter;
|
||||
import de.danoeh.antennapod.feed.EventDistributor;
|
||||
import de.danoeh.antennapod.feed.FeedItem;
|
||||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
|
@ -12,7 +13,7 @@ public class PlaybackHistoryFragment extends ItemlistFragment {
|
|||
private static final String TAG = "PlaybackHistoryFragment";
|
||||
|
||||
public PlaybackHistoryFragment() {
|
||||
super(new AbstractFeedItemlistAdapter.ItemAccess() {
|
||||
super(new DefaultFeedItemlistAdapter.ItemAccess() {
|
||||
|
||||
@Override
|
||||
public FeedItem getItem(int position) {
|
||||
|
@ -40,7 +41,7 @@ public class PlaybackHistoryFragment extends ItemlistFragment {
|
|||
}
|
||||
|
||||
private EventDistributor.EventListener historyUpdate = new EventDistributor.EventListener() {
|
||||
|
||||
|
||||
@Override
|
||||
public void update(EventDistributor eventDistributor, Integer arg) {
|
||||
if ((EventDistributor.PLAYBACK_HISTORY_UPDATE & arg) != 0) {
|
||||
|
@ -48,7 +49,7 @@ public class PlaybackHistoryFragment extends ItemlistFragment {
|
|||
Log.d(TAG, "Received content update");
|
||||
fila.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue