首页展示之轮播图

加权限

依赖包

compile 'io.reactivex.rxjava2:rxjava:2.0.0-RC3'
compile 'io.reactivex.rxjava2:rxandroid:2.0.0-RC1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.retrofit2:adapter-rxjava2:+'

compile 'com.youth.banner:banner:1.4.10'
implementation 'com.facebook.fresco:fresco:1.5.0'
compile 'com.github.bumptech.glide:glide:4.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'

api

public class APi {

    public static  final String URL="https://www.zhaoapi.cn/";
    public static  final String URL1="https://app.tuozhe8.com/";
}

---------------------------------------------------------------------------------------------------------

apiservice

public interface APiService {

    @GET("quarter/getAd")
    Flowable getSlideview();

    @GET("api/Lists/designer?token=&version=1.7")
    Flowable getDesignview();

    @GET("product/getCatagory")
    Flowable getListview();
}

 

------------------------------------------------------------------------------------------

application

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
    }
}

--------------------------------------------------------------------------------------------------------------------

retrofitutils

public class RetrofitUtils {

    //retrofitutils
     public static RetrofitUtils retrofitUtils;
          public static RetrofitUtils getinstence(){
              if (retrofitUtils==null){
                  synchronized (RetrofitUtils.class){
                      if(retrofitUtils==null){
                          retrofitUtils= new RetrofitUtils();
                      }
                  }

              }
              return retrofitUtils;
          }
          public OkHttpClient getClient(){
              HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
                  @Override
                  public void log(String message) {
                      Log.i("xxx", "日志信息:" + message);
                  }
              });
              interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
              OkHttpClient client = new OkHttpClient.Builder()
                      .addInterceptor(interceptor)
                      .connectTimeout(5000, TimeUnit.SECONDS)
                      .writeTimeout(5000, TimeUnit.SECONDS)
                      .readTimeout(5000, TimeUnit.SECONDS)
                      .build();
              return client;

          }
        public Retrofit getUrl(String URL){
            Retrofit retrofit = new Retrofit.Builder().baseUrl(URL).client(getClient()).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();
            return  retrofit;
        }
}

-------------------------------------------------------------------------------------------------------------

inter

public interface DesignListener {
    void OnSetDesign(DesignBean designBean);
}

--------------------------------------------------------------------------------------------------------

myloader

public class MyLoader extends ImageLoader {
    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {
        Glide.with(context).load(path).into(imageView);
    }
}

--------------------------------------------------------------------------------------------------

model

public interface ISildeModel {
    void getSildeData(SetListener setListener);
    void getDesignData(DesignListener designListener);
    void getListData(ListListener listListener);
}
public class SildeModel implements ISildeModel {

    @Override
    public void getSildeData(final SetListener setListener) {
        RetrofitUtils.getinstence().getUrl(APi.URL).create(APiService.class)
                .getSlideview()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new DisposableSubscriber() {
                    @Override
                    public void onNext(SlideBean slideBean) {
                        setListener.OnSetInter(slideBean);
                    }

                    @Override
                    public void onError(Throwable t) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    @Override
    public void getDesignData(final DesignListener designListener) {
        RetrofitUtils.getinstence().getUrl(APi.URL1).create(APiService.class)
                .getDesignview()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new DisposableSubscriber() {

                    @Override
                    public void onNext(DesignBean designBean) {
                        designListener.OnSetDesign(designBean);
                    }


                    @Override
                    public void onError(Throwable t) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });


    }

    @Override
    public void getListData(final ListListener listListener) {

        RetrofitUtils.getinstence().getUrl(APi.URL).create(APiService.class)
                .getListview()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new DisposableSubscriber() {


                    @Override
                    public void onNext(ListBean listBean) {
                        listListener.OnSetList(listBean);
                    }

                    @Override
                    public void onError(Throwable t) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}

---------------------------------------------------------------------------------------------------------

presenter

public interface ISildePresenter {
    void getData();
}
public class SildePresenter implements ISildePresenter{

    SildeModel sildeModel;
    ISildeView iSildeView;

    public SildePresenter(ISildeView iSildeView) {
        sildeModel =new SildeModel();
       this.iSildeView = iSildeView;
    }

    @Override
    public void getData() {
        sildeModel.getSildeData(new SetListener() {
            @Override
            public void OnSetInter(SlideBean slideBean) {
                iSildeView.SildeData(slideBean);
            }
        });
        sildeModel.getDesignData(new DesignListener() {
            @Override
            public void OnSetDesign(DesignBean designBean) {
                iSildeView.DesignData(designBean);
            }
        });
        sildeModel.getListData(new ListListener() {
            @Override
            public void OnSetList(ListBean listBean) {
                iSildeView.ListData(listBean);
            }
        });
    }
}

---------------------------------------------------------------------------------------------------------

view

public interface ISildeView {

    void SildeData(SlideBean slideBean);
    void DesignData(DesignBean designBean);
    void ListData(ListBean listBean);
}

-----------------------------------------------------------------------------------------------------

mainactivity

public class MainActivity extends AppCompatActivity implements ISildeView{


    private SildePresenter sildePresenter;
    private Banner banner;
    private Listlist =new ArrayList<>();
    private RecyclerView design_recycler,list_recycler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        //获取资源ID
        banner =findViewById(R.id.banner);
        design_recycler= findViewById(R.id.design_recycler);
        list_recycler= findViewById(R.id.listrecycler);
        sildePresenter = new SildePresenter(this);
        sildePresenter.getData();
    }


    @Override
    public void SildeData(SlideBean slideBean) {

        final List lists = slideBean.getData();
        for (int i = 0;i display = designBean.getData().getDisplay();
        DesignAdapter adapter = new DesignAdapter(this);
        adapter.addData(display);
        design_recycler.setLayoutManager(new GridLayoutManager(this,1, OrientationHelper.HORIZONTAL,false));
        design_recycler.setAdapter(adapter);

    }

    @Override
    public void ListData(ListBean listBean) {
        List data = listBean.getData();
        ListAdapter adapter = new ListAdapter(this);
        adapter.addData(data);
        list_recycler.setLayoutManager(new LinearLayoutManager(this));
        list_recycler.setAdapter(adapter);

    }
}

 

 

 

 

你可能感兴趣的:(首页展示之轮播图)