package androidx.lifecycle;

import tp.u1;

/* loaded from: classes.dex */
public final class c {

    /* renamed from: a, reason: collision with root package name */
    private final f f4757a;

    /* renamed from: b, reason: collision with root package name */
    private final dn.p f4758b;

    /* renamed from: c, reason: collision with root package name */
    private final long f4759c;

    /* renamed from: d, reason: collision with root package name */
    private final tp.m0 f4760d;

    /* renamed from: e, reason: collision with root package name */
    private final dn.a f4761e;

    /* renamed from: f, reason: collision with root package name */
    private u1 f4762f;

    /* renamed from: g, reason: collision with root package name */
    private u1 f4763g;

    /* loaded from: classes.dex */
    static final class a extends kotlin.coroutines.jvm.internal.l implements dn.p {

        /* renamed from: p, reason: collision with root package name */
        int f4764p;

        a(vm.d dVar) {
            super(2, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new a(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f4764p;
            if (i10 == 0) {
                rm.y.b(obj);
                long j10 = c.this.f4759c;
                this.f4764p = 1;
                if (tp.w0.a(j10, this) == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                rm.y.b(obj);
            }
            if (!c.this.f4757a.h()) {
                u1 u1Var = c.this.f4762f;
                if (u1Var != null) {
                    u1.a.a(u1Var, null, 1, null);
                }
                c.this.f4762f = null;
            }
            return rm.n0.f34904a;
        }

        @Override // dn.p
        public final Object invoke(tp.m0 m0Var, vm.d dVar) {
            return ((a) create(m0Var, dVar)).invokeSuspend(rm.n0.f34904a);
        }
    }

    /* loaded from: classes.dex */
    static final class b extends kotlin.coroutines.jvm.internal.l implements dn.p {

        /* renamed from: p, reason: collision with root package name */
        int f4766p;

        /* renamed from: q, reason: collision with root package name */
        private /* synthetic */ Object f4767q;

        b(vm.d dVar) {
            super(2, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            b bVar = new b(dVar);
            bVar.f4767q = obj;
            return bVar;
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f4766p;
            if (i10 == 0) {
                rm.y.b(obj);
                c0 c0Var = new c0(c.this.f4757a, ((tp.m0) this.f4767q).getCoroutineContext());
                dn.p pVar = c.this.f4758b;
                this.f4766p = 1;
                if (pVar.invoke(c0Var, this) == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                rm.y.b(obj);
            }
            c.this.f4761e.invoke();
            return rm.n0.f34904a;
        }

        @Override // dn.p
        public final Object invoke(tp.m0 m0Var, vm.d dVar) {
            return ((b) create(m0Var, dVar)).invokeSuspend(rm.n0.f34904a);
        }
    }

    public c(f liveData, dn.p block, long j10, tp.m0 scope, dn.a onDone) {
        kotlin.jvm.internal.t.g(liveData, "liveData");
        kotlin.jvm.internal.t.g(block, "block");
        kotlin.jvm.internal.t.g(scope, "scope");
        kotlin.jvm.internal.t.g(onDone, "onDone");
        this.f4757a = liveData;
        this.f4758b = block;
        this.f4759c = j10;
        this.f4760d = scope;
        this.f4761e = onDone;
    }

    public final void g() {
        u1 d10;
        if (this.f4763g != null) {
            throw new IllegalStateException("Cancel call cannot happen without a maybeRun".toString());
        }
        d10 = tp.k.d(this.f4760d, tp.a1.c().a0(), null, new a(null), 2, null);
        this.f4763g = d10;
    }

    public final void h() {
        u1 d10;
        u1 u1Var = this.f4763g;
        if (u1Var != null) {
            u1.a.a(u1Var, null, 1, null);
        }
        this.f4763g = null;
        if (this.f4762f != null) {
            return;
        }
        d10 = tp.k.d(this.f4760d, null, null, new b(null), 3, null);
        this.f4762f = d10;
    }
}
