Search code examples
rx-androidrx-java2rx-binding

rxBindings - How to know what consumer type should be when debouncing click events?


using rxBindings im trying to slow down a click event but i would like to know what the parameter is need.

For example, here is a call i am doing on a imageview. So ImageView v;

RxView.clicks(v)
                  .throttleFirst(400, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
                  .subscribe(new Consumer<Object>() {

                      @Override
                      public void accept(@io.reactivex.annotations.NonNull Object v) throws Exception {
                          showBottomSheet(getAdapterPosition());
                      }
                  });

              but im im not sure what the parameter in accept should be ?  

              I was expecting i would get the view here but when i try changing the type to View i get an error of no such method.

Solution

  • If you look at the source code of the Observable generate using RxView.clicks(), you will see that when the click happens, the following code is triggered:

    observer.onNext(Notification.INSTANCE);
    

    that is defined in the library, as:

    public enum Notification {
      INSTANCE
    }
    

    It is just a convenient way for indicating that the event happened, it doesn't carry any extra information.