<commit_before>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);
            }
        };
    }
}<commit_msg>Fix bug.<commit_after>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 BehaviorSubject<Void> lifecycleSubject = null;

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

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

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

    public final <T> Observable.Transformer<T, T> bindToLifecycle() {
        if (lifecycleSubject != null) {
            lifecycleSubject.onNext(null);
        }
        lifecycleSubject = BehaviorSubject.create();
        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);
            }
        };
    }
}
{'fraction_non_alphanumeric': 0.09670563230605739, 'fraction_numerical': 0.0007084661707403471, 'mean_word_length': 2.8737997256515775, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7153106', 'n_tokens_mistral': 852, 'n_tokens_neox': 818, 'n_words': 168}