package androidx.lifecycle;

import androidx.lifecycle.Lifecycle;
import java.util.Map;
import ῲ.ʬ.K.ῲ.C1499;
import ῲ.ʬ.K.K.C1510;
import ῲ.ؿ.AbstractC1574;
import ῲ.ؿ.AbstractC1583;
import ῲ.ؿ.AbstractC1587;
import ῲ.ؿ.C1584;
import ῲ.ᓣ.K.C1690;

public abstract class LiveData<T> {

    /* renamed from: 㳳  reason: contains not printable characters */
    public static final Object f1334 = new Object();

    /* renamed from: ʬ  reason: contains not printable characters */
    public int f1335 = 0;

    /* renamed from: ඓ  reason: contains not printable characters */
    public volatile Object f1336;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final Runnable f1337;

    /* renamed from: ῲ  reason: contains not printable characters */
    public C1499<AbstractC1587<? super T>, LiveData<T>.AbstractC0191> f1338 = new C1499<>();

    /* renamed from: ⁱ  reason: contains not printable characters */
    public boolean f1339;

    /* renamed from: K  reason: contains not printable characters */
    public final Object f1340 = new Object();

    /* renamed from: 㴹  reason: contains not printable characters */
    public int f1341;

    /* renamed from: 㸾  reason: contains not printable characters */
    public volatile Object f1342;

    /* renamed from: 㿎  reason: contains not printable characters */
    public boolean f1343;

    /* renamed from: androidx.lifecycle.LiveData$ῲ  reason: contains not printable characters */
    public abstract class AbstractC0191 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public int f1346 = -1;

        /* renamed from: ῲ  reason: contains not printable characters */
        public boolean f1347;

        /* renamed from: K  reason: contains not printable characters */
        public final AbstractC1587<? super T> f1348;

        public AbstractC0191(AbstractC1587<? super T> r2) {
            this.f1348 = r2;
        }

        /* renamed from: ῲ  reason: contains not printable characters */
        public abstract boolean m705();

        /* renamed from: K  reason: contains not printable characters */
        public void m706() {
        }

        /* renamed from: K  reason: contains not printable characters */
        public void m707(boolean z) {
            if (z != this.f1347) {
                this.f1347 = z;
                int i = 1;
                boolean z2 = LiveData.this.f1335 == 0;
                LiveData liveData = LiveData.this;
                int i2 = liveData.f1335;
                if (!this.f1347) {
                    i = -1;
                }
                liveData.f1335 = i2 + i;
                if (z2 && this.f1347) {
                    LiveData.this.m696();
                }
                LiveData liveData2 = LiveData.this;
                if (liveData2.f1335 == 0 && !this.f1347) {
                    liveData2.m693();
                }
                if (this.f1347) {
                    LiveData.this.m694((LiveData<T>.AbstractC0191) this);
                }
            }
        }

