package com.jakewharton.rxbinding2.view;

import android.graphics.drawable.Drawable;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import android.view.MenuItem;
import com.jakewharton.rxbinding.internal.Functions;
import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

import static com.jakewharton.rxbinding.internal.Preconditions.checkNotNull;

/**
 * Static factory methods for creating {@linkplain Observable observables} and {@linkplain Consumer
 * actions} for {@link MenuItem}.
 */
public final class RxMenuItem {

  /**
   * Create an observable which emits on {@code menuItem} click events. The emitted value is
   * unspecified and should only be used as notification.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   * <p>
   * <em>Warning:</em> The created observable uses {@link MenuItem#setOnMenuItemClickListener} to
   * observe clicks. Only one observable can be used for a menu item at a time.
   */
  @CheckResult @NonNull
  public static Observable<Object> clicks(@NonNull MenuItem menuItem) {
    checkNotNull(menuItem, "menuItem == null");
    return new MenuItemClickOnSubscribe(menuItem, Functions.FUNC1_ALWAYS_TRUE);
  }

  /**
   * Create an observable which emits on {@code menuItem} click events. The emitted value is
   * unspecified and should only be used as notification.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   * <p>
   * <em>Warning:</em> The created observable uses {@link MenuItem#setOnMenuItemClickListener} to
   * observe clicks. Only one observable can be used for a menu item at a time.
   *
   * @param handled Function invoked with each value to determine the return value of the
   * underlying {@link MenuItem.OnMenuItemClickListener}.
   */
  @CheckResult @NonNull
  public static Observable<Object> clicks(@NonNull MenuItem menuItem,
      @NonNull Function<? super MenuItem, Boolean> handled) {
    checkNotNull(menuItem, "menuItem == null");
    checkNotNull(handled, "handled == null");
    return new MenuItemClickOnSubscribe(menuItem, handled);
  }

  /**
   * Create an observable of action view events for {@code menuItem}.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   * <p>
   * <em>Warning:</em> The created observable uses {@link MenuItem#setOnActionExpandListener} to
   * observe action view events. Only one observable can be used for a menu item at a time.
   */
  @CheckResult @NonNull
  public static Observable<MenuItemActionViewEvent> actionViewEvents(@NonNull MenuItem menuItem) {
    checkNotNull(menuItem, "menuItem == null");
    return new MenuItemActionViewEventObservable(menuItem, Functions.FUNC1_ALWAYS_TRUE);
  }

  /**
   * Create an observable of action view events for {@code menuItem}.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   * <p>
   * <em>Warning:</em> The created observable uses {@link MenuItem#setOnActionExpandListener} to
   * observe action view events. Only one observable can be used for a menu item at a time.
   *
   * @param handled Function invoked with each value to determine the return value of the
   * underlying {@link MenuItem.OnActionExpandListener}.
   */
  @CheckResult @NonNull
  public static Observable<MenuItemActionViewEvent> actionViewEvents(@NonNull MenuItem menuItem,
      @NonNull Function<? super MenuItemActionViewEvent, Boolean> handled) {
    checkNotNull(menuItem, "menuItem == null");
    checkNotNull(handled, "handled == null");
    return new MenuItemActionViewEventObservable(menuItem, handled);
  }

  /**
   * An action which sets the checked property of {@code menuItem}.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   */
  @CheckResult @NonNull
  public static Consumer<? super Boolean> checked(@NonNull final MenuItem menuItem) {
    checkNotNull(menuItem, "menuItem == null");
    return new Consumer<Boolean>() {
      @Override public void accept(Boolean value) {
        menuItem.setChecked(value);
      }
    };
  }

  /**
   * An action which sets the enabled property of {@code menuItem}.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   */
  @CheckResult @NonNull
  public static Consumer<? super Boolean> enabled(@NonNull final MenuItem menuItem) {
    checkNotNull(menuItem, "menuItem == null");
    return new Consumer<Boolean>() {
      @Override public void accept(Boolean value) {
        menuItem.setEnabled(value);
      }
    };
  }

  /**
   * An action which sets the icon property of {@code menuItem}.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   */
  @CheckResult @NonNull
  public static Consumer<? super Drawable> icon(@NonNull final MenuItem menuItem) {
    checkNotNull(menuItem, "menuItem == null");
    return new Consumer<Drawable>() {
      @Override public void accept(Drawable value) {
        menuItem.setIcon(value);
      }
    };
  }

  /**
   * An action which sets the icon property of {@code menuItem}.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   */
  @CheckResult @NonNull
  public static Consumer<? super Integer> iconRes(@NonNull final MenuItem menuItem) {
    checkNotNull(menuItem, "menuItem == null");
    return new Consumer<Integer>() {
      @Override public void accept(Integer value) {
        menuItem.setIcon(value);
      }
    };
  }

  /**
   * An action which sets the title property of {@code menuItem}.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   */
  @CheckResult @NonNull
  public static Consumer<? super CharSequence> title(@NonNull final MenuItem menuItem) {
    checkNotNull(menuItem, "menuItem == null");
    return new Consumer<CharSequence>() {
      @Override public void accept(CharSequence value) {
        menuItem.setTitle(value);
      }
    };
  }

  /**
   * An action which sets the title property of {@code menuItem}.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   */
  @CheckResult @NonNull
  public static Consumer<? super Integer> titleRes(@NonNull final MenuItem menuItem) {
    checkNotNull(menuItem, "menuItem == null");
    return new Consumer<Integer>() {
      @Override public void accept(Integer value) {
        menuItem.setTitle(value);
      }
    };
  }

  /**
   * An action which sets the visibility property of {@code menuItem}.
   * <p>
   * <em>Warning:</em> The created observable keeps a strong reference to {@code menuItem}.
   * Unsubscribe to free this reference.
   */
  @CheckResult @NonNull
  public static Consumer<? super Boolean> visible(@NonNull final MenuItem menuItem) {
    checkNotNull(menuItem, "menuItem == null");
    return new Consumer<Boolean>() {
      @Override public void accept(Boolean value) {
        menuItem.setVisible(value);
      }
    };
  }

  private RxMenuItem() {
    throw new AssertionError("No instances.");
  }
}

@@ -222,32 +222,33 @@
 harton.rxbinding
+2
 .internal.Functi
@@ -1310,33 +1310,36 @@
 , Functions.FUNC
-1
+TION
 _ALWAYS_TRUE);%0A 
@@ -2972,9 +2972,12 @@
 FUNC
-1
+TION
 _ALW

Use Functions.FUNCTION_ALWAYS_TRUE from correct package