Created
September 26, 2017 07:44
-
-
Save mikkipastel/1aa28be2a1b6af0bd7e525d78792367d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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