在看过吴七禁写的关于android MVP架构系列文章之后,照着文章实现了MVP旗舰版的源码
Github:https://github.com/Cool-Boys/MVPDemo
本Demo是androidx版本,使用了对okhttp3封装请求的okgo,recyclerview刷新插件SmartRefreshLayout,底部导航EasyNavigation,androidx版Butterknife。
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
implementation 'com.squareup.okhttp3:okhttp:3.8.1'
implementation 'com.squareup.okio:okio:1.13.0'
implementation 'com.lzy.net:okgo:3.0.4'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.mcxiaoke.volley:library:1.0.19'
implementation 'com.github.forvv231:EasyNavigation:1.0.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
//1.1.0 androidx 版本
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-andx-4'
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-andx-4'
implementation 'androidx.cardview:cardview:1.0.0'
}
在引入butterknife时注意要指定java JDK版本:
android {
...
// Butterknife requires Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
}
在文章的基础上加入了对MvpView接口中采用泛型化定义,以及bean层,使得将请求到的数据通过bean层在view层进行操作使用。
文章通过登录的实现,以及在Fragment中加载数据信息体现MVP在开发中的实际运用。


