优雅的Android MVP开发框架 ———— FDroid
-
网络请求
:基于RxJava+Retrofit+Gson+FDroid的封装,支持对网络请求结果的统一处理、请求结果回调到UI线程、自动判断网络连接状态、自动管理生命周期、模拟后台返回数据、自定义请求头、请求响应日志打印、每个阶段都可扩展等。 -
MVP模式
:利用泛型深度解耦,为项目省掉一半代码;您不需要知道MVP实现细节,轻松使用MVP进行项目开发; -
模板开发
:无需编写MVP的各层代码,利用Android Studio Template一键生成具有View+Contract+Presenter的Activity。模板下载:FDActivity.zip -
强大的控制层
:进行网络请求时,显隐等待对话框;使用FastTask类轻松进行耗时操作,自动回调到UI线程; -
有用的FDFragment
:支持缓存rootView,防止重复加载布局;拥有是否对用户可见的操作; -
L/T/SP类
:对Log、Toast和SharedP进行的有趣封装;Log支持显示打印的位置;全局管理log和Toast的显隐; -
丰富的工具
:RxBus、FastTask、SyncFun、AsyncLayoutInflaterPlus、FDLoadingDialog等。
allprojects {
repositories {
//...
maven { url 'https://jitpack.io' }
}
}
dependencies {
// 基于AndroidX版本
api 'com.github.feimenggo:fdroid:4.0.4'
// 非AndroidX版本(不再维护)
api 'com.github.feimenggo:fdroid:3.3.1'
}
public class BaseApp extends FDApp {
@Override
protected void config() {
// 此处可以进行您项目其它库的初始化
}
}
public abstract class BaseActivity<V extends FDView, P extends FDPresenter<V>> extends FDActivity<V, P> {
}
public abstract class BaseFragment<V extends FDView, P extends FDPresenter<V>> extends FDFragment<V, P> {
}
public interface TestContract {
interface View extends FDView {
void getUserName(String username);
}
abstract class Presenter extends FDPresenter<View> {
public abstract void getUserName();
}
}
public class TestPresenter extends TestContract.Presenter {
@Override
public void getUserName() {
// 步骤二
// 这里进行具体的业务
// ...
// 简单模拟获取到的用户名是“小飞”
String username = "小飞";
// 回调结果给View层
mView.getUserName(username);
}
}
public class TestActivity extends FDActivity<TestContract.View, TestContract.Presenter> implements TestContract.View {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
// 步骤一
// 调用Presenter层,获取用户名
mPresenter.getUserName();
}
@Override
protected TestContract.Presenter initPresenter() {
return new TestPresenter();
}
@Override
public void getUserName(String username) {
// 步骤三
// 显示获取的用户名
Toast.makeText(this, "用户名是" + username, Toast.LENGTH_SHORT).show();
}
}
FDActivity模板:FDActivity.zip
Copyright 2017 feimeng
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.