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.ImageView;
import android.widget.TextView;

import com.revoapp.calendarapp.R;
import com.revoapp.calendar.helper.SimpleDialogItem;

import java.util.ArrayList;

public class WeekDayHoursAdapter extends ArrayAdapter<SimpleDialogItem> {
    private LayoutInflater inflater;
    private int resourceId;

    public WeekDayHoursAdapter(Context context, int textViewResourceId,
                               ArrayList<SimpleDialogItem> objects) {
        super(context, textViewResourceId, objects);

        resourceId = textViewResourceId;
        inflater = (LayoutInflater) getContext().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final SimpleDialogItem item = getItem(position);
        if (item == null) {
            return null;
        }


        ViewHolder holder;
        int dayTVHeigh = parent.getHeight()/4 - 2;

        if (convertView == null) {
            convertView = inflater.inflate(resourceId, null);

            holder = new ViewHolder();
            holder.dayTV = (TextView) convertView
                    .findViewById(R.id.day_hour);
            holder.dayImage = (ImageView) convertView
                    .findViewById(R.id.day_image);

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

        holder.dayImage.setImageResource(item.getDrawable());
        holder.dayTV.setText(item.getLabel());

        holder.dayTV.setHeight(dayTVHeigh);

        return convertView;
    }

    private class ViewHolder {
        TextView dayTV;
        ImageView dayImage;
    }
}