Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package com.wwe.universe.ui.adapter;
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.bumptech.glide.Glide;
import com.wwe.universe.R;
import java.util.List;
import java.util.Locale;
public class PlaylistStackAdapter extends ArrayAdapter<Video> {
private static final List<Video> mVideos;
private final LayoutInflater mInflater;
public PlaylistStackAdapter(List<Video> videos, Context context) {
super(context, R.layout.item_playlist_stack, videos);
PlaylistStackAdapter.mVideos = videos;
mInflater = LayoutInflater.from(context);
public int getCount() {
return PlaylistStackAdapter.mVideos.size();
public Video getItem(int position) {
return PlaylistStackAdapter.mVideos.get(position);
public long getItemId(int position) {
return position;
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
Video video = mVideos.get(position);
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_playlist_stack, parent, false);
holder = new ViewHolder(convertView);
} else {
holder = (ViewHolder) convertView.getTag();
return convertView;
private String formatDuration(long duration) {
int seconds = (int) duration % 60;
int minutes = (int) duration / 60;
return String.format(Locale.US, "%d:%02d", minutes, seconds);
public static class ViewHolder {
final ImageView videoImage;
final TextView videoDuration;
ViewHolder(View view) {
videoImage = (ImageView) view.findViewById(;
videoDuration = (TextView) view.findViewById(;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.