package androidx.lifecycle;

import X6FRs_4.KNBe_11.IFxWkV_5;
import X6FRs_4.KNBe_11.X6FRs_4;
import X6FRs_4.KNBe_11.Xgtqvk_8;
import X6FRs_4.KNBe_11.YghfZG_14;
/* loaded from: classes.dex */
public abstract class LiveData<T> {

    /* renamed from: Mqv2r_3  reason: collision with root package name */
    public static final Object f3531Mqv2r_3 = new Object();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public boolean f2358KQgRr5e_0;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public boolean f2360QxJ9d_1;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Object f2357KQgRr5e_0 = new Object();

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.QxJ9d_1<YghfZG_14<? super T>, LiveData<T>.QxJ9d_1> f2356KQgRr5e_0 = new X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.QxJ9d_1<>();
    public int KQgRr5e_0 = 0;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public volatile Object f2359QxJ9d_1 = f3531Mqv2r_3;
    public volatile Object PGPF6hQ_2 = f3531Mqv2r_3;
    public int QxJ9d_1 = -1;

    /* loaded from: classes.dex */
    public class KQgRr5e_0 implements Runnable {
        public KQgRr5e_0() {
        }

        /* JADX WARN: Multi-variable type inference failed */
        @Override // java.lang.Runnable
        public void run() {
            Object obj;
            synchronized (LiveData.this.f2357KQgRr5e_0) {
                obj = LiveData.this.PGPF6hQ_2;
                LiveData.this.PGPF6hQ_2 = LiveData.f3531Mqv2r_3;
            }
            LiveData.this.KQgRr5e_0((LiveData) obj);
        }
    }

    /* loaded from: classes.dex */
    public class LifecycleBoundObserver extends LiveData<T>.QxJ9d_1 implements X6FRs_4 {
        public final Xgtqvk_8 KQgRr5e_0;

        public LifecycleBoundObserver(Xgtqvk_8 xgtqvk_8, YghfZG_14<? super T> yghfZG_14) {
            super(yghfZG_14);
            this.KQgRr5e_0 = xgtqvk_8;
        }

        @Override // androidx.lifecycle.LiveData.QxJ9d_1
        public boolean KQgRr5e_0() {
            return this.KQgRr5e_0.getLifecycle().KQgRr5e_0().KQgRr5e_0(IFxWkV_5.QxJ9d_1.STARTED);
        }

        @Override // X6FRs_4.KNBe_11.X6FRs_4
        public void KQgRr5e_0(Xgtqvk_8 xgtqvk_8, IFxWkV_5.KQgRr5e_0 kQgRr5e_0) {
            if (this.KQgRr5e_0.getLifecycle().KQgRr5e_0() == IFxWkV_5.QxJ9d_1.DESTROYED) {
                LiveData.this.KQgRr5e_0((YghfZG_14) ((QxJ9d_1) this).f2361KQgRr5e_0);
            } else {
                KQgRr5e_0(KQgRr5e_0());
            }
        }

        @Override // androidx.lifecycle.LiveData.QxJ9d_1
        public boolean KQgRr5e_0(Xgtqvk_8 xgtqvk_8) {
            return this.KQgRr5e_0 == xgtqvk_8;
        }

        @Override // androidx.lifecycle.LiveData.QxJ9d_1
        public void KQgRr5e_0() {
            this.KQgRr5e_0.getLifecycle().QxJ9d_1(this);
        }
    }

    /* loaded from: classes.dex */
    public abstract class QxJ9d_1 {
        public int KQgRr5e_0 = -1;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final YghfZG_14<? super T> f2361KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public boolean f2363KQgRr5e_0;

        public QxJ9d_1(YghfZG_14<? super T> yghfZG_14) {
            this.f2361KQgRr5e_0 = yghfZG_14;
        }

        public void KQgRr5e_0() {
        }

        public void KQgRr5e_0(boolean z) {
            if (z == this.f2363KQgRr5e_0) {
                return;
            }
            this.f2363KQgRr5e_0 = z;
            boolean z2 = LiveData.this.KQgRr5e_0 == 0;
            LiveData.this.KQgRr5e_0 += this.f2363KQgRr5e_0 ? 1 : -1;
            if (z2 && this.f2363KQgRr5e_0) {
                LiveData.this.KQgRr5e_0();
            }
            LiveData liveData = LiveData.this;
            if (liveData.KQgRr5e_0 == 0 && !this.f2363KQgRr5e_0) {
                liveData.QxJ9d_1();
            }
            if (this.f2363KQgRr5e_0) {
                LiveData.this.QxJ9d_1(this);
            }
        }

