package com.sipai.jspatrol.Statement;

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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sipai.jspatrol.Bean.Statement;
import com.sipai.jspatrol.R;
import com.sipai.jspatrol.URL.GuideMenuUrl;
import com.sipai.jspatrol.Webv.WebStatementActivity;

import java.util.List;

/**
 * created by lvliming on 2021/1/19
 */
public class StatementAdapter extends RecyclerView.Adapter<StatementAdapter.ViewHolder> {
    private Context context;
    private List<Statement> list;

    public StatementAdapter(Context context, List<Statement> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_statement,parent,false);
        final ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.node.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = viewHolder.getAdapterPosition();
                Statement item = list.get(position);
                WebStatementActivity.actionStart(context, GuideMenuUrl.url_statement, item.getRptname(),item.getId());
            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Statement item = list.get(position);
        holder.tv_rptdt.setText(item.getRptdt());
        holder.tv_inputusername.setText(item.getInputusername());
        holder.tv_rptname.setText(item.getRptname());
        if (item.getInsdt().length()>16){
            holder.tv_insdt.setText(item.getInsdt().substring(0,16));
        }else {
            holder.tv_insdt.setText(item.getInsdt());
        }
    }

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

    class ViewHolder extends RecyclerView.ViewHolder{
        View node;
        TextView tv_rptdt,tv_inputusername,tv_rptname,tv_insdt;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            node = itemView;
            tv_rptdt = itemView.findViewById(R.id.moudle_item_statement_tv_rptdt);
            tv_inputusername = itemView.findViewById(R.id.moudle_item_statement_tv_inputusername);
            tv_rptname = itemView.findViewById(R.id.moudle_item_statement_tv_rptname);
            tv_insdt = itemView.findViewById(R.id.moudle_item_statement_tv_insdt);
        }
    }

}
