Advertisement
Guest User

name-update-api-call

a guest
Sep 22nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. private void updateUserDisplayName(final String displayName, final AlertDialog alertDialog){
  2.  
  3.         String fullUrl = CommonUtil.BASE_URL+"user/update";
  4.         final StringRequest request = new StringRequest(Request.Method.POST, fullUrl,
  5.                 new Response.Listener<String>() {
  6.                     @Override
  7.                     public void onResponse(String response) {
  8.                         UserDetailsUpdateResponse responsePojo = new Gson().fromJson(response, UserDetailsUpdateResponse.class);
  9.  
  10.                         if (responsePojo != null && responsePojo.getStatus().equalsIgnoreCase("success")) {
  11.                             Toast.makeText(ChitChatActivity.this, "Success", Toast.LENGTH_SHORT).show();
  12.                             storeData.setData(ChitChatActivity.this, StoreData.USER_NAME, displayName);
  13.                             alertDialog.dismiss();
  14.                         } else
  15.                             Toast.makeText(ChitChatActivity.this, "Name update failed", Toast.LENGTH_SHORT).show();
  16.                     }
  17.                 },
  18.                 new Response.ErrorListener() {
  19.                     @Override
  20.                     public void onErrorResponse(VolleyError error) {
  21.                         Toast.makeText(ChitChatActivity.this, error.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
  22.                     }
  23.                 }
  24.         )
  25.         {
  26.             @Override
  27.             public Map<String, String> getHeaders() throws AuthFailureError {
  28.                 return CommonUtil.getHeaderInfo(ChitChatActivity.this);
  29.             }
  30.  
  31.             @Override
  32.             public byte[] getBody() throws AuthFailureError {
  33.                 try {
  34.                     JSONObject jsonObject = new JSONObject();
  35.                     jsonObject.put("displayName", displayName);
  36.                     return jsonObject.toString().getBytes();
  37.                 } catch (Exception e) {
  38.                     e.printStackTrace();
  39.                     return new byte[0];
  40.                 }
  41.             }
  42.  
  43.             public String getBodyContentType() {
  44.                 return "application/json";
  45.             }
  46.         };
  47.         RequestQueue queue = Volley.newRequestQueue(this);
  48.         queue.add(request);
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement