Skip to content

Instantly share code, notes, and snippets.

@yccheok
Created October 16, 2018 12:25
Show Gist options
  • Select an option

  • Save yccheok/928b55c91c0bb5f58e068dd7befcb7a9 to your computer and use it in GitHub Desktop.

Select an option

Save yccheok/928b55c91c0bb5f58e068dd7befcb7a9 to your computer and use it in GitHub Desktop.
public static <T> void ready(LiveData<T> liveData, LifecycleOwner lifecycleOwner, Callable<T> callable) {
T t = liveData.getValue();
if (t != null) {
callable.call(t);
return;
}
liveData.observe(lifecycleOwner, new Observer<T>() {
@Override
public void onChanged(@Nullable T t) {
liveData.removeObserver(this);
callable.call(t);
}
});
}
public static void onUpdate(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
LiveData<Result> resultLiveData = getResultLiveData(appWidgetId);
ready(resultLiveData, ForeverStartLifecycleOwner.INSTANCE, result -> onUpdate(context, appWidgetManager, result.stickyNoteConfig, result.note));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment