use of com.shizhefei.test.models.datasource.volley.VolleyRequestHandle in project MVCHelper by LuckyJayce.
the class LoginAsyncTask method execute.
@Override
public RequestHandle execute(final ResponseSender<User> sender) throws Exception {
String url = "https://www.baidu.com";
Uri.Builder builder = Uri.parse(url).buildUpon();
builder.appendQueryParameter("userName", name);
builder.appendQueryParameter("password", password);
StringRequest jsonObjRequest = new StringRequest(Request.Method.GET, builder.toString(), new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (TextUtils.isEmpty(name)) {
sender.sendError(new BizException("请输入用户名"));
} else if (TextUtils.isEmpty(password)) {
sender.sendError(new BizException("请输入密码"));
} else if (name.equals("LuckyJayce") && password.equals("111")) {
sender.sendData(new User("1", "LuckyJayce", 23, "中国人"));
} else {
sender.sendError(new BizException("用户名或者密码不正确"));
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
sender.sendError(error);
}
});
MyVolley.getRequestQueue().add(jsonObjRequest);
return new VolleyRequestHandle(jsonObjRequest);
}
Aggregations