添加到购物车的model层
/**
* 添加购物车的model层
*
* */
public class AddShopCarModel {
public void receive(String source, String uid, String pid, final IAddShopCarModel iAddShopCarModel) {
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("uid",uid);
hashMap.put("pid",pid);
OkHttpUtils.getInstance().doPost("http://120.27.23.105/product/addCart", hashMap, new CallBack() {
@Override
public void onSuccess(String str) {
if(str!=null){
AddShopCarBean addShopCarBean = GsonUtils.getInstance().fromJson(str, AddShopCarBean.class);
if(addShopCarBean!=null){
String msg = addShopCarBean.getMsg();
iAddShopCarModel.onSuccess(msg);
}
}
}
@Override
public void onFailed(String message) {
iAddShopCarModel.onFailed();
}
});
}
}
添加购物车presenter层
public class AddShopCarPresenter implements IAddShopCarModel {
private AddShopCarModel addShopCarModel;
private IAddShopCarPresenter iAddShopCarPresenter;
public AddShopCarPresenter(IAddShopCarPresenter iAddShopCarPresenter) {
this.iAddShopCarPresenter = iAddShopCarPresenter;
addShopCarModel = new AddShopCarModel();
}
public void receive(String source, String uid, String pid) {
addShopCarModel.receive(source,uid,pid,this);
}
@Override
public void onSuccess(String msg) {
iAddShopCarPresenter.onSuccess(msg);
}
@Override
public void onFailed() {
iAddShopCarPresenter.onFailed();
}
}
model层的接口
public interface IAddShopCarModel {
void onSuccess(String msg);
void onFailed();
}
presenter层的接口
public interface IAddShopCarPresenter {
void onSuccess(String msg);
void onFailed();
}
联系到了view层:RecyclerDetailsActivity:
http://blog.csdn.net/qq_40087961/article/details/78859070