1
public UserRest login(Usuario usuario, final Context context){
try {
showProgress(context, "Aguarde", "Validando usuário...");
UserService service = ServiceGenerator.createService(UserService.class);
Call<UserRest> call = service.login(usuario.getEmail(),usuario.getSenha());
call.enqueue(new Callback<UserRest>() {
@Override
public void onResponse(Call<UserRest> call, Response<UserRest> response) {
closeProgress();
okhttp3.Response raw = response.raw();
userRest = response.body();
UsuarioDAO usuarioDAO = new UsuarioDAO(context);
Usuario usuario = usuarioDAO.getUsuario();
if (usuario != null && userRest.getId()!=null) {
usuario.setFlagLogado("S");
usuarioDAO.controleLogin(usuario);
context.startActivity(new Intent(context, MenuActivity.class));
}else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Usuário não encontrado", Toast.LENGTH_SHORT).show();
}
}, 500);
}
}
@Override
public void onFailure(Call<UserRest> call, Throwable t) {
closeProgress();
Log.e(ConstantsTrocaae.TAG_LOG, t.getMessage());
Toast.makeText(context, "Usuário não encontrado", Toast.LENGTH_SHORT).show();
}
});
} catch (Exception e) {
Log.e(ConstantsTrocaae.TAG_LOG, e.getMessage());
}finally {
closeProgress();
}
return userRest;
}
Would you like to know why I don’t add my file when I don’t find the user? The weirdest thing about finding it is.
private void showProgress(Context context, String titulo, String mensagem){
progressDialog = new ProgressDialog(context);
progressDialog.show(context, titulo, mensagem);
progressDialog.setCancelable(true);
}
private void closeProgress(){
if(progressDialog!=null && progressDialog.isShowing()){
progressDialog.dismiss();
progressDialog = null;
}
}