package com.sendsms.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sendsms.R;
import com.sendsms.model.MessageDetails;
import com.sendsms.utills.Constant;

import java.util.ArrayList;


/**
 * Created by Risheek on 10/19/2015.
 */
public class GetAllDataAdapter extends BaseAdapter {

    private Context context;
    ArrayList<MessageDetails> data;
    private DisplayImageOptions options;
    public GetAllDataAdapter(Context context, ArrayList<MessageDetails> tutor_arraylist) {
        this.context = context;
        this.data = tutor_arraylist;

        Bitmap default_bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(new BitmapDrawable(context.getResources(), default_bitmap))
                .showImageForEmptyUri(new BitmapDrawable(context.getResources(), default_bitmap))
                .showImageOnFail(new BitmapDrawable(context.getResources(), default_bitmap))
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .build();
    }



    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }


    @Override
    public long getItemId(int position) {
        return position;
    }

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

        ViewHolder mViewHolder;
        if (convertView == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            convertView = inflater.inflate(R.layout.get_all_data_raw, viewGroup, false);
            mViewHolder = new ViewHolder();

            mViewHolder.name = (TextView) convertView.findViewById(R.id.name);
            mViewHolder.mobile = (TextView) convertView.findViewById(R.id.mobile);
            mViewHolder.message = (TextView) convertView.findViewById(R.id.message);
            mViewHolder.msg_count = (TextView) convertView.findViewById(R.id.msg_count);

            convertView.setTag(mViewHolder);
        } else {

            mViewHolder = (ViewHolder) convertView.getTag();
        }

        if (data != null) {

            mViewHolder.name.setText(data.get(position).getName());
            mViewHolder.mobile.setText(data.get(position).getNumber());
            mViewHolder.message.setText(data.get(position).getMessage());

            int pos = position+1;
            mViewHolder.msg_count.setText(""+pos);


        }
        return convertView;
    }

    private static class ViewHolder {
        TextView name, mobile, message,msg_count;
    }

}
