package com.hong.job_management;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

public class myAdapter_Homework extends BaseAdapter {
    private Activity mContext;
    private LayoutInflater mInflater;
    private List<Homework> mDatas;
    private class ViewHolder{
        private TextView homework_name;
        private TextView homework_subject;
        private TextView homework_time;
        private TextView homework_rank;
        private TextView homework_finish;
    }

    @Override
    public int getItemViewType(int position) {
        int Isfinish=mDatas.get(position).isfinish;
        if(Isfinish==1){
            return 1;
        }else{
            return 0;
        }
    }

    public myAdapter_Homework(Activity context , List<Homework> data) {
        mContext=context;
        mDatas=data;
        mInflater=LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return (mDatas != null ? mDatas.size() : 0);
    }

    @Override
    public Object getItem(int position) {
        return (mDatas != null ? mDatas.get(position) : null);
    }

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

    @NonNull
    @Override
    public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ViewHolder viewHolder=null;
        if(convertView == null){
            convertView =mInflater.inflate(R.layout.homework_item,null);
            viewHolder =new ViewHolder();
            viewHolder.homework_name=(TextView)convertView.findViewById(R.id.homework_name);
            viewHolder.homework_subject=(TextView)convertView.findViewById(R.id.homework_subject);
            viewHolder.homework_rank=(TextView)convertView.findViewById(R.id.homework_rank);
            viewHolder.homework_time=(TextView)convertView.findViewById(R.id.homework_time);
            viewHolder.homework_finish=(TextView)convertView.findViewById(R.id.homework_finish);
            convertView.setTag(viewHolder);
        } else {
            viewHolder =(ViewHolder)convertView.getTag();
        }
        Homework homework= (Homework) getItem(position);
        viewHolder.homework_name.setText(homework.getHomework_name());
        viewHolder.homework_subject.setText(homework.getHomework_subject());
        viewHolder.homework_rank.setText(homework.getHomework_rank());
        viewHolder.homework_time.setText(homework.getHomework_time());
        if(homework.isfinish==0)
        {
            viewHolder.homework_finish.setText("×");
        }else{
            viewHolder.homework_finish.setText("√");
        }
        return convertView;
    }

}
