package bwie.com.jindongdemo.adapter.fragment02adapter;
import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import java.util.List;
import bwie.com.jindongdemo.R;
import bwie.com.jindongdemo.bean.fragment02bean.RightBean;
/**
* Created by 怪胎 on 2018.4.21.
*/
public class RightMyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<RightBean.DataBean> list;
private Context context;
private OnItemClickListener mOnItemClickListener;
public RightMyAdapter(List<RightBean.DataBean> list, Context context) {
this.list = list;
this.context = context;
}
public void setOnItemClickListener(OnItemClickListener onItemClickListener ){
this. mOnItemClickListener=onItemClickListener;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.fragment02_right_item01,parent,false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
MyViewHolder my = (MyViewHolder) holder;
my.tv.setText(list.get(position).getName());
SecondAdapter secondAdapter = new SecondAdapter(list.get(position).getList(), context);
my.recyclerView.setLayoutManager(new GridLayoutManager(context,3));
my.recyclerView.setAdapter(secondAdapter);
}
@Override
public int getItemCount() {
if (list != null){
return list.size();
}
return 0;
}
class MyViewHolder extends RecyclerView.ViewHolder{
private RecyclerView recyclerView;
private TextView tv;
public MyViewHolder(View itemView) {
super(itemView);
tv = itemView.findViewById(R.id.fragment02_right_tv01);
recyclerView = itemView.findViewById(R.id.fragment02_right_rlv02);
}
}
class SecondAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
private List<RightBean.DataBean.ListBean> listBeans;
private Context context;
public SecondAdapter(List<RightBean.DataBean.ListBean> listBeans, Context context) {
this.listBeans = listBeans;
this.context = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.fragment02_right_item02,parent,false);
return new SecondMyAdapter(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
SecondMyAdapter myAdapter = (SecondMyAdapter) holder;
myAdapter.textView.setText(listBeans.get(position).getName());
myAdapter.img.setImageURI(listBeans.get(position).getIcon());
if(mOnItemClickListener!=null){
myAdapter.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pscid = listBeans.get(position).getPscid();
mOnItemClickListener.onClick(pscid);
}
});
}
}
@Override
public int getItemCount() {
if (listBeans != null){
return listBeans.size();
}
return 0;
}
}
class SecondMyAdapter extends RecyclerView.ViewHolder{
private SimpleDraweeView img;
private TextView textView;
public SecondMyAdapter(View itemView) {
super(itemView);
img = itemView.findViewById(R.id.fragment02_right_img);
textView = itemView.findViewById(R.id.fragment02_right_tv02);
}
}
}