package com.example.service04;


import android.content.Context;
import android.graphics.drawable.ColorDrawable;
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 java.util.List;

public class AlarmAdapter extends ArrayAdapter<Alarm> 
{

    public AlarmAdapter(Context context, List<Alarm> alarmes) 
    {
        super(context, 0, alarmes);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {

        if(convertView == null)
        {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_alarm,parent, false);
        }

        AlarmViewHolder viewHolder = (AlarmViewHolder) convertView.getTag();
        
        if(viewHolder == null)
        {
            viewHolder = new AlarmViewHolder();
            viewHolder.pseudo = (TextView) convertView.findViewById(R.id.pseudo);
            viewHolder.text = (TextView) convertView.findViewById(R.id.text);
            //viewHolder.avatar = (ImageView) convertView.findViewById(R.id.avatar);
            convertView.setTag(viewHolder);
        }

        //getItem(position) va récupérer l'item [position] de la List<Tweet> tweets
        Alarm obj = getItem(position);
        viewHolder.pseudo.setText(obj.get_nom());
        viewHolder.text.setText(obj.getFromDate());
        //viewHolder.avatar.setImageDrawable(new ColorDrawable(tweet.getColor()));

        return convertView;
    }

    private class AlarmViewHolder
    {
        public TextView pseudo;
        public TextView text;
        public ImageView avatar;

    }
}