Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
YoutTubePlayList Item Adapter using ImageLoader
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.api.services.youtube.model.PlaylistItem;
import com.google.api.services.youtube.model.PlaylistItemSnippet;
import com.google.api.services.youtube.model.Thumbnail;
import com.google.api.services.youtube.model.ThumbnailDetails;
import com.novoda.imageloader.core.model.ImageTag;
import com.novoda.imageloader.core.model.ImageTagFactory;
import java.util.List;
public class PlaylistItemAdapter extends ArrayAdapter<PlaylistItem> {
private ImageTagFactory mTagFactory = ImageTagFactory.newInstance();
public PlaylistItemAdapter(Context context, List<PlaylistItem> objects) {
super(context, 0, objects);
mTagFactory.setHeight(100);
mTagFactory.setWidth(100);
mTagFactory.setDefaultImageResId(R.drawable.ic_launcher);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.video_resource_item,
null);
}
PlaylistItem res = getItem(position);
ImageView iv = (ImageView) convertView.findViewById(R.id.video_thumbnail);
TextView tv1 = (TextView) convertView.findViewById(R.id.video_title);
tv1.setText(res.getSnippet().getTitle());
String url = getThumbnailUrl(res.getSnippet());
ImageTag tag = mTagFactory.build(url, getContext());
iv.setTag(tag);
SampleApplication.getImageManager().getLoader().load(iv);
return convertView;
}
private String getThumbnailUrl(PlaylistItemSnippet snippet) {
ThumbnailDetails thumbs = snippet.getThumbnails();
Thumbnail thumb = thumbs.getDefault();
if (thumb == null)
return null;
return thumb.getUrl();
}
}// end of class
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/video_item_padding"
>
<ImageView
android:id="@+id/video_thumbnail"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/video_item_padding"
android:layout_width="@dimen/video_thumb_width"
android:layout_height="@dimen/video_thumb_height"
/>
<TextView
android:id="@+id/video_title"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/video_thumbnail"/>
</RelativeLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment