public class HomeFragment extends Fragment implements IShowView {
private RecyclerView recycle;
private HomeAdapter homeadapter;
// private List list =new ArrayList<>();
private List<Data.ResultBean.RxxpBean.CommodityListBean> rxxplist;
private List<Data.ResultBean.MlssBean.CommodityListBeanXX> mlsslist;
private List<Data.ResultBean.PzshBean.CommodityListBeanX> pzshlist;
// private Data data;
private HomePersenter homePersenter;
private XBanner banner;
ArrayList images;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.home_fragment,container,false);
recycle = view.findViewById(R.id.recycle);
banner = view.findViewById(R.id.banner);
homePersenter = new HomePersenter(this);
homePersenter.requestShow();
images = new ArrayList<>();
images.add("http://172.17.8.100/images/small/banner/cj.png");
images.add("http://172.17.8.100/images/small/banner/hzp.png");
images.add("http://172.17.8.100/images/small/banner/lyq.png");
images.add("http://172.17.8.100/images/small/banner/px.png");
banner.setData(images,null);
banner.setmAdapter(new XBanner.XBannerAdapter() {
@Override
public void loadBanner(XBanner banner, View view, int position) {
Glide.with(getActivity()).load(images.get(position)).into((ImageView) view);
}
});
//设置XBanner的页面切换特效,选择一个即可,总的大概就这么多效果啦,欢迎使用
banner.setPageTransformer(Transformer.Default);//横向移动
// 设置XBanner页面切换的时间,即动画时长
banner.setPageChangeDuration(1000);
return view;
}
@Override
public void success(Data data, Object... args) {
rxxplist = data.getResult().getRxxp().getCommodityList();
mlsslist = data.getResult().getMlss().getCommodityList();
pzshlist = data.getResult().getPzsh().getCommodityList();
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recycle.setLayoutManager(linearLayoutManager);
homeadapter = new HomeAdapter(getActivity(), data);
homeadapter.setData(rxxplist,mlsslist,pzshlist);
homeadapter.notifyDataSetChanged();
recycle.setAdapter(homeadapter);
}
@Override
public void onResume() {
super.onResume();
banner.startAutoPlay();
}
@Override
public void onStop() {
super.onStop();
banner.stopAutoPlay();
}
}