package com.revoapp.calendar.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.revoapp.api.database.calendar.pojo.Events;
import com.revoapp.api.utils.DateTimeConvert;
import com.revoapp.calendarapp.R;
import com.revoapp.calendar.helper.ThemeHelper;

import java.util.ArrayList;

public class DayEventsAdapter extends ArrayAdapter<Events> {
    private LayoutInflater layoutInflater;
    private int resourceId;

    public DayEventsAdapter(Context context, int textViewResourceId, ArrayList<Events> eventsList) {
        super(context, textViewResourceId, eventsList);

        layoutInflater = LayoutInflater.from(context);
        resourceId = textViewResourceId;
    }

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

        if (convertView == null) {
            convertView = layoutInflater.inflate(
                    resourceId, null);
            convertView.setBackgroundResource(ThemeHelper.get_component_menu_item());

            holder = new ViewHolder();

            holder.titleTV = (TextView) convertView
                    .findViewById(R.id.event_title);
            holder.messageTV = (TextView) convertView
                    .findViewById(R.id.event_message);
            holder.timeTV = (TextView) convertView
                    .findViewById(R.id.event_time);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Events item = getItem(position);
        if (item != null) {
            if (item.getTitle() != null)
                holder.titleTV.setText(item.getTitle());
            if (item.getMessage() != null)
                holder.messageTV.setText(item.getMessage());

            holder.timeTV.setText(DateTimeConvert.getTime(convertView.getContext(), item.getDate()));
            //	holder.photoIV.setBackgroundResource(colors.get(item.getmPillColor()));
            //	holder.photoIV.setImageResource(shapes.get(item.getmPillShape()));
            //	holder.nameTV.setText(item.getmQuantity() + "x " + item.getmPillName() );
        }



        return convertView;
    }

    private static class ViewHolder {
        private TextView titleTV;
        private TextView messageTV;
        private TextView timeTV;
    }
}