public class ShowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private ListBean.ResultBean result;
private int bannerType = 0;
private int rxxpType = 1;
private int mlssType = 2;
private int pzshType = 3;
public ShowAdapter(Context context, ListBean.ResultBean result) {
this.context = context;
this.result = result;
}
@Override
public int getItemViewType(int position) {
if (position == 0){
return bannerType;
}else if (position == 1){
return rxxpType;
}else if (position == 2){
return mlssType;
}else {
return pzshType;
}
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
int type = getItemViewType(i);
if (type == bannerType){
View view = LayoutInflater.from(context).inflate(R.layout.banner,viewGroup,false);
return new BannerViewHolder(view);
}else if (type == rxxpType){
View view = LayoutInflater.from(context).inflate(R.layout.rxxp,viewGroup,false);
return new RxxpViewHolder(view);
}else if (type == mlssType){
View view = LayoutInflater.from(context).inflate(R.layout.mlss,viewGroup,false);
return new MlssViewHolder(view);
}else{
View view = LayoutInflater.from(context).inflate(R.layout.pzsh,viewGroup,false);
return new PzshViewHolder(view);
}
}
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, final int i) {
int itemViewType = getItemViewType(i);
if (itemViewType == bannerType){
VolleyHttp.getInstance().VolleyGet(Api.bannerurl, new VolleyHttp.CallBack() {
@Override
public void success(String data) {
BannerBean bannerBean = new Gson().fromJson(data, BannerBean.class);
final List<BannerBean.ResultBean> result = bannerBean.getResult();
ArrayList<String> listbanner = new ArrayList<>();
for (int i=0;i<result.size();i++){
listbanner.add(result.get(i).getImageUrl());
}
final BannerViewHolder bannerViewHolder = (BannerViewHolder) viewHolder;
bannerViewHolder.xbanner.setData(listbanner,null);
bannerViewHolder.xbanner.loadImage(new XBanner.XBannerAdapter() {
@Override
public void loadBanner(XBanner banner, Object model, View view, int position) {
Glide.with(context).load(model).into((ImageView) view);
}
});
bannerViewHolder.xbanner.setPageTransformer(Transformer.Accordion);
bannerViewHolder.xbanner.setPageChangeDuration(1000);
}
@Override
public void fail(VolleyError error) {
}
});
}else if (itemViewType == rxxpType){
final RxxpViewHolder rxxpViewHolder = (RxxpViewHolder) viewHolder;
ListBean.ResultBean.RxxpBean rxxp = result.getRxxp();
rxxpViewHolder.rxxpTvTitle.setText(rxxp.getName());
List<ListBean.ResultBean.RxxpBean.CommodityListBean> commodityList = rxxp.getCommodityList();
RxxpAdapter rxxpAdapter = new RxxpAdapter(context,commodityList);
// rxxpAdapter.setRxxpEvent(new RXXPEvent() {
// @Override
// public void onItemClick(int postion) {
// // context.startActivity();
// }
// });
// new GridLayoutManager(context,3)
LinearLayoutManager rxxplayoutManager = new LinearLayoutManager(context);
rxxplayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
rxxpViewHolder.rxxpRecycler.setLayoutManager(rxxplayoutManager);
rxxpViewHolder.rxxpRecycler.setAdapter(rxxpAdapter);
}else if (itemViewType == mlssType){
MlssViewHolder mlssViewHolder = (MlssViewHolder) viewHolder;
ListBean.ResultBean.MlssBean mlss = result.getMlss();
mlssViewHolder.mlssTvTitle.setText(mlss.getName());
List<ListBean.ResultBean.MlssBean.CommodityListBeanXX> commodityList = mlss.getCommodityList();
MlssAdapter mlssAdapter = new MlssAdapter(context,commodityList);
LinearLayoutManager mlsslayoutManager = new LinearLayoutManager(context);
mlsslayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mlssViewHolder.mlssRecycler.setLayoutManager(mlsslayoutManager);
mlssViewHolder.mlssRecycler.setAdapter(mlssAdapter);
}else {
PzshViewHolder pzshViewHolder = (PzshViewHolder) viewHolder;
ListBean.ResultBean.PzshBean pzsh = result.getPzsh();
pzshViewHolder.pzshTvTitle.setText(pzsh.getName());
List<ListBean.ResultBean.PzshBean.CommodityListBeanX> commodityList = pzsh.getCommodityList();
PzshAdapter pzshAdapter = new PzshAdapter(context,commodityList);
GridLayoutManager gridLayoutManager = new GridLayoutManager(context,2);
pzshViewHolder.pzshRecycler.setLayoutManager(gridLayoutManager);
pzshViewHolder.pzshRecycler.setAdapter(pzshAdapter);
}
}
@Override
public int getItemCount() {
return 4;
}
public class BannerViewHolder extends RecyclerView.ViewHolder {
private XBanner xbanner;
public BannerViewHolder(@NonNull View itemView) {
super(itemView);
xbanner = (XBanner)itemView.findViewById(R.id.xbanner);
}
}
public class RxxpViewHolder extends RecyclerView.ViewHolder {
private TextView rxxpTvTitle;
private RecyclerView rxxpRecycler;
public RxxpViewHolder(@NonNull View itemView) {
super(itemView);
rxxpTvTitle = (TextView)itemView.findViewById(R.id.rxxpTvTitle);
rxxpRecycler = (RecyclerView)itemView.findViewById(R.id.rxxpRecycler);
}
}
public class MlssViewHolder extends RecyclerView.ViewHolder {
private RecyclerView mlssRecycler;
private TextView mlssTvTitle;
public MlssViewHolder(@NonNull View itemView) {
super(itemView);
mlssTvTitle = (TextView)itemView.findViewById(R.id.mlssTvTitle);
mlssRecycler = (RecyclerView)itemView.findViewById(R.id.mlssRecycler);
}
}
public class PzshViewHolder extends RecyclerView.ViewHolder {
private TextView pzshTvTitle;
private RecyclerView pzshRecycler;
public PzshViewHolder(@NonNull View itemView) {
super(itemView);
pzshTvTitle = (TextView)itemView.findViewById(R.id.pzshTvTitle);
pzshRecycler = (RecyclerView)itemView.findViewById(R.id.pzshRecycler);
}
}
}