google Android Architecture Blueprints学习
参考资料:
https://developer.android.google.cn/topic/libraries/architecture
1、todo-mvp
一个便签的demo,
类图:
核心:
1、View:
将对于view的操作封装成具体的接口,Activity或者Fragment来实现这些接口
public interface AddEditTaskContract {
interface View extends BaseView<Presenter> {
void showEmptyTaskError();
void showTasksList();
void setTitle(String title);
void setDescription(String description);
boolean isActive();
}
...
}
public class AddEditTaskFragment extends Fragment implements AddEditTaskContract.View {
...
}
持有Present接口(具体各个业务的Present对象),将界面对于数据的操作转接给Present层(比如保存编辑的数据),可以将原本Fragment繁重的数据操作逻辑转交给Present层实现
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPresenter.saveTask(mTitle.getText().toString(), mDescription.getText().toString());
}
});
2、Model:
本地数据库采用了Room库,
参考资料:https://developer.android.com/training/data-storage/room
TasksRepository:管理数据的读取或者是保存,给present层提供Task控制接口
3、Present:
public interface AddEditTaskContract {
...
interface Presenter extends BasePresenter {
void saveTask(String title, String description);
void populateTask();
boolean isDataMissing();
}
}
public class AddEditTaskPresenter implements AddEditTaskContract.Presenter,
TasksDataSource.GetTaskCallback {
...
}
持有View相关接口(Fragment对象),通过View接口更新界面元素
2、todo-mvvm-databinding
待续。。。