package com.qhclh.ytzh.index.planorder;

import android.content.Context;
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.bumptech.glide.Glide;
import com.qhclh.ytzh.R;
import com.qhclh.ytzh.bean.NewsBean;

import java.util.List;

/**
 * Created by 青花瓷 on 2017/11/30.
 */
///< 预警详情页
public class WarningAdapter extends BaseAdapter {
    private Context context;
    private List<NewsBean> list;
    private LayoutInflater layoutInflater;

    public WarningAdapter(Context context, List<NewsBean> list) {
        this.context = context;
        this.list = list;
        layoutInflater = LayoutInflater.from(context);
    }

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

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return list.get(i).getId();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        NewsBean message = list.get(i);
        if (view == null){
            view = layoutInflater.inflate(R.layout.item_warning,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.warning_pic = view.findViewById(R.id.warning_pic);
            viewHolder.warning_time = view.findViewById(R.id.warning_time);
            viewHolder.warning_content = view.findViewById(R.id.warning_content);

            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        Glide.with(context)
                .load(message.getUrl())
                .error(R.mipmap.ic_launcher_round)
                .placeholder(R.mipmap.ic_launcher_round)
                .into(viewHolder.warning_pic);

        viewHolder.warning_time.setText(message.getTime());
        viewHolder.warning_content.setText(message.getContent());

        return view;
    }

    private class ViewHolder{
        private ImageView warning_pic;

        private TextView warning_time;
        private TextView warning_content;
    }
}
