package com.shaon.firebasecontactsapp.adapters;
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.bumptech.glide.Glide;
import com.google.android.material.imageview.ShapeableImageView;
import com.shaon.firebasecontactsapp.R;
import com.shaon.firebasecontactsapp.models.StudentModel;
import java.util.ArrayList;
import java.util.List;
public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.StudentViewHolder> {
List<StudentModel> studentList = new ArrayList<>();
public StudentAdapter(List<StudentModel> studentList) {
this.studentList = studentList;
}
@NonNull
@Override
public StudentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.sample_row, parent, false);
return new StudentViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull StudentViewHolder holder, int position) {
StudentModel model = studentList.get(position);
if(model != null){
Glide.with(holder.profileImage.getContext())
.load(model.getProfileImg())
.placeholder(R.drawable.placeholder_image)
.into(holder.profileImage);
}
holder.name.setText(model.getName());
holder.department.setText(model.getDepartment());
holder.number.setText(model.getNumber());
}
@Override
public int getItemCount() {
return studentList.size();
}
public class StudentViewHolder extends RecyclerView.ViewHolder {
ShapeableImageView profileImage, edit, delete;
TextView name, department, number;
public StudentViewHolder(@NonNull View itemView) {
super(itemView);
profileImage = itemView.findViewById(R.id.proImg);
edit = itemView.findViewById(R.id.edit);
delete = itemView.findViewById(R.id.delete);
name = itemView.findViewById(R.id.nameTv);
department = itemView.findViewById(R.id.departmentTV);
number = itemView.findViewById(R.id.phoneNumTv);
}
}
}