Skip to content

Instantly share code, notes, and snippets.

@mitchtabian
Created June 13, 2019 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchtabian/431861cc4c0c75ff08c4c781077d5008 to your computer and use it in GitHub Desktop.
Save mitchtabian/431861cc4c0c75ff08c4c781077d5008 to your computer and use it in GitHub Desktop.
public void authenticateWithId(final LiveData<AuthResource<User>> source) {
if(cachedUser != null){
cachedUser.setValue(AuthResource.loading((User)null));
cachedUser.addSource(source, new Observer<AuthResource<User>>() {
@Override
public void onChanged(AuthResource<User> userAuthResource) {
cachedUser.setValue(userAuthResource);
cachedUser.removeSource(source);
if(userAuthResource.status.equals(AuthResource.AuthStatus.ERROR)){
cachedUser.setValue(AuthResource.<User>logout());
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment