Skip to content

Instantly share code, notes, and snippets.

@fredgrott
Created September 6, 2016 18:35
Show Gist options
  • Save fredgrott/ae950b68010fa0292e7d5ba572a2e0dd to your computer and use it in GitHub Desktop.
Save fredgrott/ae950b68010fa0292e7d5ba572a2e0dd to your computer and use it in GitHub Desktop.

Original code developed by Robert LaThanh Modifications by Fred Grott, all under Apache License 2.0 Copyright (C) 2016

public interface AdaptableViewModel<VM> {

  /**
   * Get the
   * already-{@link AdaptableAdapter#adapt(AdaptableViewModel) adapted}
   * version of this object, which had been saved by a previous call to
   * {@link #setViewModel(Object)}.
   *
   * @return the previously adapted object; {@code null} if it has not yet been
   *         adapted
   */
  @Nullable
  VM getViewModel();

  /**
   * Save the {@link AdaptableAdapter#adapt(AdaptableViewModel) adapted}
   * version of this object so that it's available when / next time it's needed.
   * If the item is still in view, this is the time to update the view; e.g.,
   * by notifying it that the view model has changed. This is the
   * responsibility of {@link AdaptableBindingAdapter} implementations.
   *
   * <p>Currently, there is no guarantee that the item will not be re-adapted
   * (for example, because of race conditions), so it is not safe to dereference
   * the adaptable data.</p>
   *
   * @param adapted the ViewModel for this item
   */
  void setViewModel(@NonNull VM adapted);

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment