xbanner

public class Frag01 extends Fragment implements MainView {

private XBanner banner;
private List list;
private List list1 = new ArrayList<>();
private List list2 = new ArrayList<>();
private List list3 = new ArrayList<>();
private RecyclerView xrea1;
private XRecyclerView xrea2;
private XRecyclerView xrea3;
private MainPre mainPre;
private YiAdapter yiAdapter;
private ErAdapter erAdapter;
private SanAdapter sanAdapter;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.frag01, container, false);
    banner = view.findViewById(R.id.xbanner);
    xrea1 = view.findViewById(R.id.xrea1);
    xrea2 = view.findViewById(R.id.xrea2);
    xrea3 = view.findViewById(R.id.xrea3);
    return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    list = new ArrayList<>();
    list.add(new NewBean("http://172.17.8.100/images/small/banner/cj.png"));
    list.add(new NewBean("http://172.17.8.100/images/small/banner/hzp.png"));
    list.add(new NewBean("http://172.17.8.100/images/small/banner/lyq.png"));
    list.add(new NewBean("http://172.17.8.100/images/small/banner/px.png"));
    list.add(new NewBean("http://172.17.8.100/images/small/banner/wy.png"));
    banner.setBannerData(list);
    banner.loadImage(new XBanner.XBannerAdapter() {
        @Override
        public void loadBanner(XBanner banner, Object model, View view, int position) {
            NewBean model1 = (NewBean) model;
            Glide.with(getActivity()).load(model1.getAa()).apply(RequestOptions.bitmapTransform(new RoundedCorners(30))).into((ImageView) view);
        }
    });
    banner.startAutoPlay();
    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    xrea1.setLayoutManager(layoutManager);
    LinearLayoutManager manager = new LinearLayoutManager(getActivity());
    manager.setOrientation(LinearLayoutManager.VERTICAL);
    xrea2.setLayoutManager(manager);
    GridLayoutManager gridLayoutManager= new GridLayoutManager(getActivity(),2);
    xrea3.setLayoutManager(gridLayoutManager);
    yiAdapter = new YiAdapter(getActivity());
    xrea1.setAdapter(yiAdapter);
    erAdapter = new ErAdapter(getActivity());
    xrea2.setAdapter(erAdapter);
    sanAdapter = new SanAdapter(getActivity());
    xrea3.setAdapter(sanAdapter);

   mainPre = new MainPre(new MainModels(),this);
   mainPre.doUrls(1);
}

@Override
public void success(int type, String data) {
    JsonBean jsonBean = new Gson().fromJson(data, JsonBean.class);
    Three result = jsonBean.getResult();
  list1 = result.getMlss().getCommodityList();
  list2 = result.getPzsh().getCommodityList();
  list3 = result.getRxxp().getCommodityList();
    yiAdapter.setData(list1);
    erAdapter.setData(list2);
    sanAdapter.setData(list3);
}

@Override
public void fail() {

}

}

public class YiAdapter extends RecyclerView.Adapter {
private List list1 = new ArrayList<>();
private Context context;

public YiAdapter(Context context) {
    this.context = context;
}

@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = View.inflate(context, R.layout.item01, null);
    MyViewHolder viewHolder = new MyViewHolder(view);
    return viewHolder;
}

@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
    String commodityName = list1.get(i).getCommodityName();
    String masterPic = list1.get(i).getMasterPic();
    String price = list1.get(i).getPrice();
    myViewHolder.text1.setText(commodityName);
    myViewHolder.te_pic.setText("¥"+price+"");
    Glide.with(context).load(masterPic).into(myViewHolder.img);
}

@Override
public int getItemCount() {
    return list1.size();
}
public void setData(List list1){
    this.list1=list1;
}
public class MyViewHolder extends RecyclerView.ViewHolder {

    private final ImageView img;
    private final TextView te_pic;
    private final TextView text1;

    public MyViewHolder(@NonNull View itemView) {
        super(itemView);
        img = itemView.findViewById(R.id.img_v1);
        text1 = itemView.findViewById(R.id.text1);
        te_pic = itemView.findViewById(R.id.te_pic);
    }
}

}
------------------------------model接口------------------------------------------------------
public interface MainModel {
interface CallBacko{
void success(int type,String data);
void fail();
}
void getUrls(int type,CallBacko callBacko);
}
------------------------------mode类------------------------------------------------------
public class MainModels implements MainModel{
@Override
public void getUrls(int type, final CallBacko callBacko) {
new OKHttpUtils().get(“http://172.17.8.100/small/commodity/v1/commodityList”).result(new OKHttpUtils.HttpLister() {
@Override
public void success(String data) {
callBacko.success(1,data);
}

        @Override
        public void fail() {
            callBacko.fail();
        }
    });
}

}
------------------------------presenter接口------------------------------------------------------
public interface MainPresenter {
void doUrls(int type);
}
------------------------------presenter类------------------------------------------------------
public class MainPre implements MainPresenter, MainModel.CallBacko {
private MainModels mainModels;
private MainView mainView;

public MainPre(MainModels mainModels, MainView mainView) {
    this.mainModels = mainModels;
    this.mainView = mainView;
}

@Override
public void doUrls(int type) {
    mainModels.getUrls(1,this);
}

@Override
public void success(int type, String data) {
    mainView.success(type,data);
}

@Override
public void fail() {
    mainView.fail();
}

}
------------------------------view接口------------------------------------------------------
public interface MainView {
void success(int type,String data);
void fail();
}
------------------------------item1------------------------------------------------------








------------------------------item2------------------------------------------------------





------------------------------item3------------------------------------------------------

你可能感兴趣的:(xbanner)