Last active
January 1, 2019 20:42
-
-
Save evandroferreiras/25b2b8e9bc25357dc8dfa601ccb05347 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface PlacesService { | |
@GET("places/{id}") | |
Call<Place> getPlaceById(@Path("id") int placeId); | |
} | |
interface UsersService { | |
@GET("users") | |
Call<List<User>> listUsers(); | |
} | |
public class DataSource { | |
// .... | |
public void getUsersWithPlace(){ | |
usersService.listUsers() | |
.enqueue(new Callback<List<User>>() | |
{ | |
ArrayList<String> myDataset = new ArrayList<>(); | |
@Override | |
public void onResponse(@NonNull Call<List<User>> call, @NonNull Response<List<User>> response) { | |
List<User> users = response.body(); | |
for (final User user : users) { | |
placesService.getPlaceById(user.placeId) | |
.enqueue(new Callback<Place>(){ | |
@Override | |
public void onResponse(@NonNull Call<Place> call, @NonNull Response<Place> response) { | |
Place place = response.body(); | |
myDataset.add(user.name + " - " + place.title); | |
updateAdapter(myDataset); | |
} | |
@Override | |
public void onFailure(@NonNull Call<Place> call, @NonNull Throwable t) { | |
Log.e("DataSource", "onFailure: ", t ); | |
} | |
}); | |
} | |
} | |
@Override | |
public void onFailure(@NonNull Call<List<User>> call, @NonNull Throwable t) { | |
Log.e("DataSource", "onFailure: ", t ); | |
} | |
}); | |
} | |
// .... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment