MVP架构接口开发套路
以下是半mvp,还没用到p
1先model,用来组装入参
public class GetUserTeminalTypeModel {
// 入参中的lat、lng、areaCode、districtCode、distance,这几个字段不传,获取当前身份下所有电站的枪头类型public void getUserTeminalTypeList(RequestListener stringSubscriber) {TeldRequestBean webHelper = new TeldRequestBean();webHelper.setModule(ApiContacts.CLP_GetUserTeminalType);webHelper.setNeedSIDFlag(0);// 0是不需要,1是需要,2是都行webHelper.setMethod(WebHelper.WebMethod.POST);
// param =
//{
// "lng": "string", // 用户经度
// "lat": "string", // 用户纬度
// "companyId": "string", // 企业账户筛选
// "busAccountId": "string", // 企业账户所属公司
// "distance": 0, // 查询距离(米)
// "areaCode":"string", // 区域Code 1 香港岛 2 九龙 3 新界
// "districtCode":"string" // 地区Code 对应StationRegion
//}HashMap<String, String> stringHashMap = new HashMap<>();JSONObject jsonObject = new JSONObject();
// jsonObject.put("lng", lng);
// jsonObject.put("lat", lat);
// jsonObject.put("distance", 100);
// jsonObject.put("areaCode", areaCode);
// jsonObject.put("districtCode", districtCode);Log.e("wy", "isPersonal: "+UserManager.getInstance().isPersonal() );if (UserManager.getInstance().isPersonal()) {jsonObject.put("companyId", "");jsonObject.put("busAccountId", "");} else {String companyId = null;String busAccountId = null;if (p(UserManager.getInstance().getCurrentEnterprise())) {companyId = UserManager.getInstance().getCurrentEnterprise().getAttrCompanyId();busAccountId = UserManager.getInstance().getCurrentEnterprise().getBusUnitId();}jsonObject.put("companyId", companyId);//车队所属公司内码jsonObject.put("busAccountId", busAccountId);//车队内码}try {String encodeStr = JSONObject.toJSONString(jsonObject);
// if (VersionCheckUtils.IS_SHOW_DES_PARAMS) {
// stringHashMap.put("debug", encodeStr);
// }Log.e("wy", "getUserTeminalTypeList: "+encodeStr );stringHashMap.put("param", CDESUtils.desCBCPKCS7Encode(encodeStr));} catch (Exception e) {e.printStackTrace();}webHelper.setRequestParam(stringHashMap);NetWorkUtils.getInstance().sendRequestStrCallBack(webHelper, stringSubscriber);}}
2后写javabean用来承接出参
public class GetUserTeminalTypeBean {/*** data : {"DCGB":false,"ACGB":false,"DCEN":true,"ACEN":true,"DCJIS":false,"ACJIS":false}* errcode :* errmsg :* state : 1* errstack : null* requestid : 56c5ef49-9282-4084-820e-9e9a2841e8ec_07081457_MA*/private DataBean data;private String errcode;private String errmsg;private String state;private Object errstack;private String requestid;public DataBean getData() {return data;}public void setData(DataBean data) {this.data = data;}public String getErrcode() {return errcode;}public void setErrcode(String errcode) {this.errcode = errcode;}public String getErrmsg() {return errmsg;}public void setErrmsg(String errmsg) {this.errmsg = errmsg;}public String getState() {return state;}public void setState(String state) {this.state = state;}public Object getErrstack() {return errstack;}public void setErrstack(Object errstack) {this.errstack = errstack;}public String getRequestid() {return requestid;}public void setRequestid(String requestid) {this.requestid = requestid;}public static class DataBean {/*** DCGB : false* ACGB : false* DCEN : true* ACEN : true* DCJIS : false* ACJIS : false*/private boolean DCGB;private boolean ACGB;private boolean DCEN;private boolean ACEN;private boolean DCJIS;private boolean ACJIS;public boolean isDCGB() {return DCGB;}public void setDCGB(boolean DCGB) {this.DCGB = DCGB;}public boolean isACGB() {return ACGB;}public void setACGB(boolean ACGB) {this.ACGB = ACGB;}public boolean isDCEN() {return DCEN;}public void setDCEN(boolean DCEN) {this.DCEN = DCEN;}public boolean isACEN() {return ACEN;}public void setACEN(boolean ACEN) {this.ACEN = ACEN;}public boolean isDCJIS() {return DCJIS;}public void setDCJIS(boolean DCJIS) {this.DCJIS = DCJIS;}public boolean isACJIS() {return ACJIS;}public void setACJIS(boolean ACJIS) {this.ACJIS = ACJIS;}}
}
3new model使用
new GetUserTeminalTypeModel().getUserTeminalTypeList( new RequestListener() {@Overridepublic void onResponseSuccess(String string) {Log.e("wy", "onResponseSuccess: " + string);GetUserTeminalTypeBean getUserTeminalTypeBean = new Gson().fromJson(string, GetUserTeminalTypeBean.class);GetUserTeminalTypeBean.DataBean data = null;if (null != getUserTeminalTypeBean && null != getUserTeminalTypeBean.getState() && getUserTeminalTypeBean.getState().equals("1")) {data = getUserTeminalTypeBean.getData();}if (data.isACGB()) {gbt_iv.setVisibility(VISIBLE);} else {gbt_iv.setVisibility(INVISIBLE);}if (data.isDCGB()) {type1_iv.setVisibility(VISIBLE);} else {type1_iv.setVisibility(INVISIBLE);}if (data.isACEN()) {type2_iv.setVisibility(VISIBLE);} else {type2_iv.setVisibility(INVISIBLE);}if (data.isDCEN()) {ccs_iv.setVisibility(VISIBLE);} else {ccs_iv.setVisibility(INVISIBLE);}if (data.isACJIS()) {ccs_t1_iv.setVisibility(VISIBLE);} else {ccs_t1_iv.setVisibility(INVISIBLE);}if (data.isDCJIS()) {cha_iv.setVisibility(VISIBLE);} else {cha_iv.setVisibility(INVISIBLE);}}@Overridepublic boolean onResponseError(Throwable throwable) {Log.e("wy", "onResponseError: "+throwable.toString() );return false;}});