package androidx.activity;

import androidx.lifecycle.Lifecycle;
import java.util.ArrayDeque;
import java.util.Iterator;
import ῲ.Ԕ.K.LayoutInflater$Factory2C1545;
import ῲ.ؿ.AbstractC1569;
import ῲ.ؿ.AbstractC1574;
import ῲ.ؿ.C1584;
import ῲ.K.AbstractC2196;
import ῲ.K.AbstractC2197;

public final class OnBackPressedDispatcher {

    /* renamed from: ῲ  reason: contains not printable characters */
    public final ArrayDeque<AbstractC2196> f133 = new ArrayDeque<>();

    /* renamed from: K  reason: contains not printable characters */
    public final Runnable f134;

    public class LifecycleOnBackPressedCancellable implements AbstractC1569, AbstractC2197 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public AbstractC2197 f135;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final AbstractC2196 f136;

        /* renamed from: K  reason: contains not printable characters */
        public final Lifecycle f137;

        public LifecycleOnBackPressedCancellable(Lifecycle lifecycle, AbstractC2196 r3) {
            this.f137 = lifecycle;
            this.f136 = r3;
            lifecycle.m690(this);
        }

        @Override // ῲ.K.AbstractC2197
        public void cancel() {
            ((C1584) this.f137).f5753.remove(this);
            this.f136.f7655.remove(this);
            AbstractC2197 k = this.f135;
            if (k != null) {
                k.cancel();
                this.f135 = null;
            }
        }

        @Override // ῲ.ؿ.AbstractC1569
        /* renamed from: K  reason: contains not printable characters */
        public void m123(AbstractC1574 r2, Lifecycle.Event event) {
            if (event == Lifecycle.Event.ON_START) {
                OnBackPressedDispatcher onBackPressedDispatcher = OnBackPressedDispatcher.this;
                AbstractC2196 r3 = this.f136;
                onBackPressedDispatcher.f133.add(r3);
                C0034 k = new C0034(r3);
                r3.m5784(k);
                this.f135 = k;
            } else if (event == Lifecycle.Event.ON_STOP) {
                AbstractC2197 k2 = this.f135;
                if (k2 != null) {
                    k2.cancel();
                }
            } else if (event == Lifecycle.Event.ON_DESTROY) {
                cancel();
            }
        }
    }

    /* renamed from: androidx.activity.OnBackPressedDispatcher$K  reason: contains not printable characters */
    public class C0034 implements AbstractC2197 {

        /* renamed from: K  reason: contains not printable characters */
        public final AbstractC2196 f140;

        public C0034(AbstractC2196 r2) {
            this.f140 = r2;
        }

        @Override // ῲ.K.AbstractC2197
        public void cancel() {
            OnBackPressedDispatcher.this.f133.remove(this.f140);
            this.f140.f7655.remove(this);
        }
    }

    public OnBackPressedDispatcher(Runnable runnable) {
        this.f134 = runnable;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m122(AbstractC1574 r3, AbstractC2196 r4) {
        Lifecycle lifecycle = r3.getLifecycle();
        if (((C1584) lifecycle).f5751 != Lifecycle.State.DESTROYED) {
            r4.f7655.add(new LifecycleOnBackPressedCancellable(lifecycle, r4));
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m121() {
        Iterator<AbstractC2196> descendingIterator = this.f133.descendingIterator();
        while (descendingIterator.hasNext()) {
            AbstractC2196 next = descendingIterator.next();
            if (next.f7656) {
                LayoutInflater$Factory2C1545.this.m4053();
                return;
            }
        }
        Runnable runnable = this.f134;
        if (runnable != null) {
            runnable.run();
        }
    }
}
