use of com.ferg.awfulapp.task.LoginRequest in project Awful.apk by Awful.
the class AwfulLoginActivity method loginClick.
private void loginClick() {
final String username = NetworkUtils.encodeHtml(mUsername.getText().toString());
final String password = NetworkUtils.encodeHtml(mPassword.getText().toString());
mDialog = ProgressDialog.show(AwfulLoginActivity.this, "Logging In", "Hold on...", true);
final AwfulLoginActivity self = this;
NetworkUtils.queueRequest(new LoginRequest(this, username, password).build(null, new AwfulRequest.AwfulResultCallback<Boolean>() {
@Override
public void success(Boolean result) {
onLoginSuccess();
}
@Override
public void failure(VolleyError error) {
// Volley sometimes generates NetworkErrors with no response set, or wraps them
NetworkResponse response = error.networkResponse;
if (response == null) {
Throwable cause = error.getCause();
if (cause != null && cause instanceof VolleyError) {
response = ((VolleyError) cause).networkResponse;
}
}
if (response != null && response.statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
Boolean result = NetworkUtils.saveLoginCookies(getApplicationContext());
if (result) {
// TODO: this should probably be handled by firing a ProfileRequest and getting the username from there, maybe through SyncManager
AwfulPreferences prefs = AwfulPreferences.getInstance(getApplicationContext());
prefs.setPreference(Keys.USERNAME, username);
onLoginSuccess();
} else {
onLoginFailed();
}
} else {
onLoginFailed();
}
}
private void onLoginSuccess() {
mDialog.dismiss();
Toast.makeText(AwfulLoginActivity.this, R.string.login_succeeded, Toast.LENGTH_SHORT).show();
setResult(Activity.RESULT_OK);
self.finish();
}
private void onLoginFailed() {
mDialog.dismiss();
Toast.makeText(AwfulLoginActivity.this, R.string.login_failed, Toast.LENGTH_SHORT).show();
setResult(Activity.RESULT_CANCELED);
}
}));
}
Aggregations