        /* renamed from: K  reason: contains not printable characters */
        public boolean m708(AbstractC1574 r1) {
            return false;
        }
    }

    /* renamed from: androidx.lifecycle.LiveData$K  reason: contains not printable characters */
    public class RunnableC0192 implements Runnable {
        public RunnableC0192() {
        }

        /* JADX DEBUG: Multi-variable search result rejected for r0v2, resolved type: androidx.lifecycle.LiveData */
        /* JADX WARN: Multi-variable type inference failed */
        public void run() {
            Object obj;
            synchronized (LiveData.this.f1340) {
                obj = LiveData.this.f1336;
                LiveData.this.f1336 = LiveData.f1334;
            }
            LiveData.this.m695(obj);
        }
    }

    public LiveData() {
        Object obj = f1334;
        this.f1342 = obj;
        this.f1336 = obj;
        this.f1341 = -1;
        this.f1337 = new RunnableC0192();
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m693() {
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m694(LiveData<T>.AbstractC0191 r4) {
        if (this.f1339) {
            this.f1343 = true;
            return;
        }
        this.f1339 = true;
        do {
            this.f1343 = false;
            if (r4 == null) {
                C1499<K, V>.C1505 r1 = this.f1338.m3832();
                while (r1.hasNext()) {
                    m697((LiveData<T>.AbstractC0191) ((AbstractC0191) ((Map.Entry) r1.next()).getValue()));
                    if (this.f1343) {
                        break;
                    }
                }
            } else {
                m697(r4);
                r4 = null;
            }
        } while (this.f1343);
        this.f1339 = false;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m696() {
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m697(LiveData<T>.AbstractC0191 r4) {
        if (r4.f1347) {
            if (!r4.m705()) {
                r4.m707(false);
                return;
            }
            int i = r4.f1346;
            int i2 = this.f1341;
            if (i < i2) {
                r4.f1346 = i2;
                AbstractC1587<? super T> r42 = r4.f1348;
                C1690.C1693 r43 = (C1690.C1693) r42;
                r43.f5962.m4344(r43.f5963, this.f1342);
                r43.f5961 = true;
            }
        }
    }

    public class LifecycleBoundObserver extends LiveData<T>.AbstractC0191 implements AbstractC1583 {

        /* renamed from: ඓ  reason: contains not printable characters */
        public final AbstractC1574 f1344;

        public LifecycleBoundObserver(AbstractC1574 r2, AbstractC1587<? super T> r3) {
            super(r3);
            this.f1344 = r2;
        }

        @Override // androidx.lifecycle.LiveData.AbstractC0191
        /* renamed from: ῲ  reason: contains not printable characters */
        public boolean m701() {
            return ((C1584) this.f1344.getLifecycle()).f5751.isAtLeast(Lifecycle.State.STARTED);
        }

        @Override // ῲ.ؿ.AbstractC1569
        /* renamed from: K  reason: contains not printable characters */
        public void m703(AbstractC1574 r1, Lifecycle.Event event) {
            if (((C1584) this.f1344.getLifecycle()).f5751 == Lifecycle.State.DESTROYED) {
                LiveData.this.m700((AbstractC1587) this.f1348);
            } else {
                m707(m701());
            }
        }

        @Override // androidx.lifecycle.LiveData.AbstractC0191
        /* renamed from: K  reason: contains not printable characters */
        public boolean m704(AbstractC1574 r2) {
            return this.f1344 == r2;
        }

        @Override // androidx.lifecycle.LiveData.AbstractC0191
        /* renamed from: K  reason: contains not printable characters */
        public void m702() {
            ((C1584) this.f1344.getLifecycle()).f5753.remove(this);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m699(AbstractC1574 r3, AbstractC1587<? super T> r4) {
        m692("observe");
        if (((C1584) r3.getLifecycle()).f5751 != Lifecycle.State.DESTROYED) {
            LifecycleBoundObserver lifecycleBoundObserver = new LifecycleBoundObserver(r3, r4);
            LiveData<T>.AbstractC0191 r42 = this.f1338.m3829(r4, lifecycleBoundObserver);
            if (r42 != null && !r42.m708(r3)) {
                throw new IllegalArgumentException("Cannot add the same observer with different lifecycles");
            } else if (r42 == null) {
                r3.getLifecycle().m690(lifecycleBoundObserver);
            }
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m695(T t) {
        m692("setValue");
        this.f1341++;
        this.f1342 = t;
        m694((LiveData<T>.AbstractC0191) null);
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m700(AbstractC1587<? super T> r2) {
        m692("removeObserver");
        LiveData<T>.AbstractC0191 remove = this.f1338.remove(r2);
        if (remove != null) {
            remove.m706();
            remove.m707(false);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m698(T t) {
        boolean z;
        synchronized (this.f1340) {
            z = this.f1336 == f1334;
            this.f1336 = t;
        }
        if (z) {
            C1510.m3851().f5560.m3845(this.f1337);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static void m692(String str) {
        if (!C1510.m3851().m3854()) {
            throw new IllegalStateException("Cannot invoke " + str + " on a background" + " thread");
        }
    }
}
