package com.trello.rxlifecycle3;

import com.trello.rxlifecycle3.internal.Preconditions;
import f.a.e;
import f.a.i;
import f.a.l;
import f.a.v.b;
import f.a.v.d;
import f.a.w.b.a;
import f.a.w.e.d.f0;
import f.a.w.e.d.h0;
import f.a.w.e.d.s;
import f.a.w.e.d.w;
import f.a.w.e.d.y;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;

/* JADX INFO: loaded from: classes.dex */
public class RxLifecycle {
    private RxLifecycle() {
        throw new AssertionError("No instances");
    }

    @Nonnull
    @CheckReturnValue
    public static <T, R> LifecycleTransformer<T> bind(@Nonnull i<R> iVar) {
        return new LifecycleTransformer<>(iVar);
    }

    @Nonnull
    @CheckReturnValue
    public static <T, R> LifecycleTransformer<T> bindUntilEvent(@Nonnull i<R> iVar, @Nonnull R r) {
        Preconditions.checkNotNull(iVar, "lifecycle == null");
        Preconditions.checkNotNull(r, "event == null");
        return bind(takeUntilEvent(iVar, r));
    }

    private static <R> i<Boolean> takeUntilCorrespondingEvent(i<R> iVar, d<R, R> dVar) {
        Objects.requireNonNull(iVar);
        h0 h0Var = new h0(iVar, 1L);
        Objects.requireNonNull(dVar, "mapper is null");
        s sVar = new s(h0Var, dVar);
        f0 f0Var = new f0(iVar, 1L);
        a.C0066a c0066a = new a.C0066a(new b<R, R, Boolean>() { // from class: com.trello.rxlifecycle3.RxLifecycle.2
            /* JADX WARN: Can't rename method to resolve collision */
            @Override // f.a.v.b
            public Boolean apply(R r, R r2) throws Exception {
                return Boolean.valueOf(r2.equals(r));
            }
        });
        int i2 = e.f3697b;
        l[] lVarArr = {sVar, f0Var};
        f.a.w.b.b.a(i2, "bufferSize");
        return new f.a.w.e.d.b(lVarArr, null, c0066a, i2 << 1, false).o(Functions.RESUME_FUNCTION).j(Functions.SHOULD_COMPLETE);
    }

    private static <R> i<R> takeUntilEvent(i<R> iVar, final R r) {
        return iVar.j(new f.a.v.e<R>() { // from class: com.trello.rxlifecycle3.RxLifecycle.1
            @Override // f.a.v.e
            public boolean test(R r2) throws Exception {
                return r2.equals(r);
            }
        });
    }

    @Nonnull
    @CheckReturnValue
    public static <T, R> LifecycleTransformer<T> bind(@Nonnull i<R> iVar, @Nonnull d<R, R> dVar) {
        Preconditions.checkNotNull(iVar, "lifecycle == null");
        Preconditions.checkNotNull(dVar, "correspondingEvents == null");
        Objects.requireNonNull(iVar);
        new AtomicReference();
        return bind(takeUntilCorrespondingEvent(new y(new w(iVar)), dVar));
    }
}
