Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstancesState){
super.onCreate(savedInstancesState);
setContentView(R.layout.activity_main);

Button Boton = findViewById(R.id.boton);


Boton.setOnClickListener(new View.OnClickListener() {
EditText usuario_email = findViewById(R.id.usuario1);
EditText usuario_password = findViewById(R.id.password1);
HttpLoggingInterceptor loggin = new HttpLoggingInterceptor();
@Override
public void onClick(View v) {
String email=usuario_email.getText().toString();
String password=usuario_password.getText().toString();

loggin .setLevel(HttpLoggingInterceptor.Level.BODY);

OkHttpClient.Builder httpClient=new OkHttpClient.Builder();


httpClient.addInterceptor(loggin);

Retrofit retrofit = new Retrofit.Builder()

.baseUrl("http://192.168.0.9:9095/api/Login/IniciodeSesion/")
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
ApiUsuario login = retrofit.create(ApiUsuario.class);
Call<Usuario> call = login.LOGIN_CALL(email,password);
call.enqueue(new Callback<Usuario>() {
@Override
public void onResponse(Call<Usuario> call, Response<Usuario>
response) {
if (response.isSuccessful() && response.body() !=null){
usuario_email.getText().clear();
usuario_password.getText().clear();

Intent intent = new Intent(MainActivity.this,


menudeusuarios.class);
startActivity(intent);
Toast.makeText(MainActivity.this, "Bienvenido",
Toast.LENGTH_SHORT).show();

} else if (response.code()==401) {
Toast.makeText(MainActivity.this,"Valida tu
Correo",Toast.LENGTH_SHORT).show();

}else {
Toast.makeText(MainActivity.this,"Error de
Credenciaes",Toast.LENGTH_SHORT).show();
}
}

@Override
public void onFailure(Call<Usuario> call, Throwable throwable)
{
Toast.makeText(MainActivity.this, "Ocurrio un Error Vuelve
a Intentarlo",Toast.LENGTH_SHORT).show();
}
});

}
});
}

You might also like