首先创建一个契约类(接口)。p层使用抽象类,m层和v层都使用内部接口来实现。
p层
abstract class OnePresenter{
public abstract void getLeftList(HashMap<String,String> params);
public abstract void getRightList(HashMap<String,String> params);
}
M层
public interface OneModel{
void getLeftList(HashMap<String,String> params, model.OneModel.OneModelCallBack oneModelCallBack);
void getRightList(HashMap<String,String> params, model.OneModel.OneModelCallBack oneModelCallBack);
}
v层
public interface OneView{
void leftSuccess(List<LeftBean.Data> leftbeanList);
void rightSuccess(List<RightBean.OneData> rightbeanList);
void leftFailure(String error);
void rightFailure(String error);
}
契约类创建完之后,再使用MVP框架。(开始创建model和presenter)。
model类-----实现契约类的model接口(model接口只有两个方法:getLeft和getRight)
@Override
public void getLeftList(HashMap<String, String> params, final OneModelCallBack oneModelCallBack) {
OKHttpUtils.getmInstance().doPost(ApiUrl.LEFT_URL, params, new OkHttpCallBack() {
@Override
public void failure(String msg) {
if(oneModelCallBack != null){
oneModelCallBack.leftFailure(msg);
}
}
@Override
public void success(String result) {
if(oneModelCallBack != null){
oneModelCallBack.leftSuccess(result);
}
}
});
}
@Override
public void getRightList(HashMap<String, String> params, final OneModelCallBack oneModelCallBack) {
OKHttpUtils.getmInstance().doPost(ApiUrl.RIGHT_URL, params, new OkHttpCallBack() {
@Override
public void failure(String msg) {
if(oneModelCallBack != null){
oneModelCallBack.ri