        /* renamed from: KQgRr5e_0  reason: collision with other method in class */
        public abstract boolean m898KQgRr5e_0();

        public boolean KQgRr5e_0(Xgtqvk_8 xgtqvk_8) {
            return false;
        }
    }

    public LiveData() {
        new KQgRr5e_0();
    }

    public void KQgRr5e_0() {
    }

    public final void KQgRr5e_0(LiveData<T>.QxJ9d_1 qxJ9d_1) {
        if (qxJ9d_1.f2363KQgRr5e_0) {
            if (!qxJ9d_1.m898KQgRr5e_0()) {
                qxJ9d_1.KQgRr5e_0(false);
                return;
            }
            int i = qxJ9d_1.KQgRr5e_0;
            int i2 = this.QxJ9d_1;
            if (i >= i2) {
                return;
            }
            qxJ9d_1.KQgRr5e_0 = i2;
            qxJ9d_1.f2361KQgRr5e_0.KQgRr5e_0((Object) this.f2359QxJ9d_1);
        }
    }

    public void QxJ9d_1() {
    }

    public void QxJ9d_1(LiveData<T>.QxJ9d_1 qxJ9d_1) {
        if (this.f2358KQgRr5e_0) {
            this.f2360QxJ9d_1 = true;
            return;
        }
        this.f2358KQgRr5e_0 = true;
        do {
            this.f2360QxJ9d_1 = false;
            if (qxJ9d_1 != null) {
                KQgRr5e_0((QxJ9d_1) qxJ9d_1);
                qxJ9d_1 = null;
            } else {
                X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.QxJ9d_1<YghfZG_14<? super T>, LiveData<T>.QxJ9d_1>.Mqv2r_3 KQgRr5e_02 = this.f2356KQgRr5e_0.KQgRr5e_0();
                while (KQgRr5e_02.hasNext()) {
                    KQgRr5e_0((QxJ9d_1) ((QxJ9d_1) KQgRr5e_02.next().getValue()));
                    if (this.f2360QxJ9d_1) {
                        break;
                    }
                }
            }
        } while (this.f2360QxJ9d_1);
        this.f2358KQgRr5e_0 = false;
    }

    public void KQgRr5e_0(Xgtqvk_8 xgtqvk_8, YghfZG_14<? super T> yghfZG_14) {
        KQgRr5e_0("observe");
        if (xgtqvk_8.getLifecycle().KQgRr5e_0() == IFxWkV_5.QxJ9d_1.DESTROYED) {
            return;
        }
        LifecycleBoundObserver lifecycleBoundObserver = new LifecycleBoundObserver(xgtqvk_8, yghfZG_14);
        LiveData<T>.QxJ9d_1 m529KQgRr5e_0 = this.f2356KQgRr5e_0.m529KQgRr5e_0((X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.QxJ9d_1<YghfZG_14<? super T>, LiveData<T>.QxJ9d_1>) yghfZG_14, (YghfZG_14<? super T>) lifecycleBoundObserver);
        if (m529KQgRr5e_0 != null && !m529KQgRr5e_0.KQgRr5e_0(xgtqvk_8)) {
            throw new IllegalArgumentException("Cannot add the same observer with different lifecycles");
        }
        if (m529KQgRr5e_0 != null) {
            return;
        }
        xgtqvk_8.getLifecycle().KQgRr5e_0(lifecycleBoundObserver);
    }

    public void KQgRr5e_0(YghfZG_14<? super T> yghfZG_14) {
        KQgRr5e_0("removeObserver");
        LiveData<T>.QxJ9d_1 m528KQgRr5e_0 = this.f2356KQgRr5e_0.m528KQgRr5e_0((X6FRs_4.QxJ9d_1.KQgRr5e_0.QxJ9d_1.QxJ9d_1<YghfZG_14<? super T>, LiveData<T>.QxJ9d_1>) yghfZG_14);
        if (m528KQgRr5e_0 == null) {
            return;
        }
        m528KQgRr5e_0.KQgRr5e_0();
        m528KQgRr5e_0.KQgRr5e_0(false);
    }

    public void KQgRr5e_0(T t) {
        KQgRr5e_0("setValue");
        this.QxJ9d_1++;
        this.f2359QxJ9d_1 = t;
        QxJ9d_1(null);
    }

    public static void KQgRr5e_0(String str) {
        if (X6FRs_4.QxJ9d_1.KQgRr5e_0.KQgRr5e_0.KQgRr5e_0.KQgRr5e_0().mo527KQgRr5e_0()) {
            return;
        }
        throw new IllegalStateException("Cannot invoke " + str + " on a background thread");
    }
}
