//We show the loader and hide the form
private void attemptLogin() {
        // Reset errors.
        mEmailView.setError(null);
        mPasswordView.setError(null);
        // Store values at the time of the login attempt.
        final String email = mEmailView.getText().toString();
        final String password = mPasswordView.getText().toString();
        boolean cancel = false;
        View focusView = null;
        // Check for a valid password.
        if (TextUtils.isEmpty(password)) {
            mPasswordView.setError(getString(R.string.error_field_required));
            focusView = mPasswordView;
            cancel = true;
        }
        // Check for a valid email address.
        if (TextUtils.isEmpty(email)) {
            mEmailView.setError(getString(R.string.error_field_required));
            focusView = mEmailView;
            cancel = true;
        }
        if (cancel) {
            // There was an error; don't attempt login and focus the first
            // form field with an error.
            focusView.requestFocus();
        } else {
            //We show the loader and hide the form
            showHideView(mProgressView, mLoginFormView, true);
            //We set the response listener with corresponding overridden methods
            AppResponseListener<JSONObject> responseListener = new AppResponseListener<JSONObject>(getApplicationContext()){
                @Override
                public void onResponse(JSONObject response) {
                    Context context = getApplicationContext();
                    String firstName = null;
                    String lastName = null;
                    try {
                        firstName = response.getString(UserRequestManager.FIRST_NAME);
                        lastName = response.getString(UserRequestManager.LAST_NAME);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    //TODO: Use method UserManager.logInUser loading user from database
                    PrefsManager.saveUserCredentials(context, email, password);
                    PrefsManager.setStringPref(context, PrefsManager.PREF_USER_FIRST_NAME, firstName);
                    PrefsManager.setStringPref(context, PrefsManager.PREF_USER_LAST_NAME, lastName);
                    startActivityClosingAllOthers(DrawerActivity.class);
                    onPostResponse();
                }
                @Override
                public void onUnauthorizedError(VolleyError error) {
                    showToast(R.string.error_wrong_credentials);
                }
                @Override
                public void onPostResponse(){
                    showHideView(mLoginFormView, mProgressView, true);
                }
            };
            //We add the request
            JsonObjectRequest request = UserRequestManager.userLogInRequest(email, password, responseListener);
            VolleyManager.getInstance(getApplicationContext()).addToRequestQueue(request);
        }
    }
focusView.requestFocus();
} else {
//We show the loader and hide the form
showHideView(mProgressView, mLoginFormView, true);
//We set the response listener with corresponding overridden methods
if (TextUtils.isEmpty(email)) {
mEmailView.setError(getString(R.string.error_field_required));
focusView = mEmailView;
cancel = true;
}
if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
} else {
//We show the loader and hide the form
showHideView(mProgressView, mLoginFormView, true);
//We set the response listener with corresponding overridden methods
AppResponseListener<JSONObject> responseListener = new AppResponseListener<JSONObject>(getApplicationContext()){
@Override
public void onResponse(JSONObject response) {
Context context = getApplicationContext();
String firstName = null;
String lastName = null;
try {
firstName = response.getString(UserRequestManager.FIRST_NAME);
final String password = mPasswordView.getText().toString();
boolean cancel = false;
View focusView = null;
// Check for a valid password.
if (TextUtils.isEmpty(password)) {
mPasswordView.setError(getString(R.string.error_field_required));
focusView = mPasswordView;
cancel = true;
}
// Check for a valid email address.
if (TextUtils.isEmpty(email)) {
mEmailView.setError(getString(R.string.error_field_required));
focusView = mEmailView;
cancel = true;
}
if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
} else {
//We show the loader and hide the form
showHideView(mProgressView, mLoginFormView, true);
//We set the response listener with corresponding overridden methods
AppResponseListener<JSONObject> responseListener = new AppResponseListener<JSONObject>(getApplicationContext()){
@Override
public void onResponse(JSONObject response) {
Context context = getApplicationContext();
String firstName = null;
String lastName = null;
try {
firstName = response.getString(UserRequestManager.FIRST_NAME);
lastName = response.getString(UserRequestManager.LAST_NAME);
} catch (JSONException e) {
e.printStackTrace();
}
//TODO: Use method UserManager.logInUser loading user from database
PrefsManager.saveUserCredentials(context, email, password);
PrefsManager.setStringPref(context, PrefsManager.PREF_USER_FIRST_NAME, firstName);
PrefsManager.setStringPref(context, PrefsManager.PREF_USER_LAST_NAME, lastName);
startActivityClosingAllOthers(DrawerActivity.class);
onPostResponse();