StudyXrecAdapter.java 3.0 KB
package com.hh.xuetubao.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hh.xuetubao.R;
import com.hh.xuetubao.bean.LearningRecordDataBean;

import java.util.List;

public class StudyXrecAdapter extends RecyclerView.Adapter<StudyXrecAdapter.ViewHolder> {
    private Context context;
    private List<LearningRecordDataBean.learnBean> list;

    public StudyXrecAdapter(Context context, List<LearningRecordDataBean.learnBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.xrv_record, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        if (list.get(position).getLessonName() != null)
            holder.title.setText(list.get(position).getLessonName());
        holder.percent.setText(String.valueOf(list.get(position).getStudyPercent()));
        if (list.get(position).getLatelyStudyTime() != null)
            holder.time.setText(list.get(position).getLatelyStudyTime());
        if (list.get(position).getLatelyResourceName() != null)
            holder.resourse.setText(list.get(position).getLatelyResourceName());
        if (list.get(position).getCoverPic() != null)
            Glide.with(context).load(list.get(position).getCoverPic()).into(holder.img);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (turnTo != null) {
                    turnTo.turn(list.get(position).getLessonOid());
                }
            }
        });
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView time;
        private final ImageView img;
        private final TextView title;
        private final TextView resourse;
        private final TextView percent;

        public ViewHolder(View itemView) {
            super(itemView);
            time = (TextView) itemView.findViewById(R.id.tv_time);
            title = (TextView) itemView.findViewById(R.id.title);
            percent = (TextView) itemView.findViewById(R.id.tv_percent);
            img = (ImageView) itemView.findViewById(R.id.img);
            resourse = (TextView) itemView.findViewById(R.id.tv_resourse);
        }
    }

    private TurnTo turnTo;

    public void setTurnTo(TurnTo turnTo) {
        this.turnTo = turnTo;
    }

    public interface TurnTo {
        void turn(String LessonOid);
    }
}