package jp.satorufujiwara.binder.recycler;


import android.app.Activity;
import android.support.v7.widget.RecyclerView;

import jp.satorufujiwara.binder.ViewType;
import rx.Observable;
import rx.subjects.BehaviorSubject;

public abstract class RxRecyclerBinder<V extends ViewType> extends RecyclerBinder<V> {

    private final BehaviorSubject<Void> lifecycleSubject = BehaviorSubject.create();

    protected RxRecyclerBinder(final Activity activity, final V viewType) {
        super(activity, viewType);
    }

    @Override
    public void onRemoved() {
        super.onRemoved();
        lifecycleSubject.onNext(null);
    }

    @Override
    public void onViewRecycled(RecyclerView.ViewHolder holder) {
        super.onViewRecycled(holder);
        lifecycleSubject.onNext(null);
    }

    public final <T> Observable.Transformer<T, T> bindToLifecycle() {
        return bind(lifecycleSubject);
    }

    private static <T, R> Observable.Transformer<T, T> bind(final Observable<R> lifecycle) {
        return new Observable.Transformer<T, T>() {
            @Override
            public Observable<T> call(Observable<T> source) {
                return source.takeUntil(lifecycle);
            }
        };
    }
}

@@ -316,22 +316,16 @@
 private 
-final 
 Behavior
@@ -361,32 +361,12 @@
 t = 
-BehaviorSubject.create()
+null
 ;%0A%0A 
@@ -553,16 +553,86 @@
 oved();%0A
+        if (lifecycleSubject == null) %7B%0A            return;%0A        %7D%0A
         
@@ -654,32 +654,65 @@
 t.onNext(null);%0A
+        lifecycleSubject = null;%0A
     %7D%0A%0A    @Over
@@ -831,115 +831,364 @@
     
-lifecycleSubject.onNext(null);%0A    %7D%0A%0A    public final %3CT%3E Observable.Transformer%3CT, T%3E bindToLifecycle() %7B
+if (lifecycleSubject == null) %7B%0A            return;%0A        %7D%0A        lifecycleSubject.onNext(null);%0A        lifecycleSubject = null;%0A    %7D%0A%0A    public final %3CT%3E Observable.Transformer%3CT, T%3E bindToLifecycle() %7B%0A        if (lifecycleSubject != null) %7B%0A            lifecycleSubject.onNext(null);%0A        %7D%0A        lifecycleSubject = BehaviorSubject.create();
 %0A   

Fix bug.