Skip to content
Snippets Groups Projects
Commit 600b7e36 authored by Bruno Teixeira's avatar Bruno Teixeira
Browse files

Retrofit example

parent 7cd196e0
No related branches found
No related tags found
No related merge requests found
...@@ -3,23 +3,31 @@ package com.example.mobileapp; ...@@ -3,23 +3,31 @@ package com.example.mobileapp;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import com.example.mobileapp.model.User;
import com.example.mobileapp.networking.RetrofitClient;
import com.example.mobileapp.networking.UserService;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class Start_Screen extends AppCompatActivity { public class Start_Screen extends AppCompatActivity {
private TextInputLayout textInputEmail; private TextInputLayout textInputEmail;
private TextInputLayout textInputPW; private TextInputLayout textInputPW;
private UserService userService;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
userService = RetrofitClient.getRetrofitInstance().create(UserService.class);
textInputEmail = findViewById(R.id.text_input_email); textInputEmail = findViewById(R.id.text_input_email);
textInputPW = findViewById(R.id.text_input_pw); textInputPW = findViewById(R.id.text_input_pw);
...@@ -27,7 +35,6 @@ public class Start_Screen extends AppCompatActivity { ...@@ -27,7 +35,6 @@ public class Start_Screen extends AppCompatActivity {
private boolean validateEmail () { private boolean validateEmail () {
String emailInput = textInputEmail.getEditText().getText().toString().trim(); String emailInput = textInputEmail.getEditText().getText().toString().trim();
if(emailInput.isEmpty()) { if(emailInput.isEmpty()) {
textInputEmail.setError("Field cannot be empty"); textInputEmail.setError("Field cannot be empty");
return false; return false;
...@@ -66,6 +73,20 @@ public class Start_Screen extends AppCompatActivity { ...@@ -66,6 +73,20 @@ public class Start_Screen extends AppCompatActivity {
} }
startActivity(new Intent(Start_Screen.this, Trip_Overview_Screen.class)); startActivity(new Intent(Start_Screen.this, Trip_Overview_Screen.class));
Toast.makeText(this, "Logging in ...", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Logging in ...", Toast.LENGTH_SHORT).show();
final User[] testUser = new User[0];
Call<User> call = userService.getUserByEmail("bruno@mail.com");
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
// https://medium.com/@prakash_pun/retrofit-a-simple-android-tutorial-48437e4e5a23
testUser[0] = response.body();
}
@Override
public void onFailure(Call<User> call, Throwable t) {
//onFailure
}
});
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment