美文网首页
MVP+Retrofit+dagger2+RxAndroid框架

MVP+Retrofit+dagger2+RxAndroid框架

作者: 湫兮若风__流年 | 来源:发表于2018-12-21 10:35 被阅读0次
  1. MVP模式:主要实在传统的MVC模式上新增了一层presenter,作为View与Model交互的中间纽带,处理与用户交互的负责逻辑。

  2. Retrofit:是Square公司开发的一款针对Android网络请求的框架,Retrofit2底层基于OkHttp实现的。

  3. dagger2:简而言之就是一套Android上使用的依赖注入框架。

  4. RxAndroid:RxJava的Android版,是一套实现异步的框架。

  5. lambd表达式:用来代替匿名的内部类,让代码变的简单、而且可读、最重要的是代码量也随之减少很多。

  6. icepick:对activity以及fragment 的状态的保存和恢复。
    原始保存/恢复数据的写法:

onCreate: 
if(savedInstanceState!=null)
mCodeData=savedInstanceState.getInt("code");

@Override protected void onSaveInstanceState(Bundle outState) {
 outState.putInt("code",mCodeData); super.onSaveInstanceState(outState);
}

icepick: 
Icepick.restoreInstanceState(this, savedInstanceState);
@Override protected void onSaveInstanceState(Bundle outState) {                   
   Icepick.saveInstanceState(this, outState); 
   super.onSaveInstanceState(outState); 
}
  1. butterknife:这个开源库可以让我们从大量的findViewById()和setonclicktListener()解放出来,并且使用Android Butterknife Zelezny插件可以快速生成XML文件的各种控件对应java代码。
    首先,你需要在OnCreate初始化方法中先绑定布局文件:
OnCreate(): 
ButterKnife.bind(this); //绑定布局文件
@bindView(R.id.text1)TextView text1; //绑定需要操作的控件
@OnClick({R.id.button1, R.id.button2, R.id.button3})  //设置事件
public void onClick(View view) { switch (view.getId()) { 
    case R.id.button1: break; 
    case R.id.button2: break; 
    case R.id.button3: break;
 }}
  1. 我们需要对这套框架进行配置;

相关文章

网友评论

      本文标题:MVP+Retrofit+dagger2+RxAndroid框架

      本文链接:https://www.haomeiwen.com/subject/qlfmkqtx.html