首页展示之轮播图
加权限
依赖包
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 staticfinal String URL="https://www.zhaoapi.cn/"; public staticfinal String URL1="https://app.tuozhe8.com/"; }
---------------------------------------------------------------------------------------------------------
apiservice
public interface APiService {@GET("quarter/getAd") Flowable getSlideview(); @GET("api/Lists/designer?token=&version=1.7") FlowablegetDesignview(); @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(); returnretrofit; } }
-------------------------------------------------------------------------------------------------------------
【首页展示之轮播图】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; idisplay = 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 = https://www.it610.com/article/listBean.getData(); ListAdapter adapter = new ListAdapter(this); adapter.addData(data); list_recycler.setLayoutManager(new LinearLayoutManager(this)); list_recycler.setAdapter(adapter); } }
推荐阅读
- 广角叙述|广角叙述 展众生群像——试析鲁迅《示众》的展示艺术
- 工具|后天就是七夕节,你准备好了吗(送上几个七夕代码,展示你技能的时候到了!)
- 界面展示bug随笔
- 学生优秀作文展示(羽毛球的魅力)
- 关于展示网络GIF(基于FLAnimatedImageView)
- Axure|Axure 教程(PC 端电商首页商品分类)
- 文献笔记六十六(可视化展示blast结果的网页工具Kablammo)
- 神经网络绘图工具汇总
- 【钊妈生活手记42】妈妈,我的目标是尝试去展示自己,投票不重要
- 基于百度脑图的用例增量保存 + diff 展示整体设计