Search in sources :

Example 1 with SwipeDismissBehavior

use of android.support.design.widget.SwipeDismissBehavior in project RxBinding by JakeWharton.

the class SwipeDismissBehaviorObservable method subscribeActual.

@Override
protected void subscribeActual(Observer<? super View> observer) {
    if (!checkMainThread(observer)) {
        return;
    }
    if (!(view.getLayoutParams() instanceof LayoutParams)) {
        throw new IllegalArgumentException("The view is not in a Coordinator Layout.");
    }
    LayoutParams params = (LayoutParams) view.getLayoutParams();
    final SwipeDismissBehavior behavior = (SwipeDismissBehavior) params.getBehavior();
    if (behavior == null) {
        throw new IllegalStateException("There's no behavior set on this view.");
    }
    Listener listener = new Listener(behavior, observer);
    observer.onSubscribe(listener);
    behavior.setListener(listener);
}
Also used : SwipeDismissBehavior(android.support.design.widget.SwipeDismissBehavior) LayoutParams(android.support.design.widget.CoordinatorLayout.LayoutParams) OnDismissListener(android.support.design.widget.SwipeDismissBehavior.OnDismissListener)

Example 2 with SwipeDismissBehavior

use of android.support.design.widget.SwipeDismissBehavior in project RxBinding by JakeWharton.

the class RxSwipeDismissBehaviorTest method dismisses.

@Test
public void dismisses() {
    ((CoordinatorLayout.LayoutParams) view.getLayoutParams()).setBehavior(new SwipeDismissBehavior());
    RecordingObserver<View> o = new RecordingObserver<>();
    RxSwipeDismissBehavior.dismisses(view).subscribeOn(AndroidSchedulers.mainThread()).subscribe(o);
    // No initial value.
    o.assertNoMoreEvents();
    onView(withId(1)).perform(swipeRight());
    assertEquals(view, o.takeNext());
    o.dispose();
    onView(withId(1)).perform(swipeRight());
    o.assertNoMoreEvents();
}
Also used : SwipeDismissBehavior(android.support.design.widget.SwipeDismissBehavior) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View) Test(org.junit.Test)

Aggregations

SwipeDismissBehavior (android.support.design.widget.SwipeDismissBehavior)2 LayoutParams (android.support.design.widget.CoordinatorLayout.LayoutParams)1 OnDismissListener (android.support.design.widget.SwipeDismissBehavior.OnDismissListener)1 Espresso.onView (android.support.test.espresso.Espresso.onView)1 View (android.view.View)1 RecordingObserver (com.jakewharton.rxbinding2.RecordingObserver)1 Test (org.junit.Test)1