package com.hong.job_management;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;

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

import java.util.List;

class myAdapter_Schedule extends BaseAdapter {
    private Activity mContext;
    private LayoutInflater mInflater;
    private List<Subject_schedule> mDatas;
    private class ViewHolder{
        private TextView subject_name;
        private TextView subject_value;
        private ProgressBar subject_progress;
    }

    public myAdapter_Schedule(Activity context ,List<Subject_schedule> 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(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ViewHolder viewHolder=null;
        if(convertView==null)
        {
            convertView =mInflater.inflate(R.layout.schedule_item,null);
            viewHolder=new ViewHolder();
            viewHolder.subject_name=(TextView) convertView.findViewById(R.id.subject_name);
            viewHolder.subject_value=(TextView)convertView.findViewById(R.id.subject_value);
            viewHolder.subject_progress=(ProgressBar)convertView.findViewById((R.id.subject_progress));
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder) convertView.getTag();
        }
        Subject_schedule subject_schedule=(Subject_schedule) getItem(position);
        viewHolder.subject_name.setText(subject_schedule.getSubject());
        viewHolder.subject_progress.setMax(subject_schedule.getMax());
        viewHolder.subject_progress.setProgress(subject_schedule.getProgress());
        viewHolder.subject_value.setText(String.valueOf((int)(((float)subject_schedule.getProgress()/(float)subject_schedule.getMax())*1000)/10.0+"%"));
        return convertView;
    }
}