Skip to content

Instantly share code, notes, and snippets.

@mikkipastel
Created September 26, 2017 07:44
Show Gist options
  • Save mikkipastel/1aa28be2a1b6af0bd7e525d78792367d to your computer and use it in GitHub Desktop.
Save mikkipastel/1aa28be2a1b6af0bd7e525d78792367d to your computer and use it in GitHub Desktop.
public class UserRepository {
private Webservice webservice;
// ...
public LiveData<User> getUser(int userId) {
// This is not an optimal implementation, we'll fix it below
final MutableLiveData<User> data = new MutableLiveData<>();
webservice.getUser(userId).enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
// error case is left out for brevity
data.setValue(response.body());
}
});
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment