Search in sources :

Example 1 with VolleyRequestHandle

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);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) User(com.shizhefei.test.models.enties.User) VolleyRequestHandle(com.shizhefei.test.models.datasource.volley.VolleyRequestHandle) StringRequest(com.android.volley.toolbox.StringRequest) BizException(com.shizhefei.test.models.exception.BizException) Uri(android.net.Uri)

Aggregations

Uri (android.net.Uri)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 StringRequest (com.android.volley.toolbox.StringRequest)1 VolleyRequestHandle (com.shizhefei.test.models.datasource.volley.VolleyRequestHandle)1 User (com.shizhefei.test.models.enties.User)1 BizException (com.shizhefei.test.models.exception.BizException)1