package com.hosaka.rxanimation.animator;

import android.animation.Animator;

import com.hosaka.rxanimation.internal.MainThreadSubscription;

import rx.Observable;
import rx.Subscriber;

import static com.hosaka.rxanimation.internal.Preconditions.checkUiThread;

/**
 * Created by shunhosaka on 15/10/09.
 */
final class AnimatorEventOnSubscribe implements Observable.OnSubscribe<AnimatorEvent> {
    private final Animator animation;

    AnimatorEventOnSubscribe(Animator animation) {
        this.animation = animation;
    }

    @Override public void call(final Subscriber<? super AnimatorEvent> subscriber) {
        checkUiThread();

        final Animator.AnimatorListener listener = new Animator.AnimatorListener() {
            @Override public void onAnimationStart(Animator animation) {
                if (!subscriber.isUnsubscribed()) {
                    subscriber.onNext(AnimatorEvent.create(animation, AnimatorEvent.Kind.START));
                }
            }

            @Override public void onAnimationEnd(Animator animation) {
                if (!subscriber.isUnsubscribed()) {
                    subscriber.onNext(AnimatorEvent.create(animation, AnimatorEvent.Kind.END));
                }
            }

            @Override public void onAnimationCancel(Animator animation) {
                if (!subscriber.isUnsubscribed()) {
                    subscriber.onNext(AnimatorEvent.create(animation, AnimatorEvent.Kind.CANCEL));
                }
            }

            @Override public void onAnimationRepeat(Animator animation) {
                if (!subscriber.isUnsubscribed()) {
                    subscriber.onNext(AnimatorEvent.create(animation, AnimatorEvent.Kind.REPEAT));
                }
            }
        };
        animation.addListener(listener);

        subscriber.add(new MainThreadSubscription() {
            @Override
            protected void onUnSubscribe() {
                animation.removeListener(listener);
            }
        });
    }
}

@@ -61,32 +61,101 @@
 mation.Animator;
+%0Aimport android.support.annotation.NonNull;%0Aimport android.view.View;
 %0A%0Aimport com.hos
@@ -527,16 +527,25 @@
 bscribe(
+@NonNull 
 Animator

add nonnull annotation