package X6FRs_4.KNBe_11;

import X6FRs_4.KNBe_11.IFxWkV_5;
import android.util.Log;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
/* compiled from: LifecycleRegistry.java */
/* loaded from: classes.dex */
public class XnFJ5_9 extends IFxWkV_5 {

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final WeakReference<Xgtqvk_8> f614KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.KQgRr5e_0<FSaI4_7, QxJ9d_1> f613KQgRr5e_0 = new X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.KQgRr5e_0<>();
    public int KQgRr5e_0 = 0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public boolean f616KQgRr5e_0 = false;
    public boolean QxJ9d_1 = false;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public ArrayList<IFxWkV_5.QxJ9d_1> f615KQgRr5e_0 = new ArrayList<>();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public IFxWkV_5.QxJ9d_1 f612KQgRr5e_0 = IFxWkV_5.QxJ9d_1.INITIALIZED;

    /* compiled from: LifecycleRegistry.java */
    /* loaded from: classes.dex */
    public static /* synthetic */ class KQgRr5e_0 {
        public static final /* synthetic */ int[] KQgRr5e_0;
        public static final /* synthetic */ int[] QxJ9d_1;

        static {
            int[] iArr = new int[IFxWkV_5.QxJ9d_1.values().length];
            QxJ9d_1 = iArr;
            try {
                iArr[IFxWkV_5.QxJ9d_1.INITIALIZED.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                QxJ9d_1[IFxWkV_5.QxJ9d_1.CREATED.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                QxJ9d_1[IFxWkV_5.QxJ9d_1.STARTED.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                QxJ9d_1[IFxWkV_5.QxJ9d_1.RESUMED.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                QxJ9d_1[IFxWkV_5.QxJ9d_1.DESTROYED.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            int[] iArr2 = new int[IFxWkV_5.KQgRr5e_0.values().length];
            KQgRr5e_0 = iArr2;
            try {
                iArr2[IFxWkV_5.KQgRr5e_0.ON_CREATE.ordinal()] = 1;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                KQgRr5e_0[IFxWkV_5.KQgRr5e_0.ON_STOP.ordinal()] = 2;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                KQgRr5e_0[IFxWkV_5.KQgRr5e_0.ON_START.ordinal()] = 3;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                KQgRr5e_0[IFxWkV_5.KQgRr5e_0.ON_PAUSE.ordinal()] = 4;
            } catch (NoSuchFieldError unused9) {
            }
            try {
                KQgRr5e_0[IFxWkV_5.KQgRr5e_0.ON_RESUME.ordinal()] = 5;
            } catch (NoSuchFieldError unused10) {
            }
            try {
                KQgRr5e_0[IFxWkV_5.KQgRr5e_0.ON_DESTROY.ordinal()] = 6;
            } catch (NoSuchFieldError unused11) {
            }
            try {
                KQgRr5e_0[IFxWkV_5.KQgRr5e_0.ON_ANY.ordinal()] = 7;
            } catch (NoSuchFieldError unused12) {
            }
        }
    }

    /* compiled from: LifecycleRegistry.java */
    /* loaded from: classes.dex */
    public static class QxJ9d_1 {
        public IFxWkV_5.QxJ9d_1 KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public X6FRs_4 f617KQgRr5e_0;

        public QxJ9d_1(FSaI4_7 fSaI4_7, IFxWkV_5.QxJ9d_1 qxJ9d_1) {
            this.f617KQgRr5e_0 = KNBe_11.KQgRr5e_0(fSaI4_7);
            this.KQgRr5e_0 = qxJ9d_1;
        }

        public void KQgRr5e_0(Xgtqvk_8 xgtqvk_8, IFxWkV_5.KQgRr5e_0 kQgRr5e_0) {
            IFxWkV_5.QxJ9d_1 KQgRr5e_0 = XnFJ5_9.KQgRr5e_0(kQgRr5e_0);
            this.KQgRr5e_0 = XnFJ5_9.KQgRr5e_0(this.KQgRr5e_0, KQgRr5e_0);
            this.f617KQgRr5e_0.KQgRr5e_0(xgtqvk_8, kQgRr5e_0);
            this.KQgRr5e_0 = KQgRr5e_0;
        }
    }

    public XnFJ5_9(Xgtqvk_8 xgtqvk_8) {
        this.f614KQgRr5e_0 = new WeakReference<>(xgtqvk_8);
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public void m362KQgRr5e_0(IFxWkV_5.QxJ9d_1 qxJ9d_1) {
        m363QxJ9d_1(qxJ9d_1);
    }

    public final void PGPF6hQ_2(IFxWkV_5.QxJ9d_1 qxJ9d_1) {
        this.f615KQgRr5e_0.add(qxJ9d_1);
    }

    /* renamed from: QxJ9d_1  reason: collision with other method in class */
    public final void m363QxJ9d_1(IFxWkV_5.QxJ9d_1 qxJ9d_1) {
        if (this.f612KQgRr5e_0 == qxJ9d_1) {
            return;
        }
        this.f612KQgRr5e_0 = qxJ9d_1;
        if (!this.f616KQgRr5e_0 && this.KQgRr5e_0 == 0) {
            this.f616KQgRr5e_0 = true;
            QxJ9d_1();
            this.f616KQgRr5e_0 = false;
            return;
        }
        this.QxJ9d_1 = true;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public void m361KQgRr5e_0(IFxWkV_5.KQgRr5e_0 kQgRr5e_0) {
        m363QxJ9d_1(KQgRr5e_0(kQgRr5e_0));
    }

    @Override // X6FRs_4.KNBe_11.IFxWkV_5
    public final boolean KQgRr5e_0() {
        if (this.f613KQgRr5e_0.size() == 0) {
            return true;
        }
        IFxWkV_5.QxJ9d_1 qxJ9d_1 = this.f613KQgRr5e_0.m531KQgRr5e_0().getValue().KQgRr5e_0;
        IFxWkV_5.QxJ9d_1 qxJ9d_12 = this.f613KQgRr5e_0.QxJ9d_1().getValue().KQgRr5e_0;
        return qxJ9d_1 == qxJ9d_12 && this.f612KQgRr5e_0 == qxJ9d_12;
    }

    @Override // X6FRs_4.KNBe_11.IFxWkV_5
    public final IFxWkV_5.QxJ9d_1 KQgRr5e_0(FSaI4_7 fSaI4_7) {
        Map.Entry<FSaI4_7, QxJ9d_1> KQgRr5e_02 = this.f613KQgRr5e_0.KQgRr5e_0((X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.KQgRr5e_0<FSaI4_7, QxJ9d_1>) fSaI4_7);
        IFxWkV_5.QxJ9d_1 qxJ9d_1 = null;
        IFxWkV_5.QxJ9d_1 qxJ9d_12 = KQgRr5e_02 != null ? KQgRr5e_02.getValue().KQgRr5e_0 : null;
        if (!this.f615KQgRr5e_0.isEmpty()) {
            ArrayList<IFxWkV_5.QxJ9d_1> arrayList = this.f615KQgRr5e_0;
            qxJ9d_1 = arrayList.get(arrayList.size() - 1);
        }
        return KQgRr5e_0(KQgRr5e_0(this.f612KQgRr5e_0, qxJ9d_12), qxJ9d_1);
    }

    @Override // X6FRs_4.KNBe_11.IFxWkV_5
    public void QxJ9d_1(FSaI4_7 fSaI4_7) {
        this.f613KQgRr5e_0.KQgRr5e_0((X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.KQgRr5e_0<FSaI4_7, QxJ9d_1>) fSaI4_7);
    }

    public static IFxWkV_5.KQgRr5e_0 QxJ9d_1(IFxWkV_5.QxJ9d_1 qxJ9d_1) {
        int i = KQgRr5e_0.QxJ9d_1[qxJ9d_1.ordinal()];
        if (i != 1) {
            if (i == 2) {
                return IFxWkV_5.KQgRr5e_0.ON_START;
            }
            if (i == 3) {
                return IFxWkV_5.KQgRr5e_0.ON_RESUME;
            }
            if (i == 4) {
                throw new IllegalArgumentException();
            }
            if (i != 5) {
                throw new IllegalArgumentException("Unexpected state value " + qxJ9d_1);
            }
        }
        return IFxWkV_5.KQgRr5e_0.ON_CREATE;
    }

    @Override // X6FRs_4.KNBe_11.IFxWkV_5
    public void KQgRr5e_0(FSaI4_7 fSaI4_7) {
        Xgtqvk_8 xgtqvk_8;
        IFxWkV_5.QxJ9d_1 qxJ9d_1 = this.f612KQgRr5e_0;
        IFxWkV_5.QxJ9d_1 qxJ9d_12 = IFxWkV_5.QxJ9d_1.DESTROYED;
        if (qxJ9d_1 != qxJ9d_12) {
            qxJ9d_12 = IFxWkV_5.QxJ9d_1.INITIALIZED;
        }
        QxJ9d_1 qxJ9d_13 = new QxJ9d_1(fSaI4_7, qxJ9d_12);
        if (this.f613KQgRr5e_0.KQgRr5e_0((X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.KQgRr5e_0<FSaI4_7, QxJ9d_1>) fSaI4_7, (FSaI4_7) qxJ9d_13) == null && (xgtqvk_8 = this.f614KQgRr5e_0.get()) != null) {
            boolean z = this.KQgRr5e_0 != 0 || this.f616KQgRr5e_0;
            IFxWkV_5.QxJ9d_1 KQgRr5e_02 = KQgRr5e_0(fSaI4_7);
            this.KQgRr5e_0++;
            while (qxJ9d_13.KQgRr5e_0.compareTo(KQgRr5e_02) < 0 && this.f613KQgRr5e_0.contains(fSaI4_7)) {
                PGPF6hQ_2(qxJ9d_13.KQgRr5e_0);
                qxJ9d_13.KQgRr5e_0(xgtqvk_8, QxJ9d_1(qxJ9d_13.KQgRr5e_0));
                KQgRr5e_0();
                KQgRr5e_02 = KQgRr5e_0(fSaI4_7);
            }
            if (!z) {
                QxJ9d_1();
            }
            this.KQgRr5e_0--;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final void QxJ9d_1(Xgtqvk_8 xgtqvk_8) {
        X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.QxJ9d_1<FSaI4_7, QxJ9d_1>.Mqv2r_3 KQgRr5e_02 = this.f613KQgRr5e_0.KQgRr5e_0();
        while (KQgRr5e_02.hasNext() && !this.QxJ9d_1) {
            Map.Entry next = KQgRr5e_02.next();
            QxJ9d_1 qxJ9d_1 = (QxJ9d_1) next.getValue();
            while (qxJ9d_1.KQgRr5e_0.compareTo(this.f612KQgRr5e_0) < 0 && !this.QxJ9d_1 && this.f613KQgRr5e_0.contains(next.getKey())) {
                PGPF6hQ_2(qxJ9d_1.KQgRr5e_0);
                qxJ9d_1.KQgRr5e_0(xgtqvk_8, QxJ9d_1(qxJ9d_1.KQgRr5e_0));
                KQgRr5e_0();
            }
        }
    }

    public final void QxJ9d_1() {
        Xgtqvk_8 xgtqvk_8 = this.f614KQgRr5e_0.get();
        if (xgtqvk_8 == null) {
            Log.w("LifecycleRegistry", "LifecycleOwner is garbage collected, you shouldn't try dispatch new events from it.");
            return;
        }
        while (!KQgRr5e_0()) {
            this.QxJ9d_1 = false;
            if (this.f612KQgRr5e_0.compareTo(this.f613KQgRr5e_0.m531KQgRr5e_0().getValue().KQgRr5e_0) < 0) {
                KQgRr5e_0(xgtqvk_8);
            }
            Map.Entry<FSaI4_7, QxJ9d_1> QxJ9d_12 = this.f613KQgRr5e_0.QxJ9d_1();
            if (!this.QxJ9d_1 && QxJ9d_12 != null && this.f612KQgRr5e_0.compareTo(QxJ9d_12.getValue().KQgRr5e_0) > 0) {
                QxJ9d_1(xgtqvk_8);
            }
        }
        this.QxJ9d_1 = false;
    }

    @Override // X6FRs_4.KNBe_11.IFxWkV_5
    public final void KQgRr5e_0() {
        ArrayList<IFxWkV_5.QxJ9d_1> arrayList = this.f615KQgRr5e_0;
        arrayList.remove(arrayList.size() - 1);
    }

    @Override // X6FRs_4.KNBe_11.IFxWkV_5
    public IFxWkV_5.QxJ9d_1 KQgRr5e_0() {
        return this.f612KQgRr5e_0;
    }

    public static IFxWkV_5.QxJ9d_1 KQgRr5e_0(IFxWkV_5.KQgRr5e_0 kQgRr5e_0) {
        switch (KQgRr5e_0.KQgRr5e_0[kQgRr5e_0.ordinal()]) {
            case 1:
            case 2:
                return IFxWkV_5.QxJ9d_1.CREATED;
            case 3:
            case 4:
                return IFxWkV_5.QxJ9d_1.STARTED;
            case 5:
                return IFxWkV_5.QxJ9d_1.RESUMED;
            case 6:
                return IFxWkV_5.QxJ9d_1.DESTROYED;
            default:
                throw new IllegalArgumentException("Unexpected event value " + kQgRr5e_0);
        }
    }

    public static IFxWkV_5.KQgRr5e_0 KQgRr5e_0(IFxWkV_5.QxJ9d_1 qxJ9d_1) {
        int i = KQgRr5e_0.QxJ9d_1[qxJ9d_1.ordinal()];
        if (i != 1) {
            if (i != 2) {
                if (i != 3) {
                    if (i != 4) {
                        if (i != 5) {
                            throw new IllegalArgumentException("Unexpected state value " + qxJ9d_1);
                        }
                        throw new IllegalArgumentException();
                    }
                    return IFxWkV_5.KQgRr5e_0.ON_PAUSE;
                }
                return IFxWkV_5.KQgRr5e_0.ON_STOP;
            }
            return IFxWkV_5.KQgRr5e_0.ON_DESTROY;
        }
        throw new IllegalArgumentException();
    }

    public final void KQgRr5e_0(Xgtqvk_8 xgtqvk_8) {
        Iterator<Map.Entry<FSaI4_7, QxJ9d_1>> m530KQgRr5e_0 = this.f613KQgRr5e_0.m530KQgRr5e_0();
        while (m530KQgRr5e_0.hasNext() && !this.QxJ9d_1) {
            Map.Entry<FSaI4_7, QxJ9d_1> next = m530KQgRr5e_0.next();
            QxJ9d_1 value = next.getValue();
            while (value.KQgRr5e_0.compareTo(this.f612KQgRr5e_0) > 0 && !this.QxJ9d_1 && this.f613KQgRr5e_0.contains(next.getKey())) {
                IFxWkV_5.KQgRr5e_0 KQgRr5e_02 = KQgRr5e_0(value.KQgRr5e_0);
                PGPF6hQ_2(KQgRr5e_0(KQgRr5e_02));
                value.KQgRr5e_0(xgtqvk_8, KQgRr5e_02);
                KQgRr5e_0();
            }
        }
    }

    public static IFxWkV_5.QxJ9d_1 KQgRr5e_0(IFxWkV_5.QxJ9d_1 qxJ9d_1, IFxWkV_5.QxJ9d_1 qxJ9d_12) {
        return (qxJ9d_12 == null || qxJ9d_12.compareTo(qxJ9d_1) >= 0) ? qxJ9d_1 : qxJ9d_12;
    }
}
