Skip to content

Instantly share code, notes, and snippets.

@LTroya

LTroya/Retrofit

Created Dec 3, 2016
Embed
What would you like to do?
// Registro
@Override
public void onValidationSucceeded() {
// Toast.makeText(SignUpActivty.this, "Todas las validaciones fueron resueltas", Toast.LENGTH_SHORT).show();
SignUp signUp = new SignUp(
inputName.getText().toString(),
inputJob.getText().toString(),
inputEmail.getText().toString(),
inputUsername.getText().toString(),
Utilities.md5(inputPassword.getText().toString()),
"" + inputSex.getText().toString().charAt(0),
inputBirthday.getText().toString(),
inputCountry.getText().toString(),
Integer.parseInt(currentIndustry.getIndustryId()),
"PERSONA_INFLUYENTE",
Collections.<Interest>emptyList(),
null,
null
);
String contentType = "application/json";
progressDialog.show();
Observable<Response<SignIn>> call = bCardAPI.addUser(contentType, signUp);
subscription = call
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Response<SignIn>>() {
@Override
public void onCompleted() {
Log.d("onCompleted", "On completed");
}
@Override
public void onError(Throwable e) {
progressDialog.dismiss();
Toast.makeText(SignUpActivty.this, getString(R.string.toast_server_error), Toast.LENGTH_LONG).show();
}
@Override
public void onNext(Response<SignIn> signInResponse) {
String statusCode = signInResponse.body().getCode();
if (statusCode == null) {
sendWelcomeEmail(signInResponse.body());
} else {
switch (statusCode) {
case INTERNAL_SERVER_ERROR:
Toast.makeText(SignUpActivty.this, getString(R.string.toast_internal_server_error), Toast.LENGTH_LONG).show();
progressDialog.dismiss();
break;
case SERVER_VALIDATION_EMAIL_ERROR:
Toast.makeText(SignUpActivty.this, getString(R.string.toast_server_email_exists_error), Toast.LENGTH_LONG).show();
if (!inputEmail.requestFocus()) {
inputEmail.setSelection(inputEmail.getText().length());
}
progressDialog.dismiss();
break;
case SERVER_VALIDATION_USER_NOT_COMPLETED_ERROR:
Toast.makeText(SignUpActivty.this, getString(R.string.toast_server_name_not_completed_error), Toast.LENGTH_LONG).show();
if (!inputName.requestFocus()) {
inputName.setSelection(inputName.getText().length());
}
progressDialog.dismiss();
case SERVER_VALIDATION_USER_ERROR:
Toast.makeText(SignUpActivty.this, getString(R.string.toast_server_user_exists_error), Toast.LENGTH_LONG).show();
if (!inputUsername.requestFocus()) {
inputUsername.setSelection(inputUsername.getText().length());
}
progressDialog.dismiss();
break;
default:
Log.d(TAG, "Opción no encontrada");
}
}
}
});
}
// Inicio de sesión
@Override
public void onValidationSucceeded() {
final String username = inputUsername.getText().toString();
final String password = Utilities.md5(inputPassword.getText().toString());
BCardAPI bCardAPI = ServiceGenerator.createService(BCardAPI.class);
progressDialog.show();
Observable<Response<SignIn>> call = bCardAPI.getUser(username, password);
subscription = call
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Response<SignIn>>() {
@Override
public void onCompleted() {
Log.d(TAG, "Login completed");
progressDialog.dismiss();
}
@Override
public void onError(Throwable e) {
progressDialog.dismiss();
e.printStackTrace();
Toast.makeText(SignInActivity.this, getString(R.string.toast_server_error), Toast.LENGTH_SHORT).show();
}
@Override
public void onNext(Response<SignIn> signInResponse) {
Utilities.logInfo(TAG, signInResponse.toString());
if (signInResponse.body().getCode() != null && signInResponse.body().getCode().equals("200")) {
alertDialog.show();
} else {
// Guardar la informacion en el SharedPreferences
sessionManager.createLoginSession(username, password, signInResponse.body());
// Redireccionar a la pantalla de home
Intent intent = new Intent(SignInActivity.this, HomeActivity.class);
startActivity(intent);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.