package androidx.preference;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import androidx.preference.Preference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import p037.p041.p042.LayoutInflaterFactory2C1494;
import p037.p057.C1729;
import p037.p106.C2287;
import p037.p106.C2300;

/* JADX INFO: loaded from: classes.dex */
public abstract class PreferenceGroup extends Preference {

    /* JADX INFO: renamed from: ࢦ, reason: contains not printable characters */
    public final C1729<String, Long> f1049;

    /* JADX INFO: renamed from: ࢧ, reason: contains not printable characters */
    public final Handler f1050;

    /* JADX INFO: renamed from: ࢨ, reason: contains not printable characters */
    public List<Preference> f1051;

    /* JADX INFO: renamed from: ࢩ, reason: contains not printable characters */
    public boolean f1052;

    /* JADX INFO: renamed from: ࢪ, reason: contains not printable characters */
    public int f1053;

    /* JADX INFO: renamed from: ࢫ, reason: contains not printable characters */
    public boolean f1054;

    /* JADX INFO: renamed from: ࢬ, reason: contains not printable characters */
    public int f1055;

    /* JADX INFO: renamed from: ೱ, reason: contains not printable characters */
    public InterfaceC0167 f1056;

    /* JADX INFO: renamed from: ೲ, reason: contains not printable characters */
    public final Runnable f1057;

    /* JADX INFO: renamed from: androidx.preference.PreferenceGroup$֏, reason: contains not printable characters */
    public class RunnableC0166 implements Runnable {
        public RunnableC0166() {
        }

        @Override // java.lang.Runnable
        public void run() {
            synchronized (this) {
                PreferenceGroup.this.f1049.clear();
            }
        }
    }

    /* JADX INFO: renamed from: androidx.preference.PreferenceGroup$ؠ, reason: contains not printable characters */
    public interface InterfaceC0167 {
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        void m415();
    }

    /* JADX INFO: renamed from: androidx.preference.PreferenceGroup$ހ, reason: contains not printable characters */
    public interface InterfaceC0168 {
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        int mo416(Preference preference);

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        int mo417(String str);
    }

    /* JADX INFO: renamed from: androidx.preference.PreferenceGroup$ށ, reason: contains not printable characters */
    public static class C0169 extends Preference.C0160 {
        public static final Parcelable.Creator<C0169> CREATOR = new C0170();

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public int f1059;

        /* JADX INFO: renamed from: androidx.preference.PreferenceGroup$ށ$֏, reason: contains not printable characters */
        public static class C0170 implements Parcelable.Creator<C0169> {
            @Override // android.os.Parcelable.Creator
            public C0169 createFromParcel(Parcel parcel) {
                return new C0169(parcel);
            }

            @Override // android.os.Parcelable.Creator
            public C0169[] newArray(int i) {
                return new C0169[i];
            }
        }

        public C0169(Parcel parcel) {
            super(parcel);
            this.f1059 = parcel.readInt();
        }

        public C0169(Parcelable parcelable, int i) {
            super(parcelable);
            this.f1059 = i;
        }

        @Override // android.view.AbsSavedState, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeInt(this.f1059);
        }
    }

    public PreferenceGroup(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public PreferenceGroup(Context context, AttributeSet attributeSet, int i) {
        this(context, attributeSet, i, 0);
    }

    public PreferenceGroup(Context context, AttributeSet attributeSet, int i, int i2) {
        super(context, attributeSet, i, i2);
        this.f1049 = new C1729<>();
        this.f1050 = new Handler();
        this.f1052 = true;
        this.f1053 = 0;
        this.f1054 = false;
        this.f1055 = Integer.MAX_VALUE;
        this.f1056 = null;
        this.f1057 = new RunnableC0166();
        this.f1051 = new ArrayList();
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, C2300.PreferenceGroup, i, i2);
        int i3 = C2300.PreferenceGroup_orderingFromXml;
        this.f1052 = LayoutInflaterFactory2C1494.C1505.m2959(typedArrayObtainStyledAttributes, i3, i3, true);
        if (typedArrayObtainStyledAttributes.hasValue(C2300.PreferenceGroup_initialExpandedChildrenCount)) {
            int i4 = C2300.PreferenceGroup_initialExpandedChildrenCount;
            m410(typedArrayObtainStyledAttributes.getInt(i4, typedArrayObtainStyledAttributes.getInt(i4, Integer.MAX_VALUE)));
        }
        typedArrayObtainStyledAttributes.recycle();
    }

    @Override // androidx.preference.Preference
    /* JADX INFO: renamed from: ֏ */
    public void mo382(Bundle bundle) {
        super.mo382(bundle);
        int iM411 = m411();
        for (int i = 0; i < iM411; i++) {
            m408(i).mo382(bundle);
        }
    }

    @Override // androidx.preference.Preference
    /* JADX INFO: renamed from: ֏ */
    public void mo366(Parcelable parcelable) {
        if (parcelable == null || !parcelable.getClass().equals(C0169.class)) {
            super.mo366(parcelable);
            return;
        }
        C0169 c0169 = (C0169) parcelable;
        this.f1055 = c0169.f1059;
        super.mo366(c0169.getSuperState());
    }

    /* JADX WARN: Removed duplicated region for block: B:39:0x00a5  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean m406(Preference preference) {
        long jM4335;
        if (this.f1051.contains(preference)) {
            return true;
        }
        if (preference.f1018 != null) {
            PreferenceGroup preferenceGroup = this;
            while (true) {
                PreferenceGroup preferenceGroup2 = preferenceGroup.f1042;
                if (preferenceGroup2 == null) {
                    break;
                }
                preferenceGroup = preferenceGroup2;
            }
            String str = preference.f1018;
            if (preferenceGroup.m409((CharSequence) str) != null) {
                Log.e("PreferenceGroup", "Found duplicated key: \"" + str + "\". This can cause unintended behaviour, please use unique keys for every preference.");
            }
        }
        if (preference.f1012 == Integer.MAX_VALUE) {
            if (this.f1052) {
                int i = this.f1053;
                this.f1053 = i + 1;
                preference.m387(i);
            }
            if (preference instanceof PreferenceGroup) {
                ((PreferenceGroup) preference).f1052 = this.f1052;
            }
        }
        int iBinarySearch = Collections.binarySearch(this.f1051, preference);
        if (iBinarySearch < 0) {
            iBinarySearch = (iBinarySearch * (-1)) - 1;
        }
        boolean zMo370 = mo370();
        if (preference.f1029 == zMo370) {
            preference.f1029 = !zMo370;
            preference.mo390(preference.mo370());
            preference.mo364();
        }
        synchronized (this) {
            this.f1051.add(iBinarySearch, preference);
        }
        C2287 c2287 = this.f1007;
        String str2 = preference.f1018;
        if (str2 == null) {
            jM4335 = c2287.m4335();
        } else {
            if (this.f1049.m3387(str2) >= 0) {
                jM4335 = this.f1049.getOrDefault(str2, null).longValue();
                this.f1049.remove(str2);
            }
        }
        preference.f1009 = jM4335;
        preference.f1010 = true;
        try {
            preference.m385(c2287);
            preference.f1010 = false;
            if (preference.f1042 != null) {
                throw new IllegalStateException("This preference already has a parent. You must remove the existing parent before assigning a new one.");
            }
            preference.f1042 = this;
            if (this.f1054) {
                preference.mo402();
            }
            m401();
            return true;
        } catch (Throwable th) {
            preference.f1010 = false;
            throw th;
        }
    }

    @Override // androidx.preference.Preference
    /* JADX INFO: renamed from: ؠ */
    public void mo388(Bundle bundle) {
        super.mo388(bundle);
        int iM411 = m411();
        for (int i = 0; i < iM411; i++) {
            m408(i).mo388(bundle);
        }
    }

    @Override // androidx.preference.Preference
    /* JADX INFO: renamed from: ؠ */
    public void mo390(boolean z) {
        super.mo390(z);
        int iM411 = m411();
        for (int i = 0; i < iM411; i++) {
            Preference preferenceM408 = m408(i);
            if (preferenceM408.f1029 == z) {
                preferenceM408.f1029 = !z;
                preferenceM408.mo390(preferenceM408.mo370());
                preferenceM408.mo364();
            }
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final boolean m407(Preference preference) {
        boolean zRemove;
        synchronized (this) {
            preference.m405();
            if (preference.f1042 == this) {
                preference.f1042 = null;
            }
            zRemove = this.f1051.remove(preference);
            if (zRemove) {
                String str = preference.f1018;
                if (str != null) {
                    this.f1049.put(str, Long.valueOf(preference.mo397()));
                    this.f1050.removeCallbacks(this.f1057);
                    this.f1050.post(this.f1057);
                }
                if (this.f1054) {
                    preference.mo403();
                }
            }
        }
        return zRemove;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public Preference m408(int i) {
        return this.f1051.get(i);
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public <T extends Preference> T m409(CharSequence charSequence) {
        T t;
        if (charSequence == null) {
            throw new IllegalArgumentException("Key cannot be null");
        }
        if (TextUtils.equals(this.f1018, charSequence)) {
            return this;
        }
        int iM411 = m411();
        for (int i = 0; i < iM411; i++) {
            PreferenceGroup preferenceGroup = (T) m408(i);
            if (TextUtils.equals(preferenceGroup.f1018, charSequence)) {
                return preferenceGroup;
            }
            if ((preferenceGroup instanceof PreferenceGroup) && (t = (T) preferenceGroup.m409(charSequence)) != null) {
                return t;
            }
        }
        return null;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public void m410(int i) {
        if (i != Integer.MAX_VALUE && !m399()) {
            Log.e("PreferenceGroup", getClass().getSimpleName() + " should have a key defined if it contains an expandable preference");
        }
        this.f1055 = i;
    }

    @Override // androidx.preference.Preference
    /* JADX INFO: renamed from: ގ */
    public void mo402() {
        super.mo402();
        this.f1054 = true;
        int iM411 = m411();
        for (int i = 0; i < iM411; i++) {
            m408(i).mo402();
        }
    }

    @Override // androidx.preference.Preference
    /* JADX INFO: renamed from: ސ */
    public void mo403() {
        m405();
        this.f1054 = false;
        int iM411 = m411();
        for (int i = 0; i < iM411; i++) {
            m408(i).mo403();
        }
    }

    @Override // androidx.preference.Preference
    /* JADX INFO: renamed from: ޑ */
    public Parcelable mo369() {
        return new C0169(super.mo369(), this.f1055);
    }

    /* JADX INFO: renamed from: ޕ, reason: contains not printable characters */
    public int m411() {
        return this.f1051.size();
    }

    /* JADX INFO: renamed from: ޖ, reason: contains not printable characters */
    public boolean mo412() {
        return true;
    }

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public void m413() {
        synchronized (this) {
            List<Preference> list = this.f1051;
            for (int size = list.size() - 1; size >= 0; size--) {
                m407(list.get(0));
            }
        }
        m401();
    }

    /* JADX INFO: renamed from: ޘ, reason: contains not printable characters */
    public void m414() {
        synchronized (this) {
            Collections.sort(this.f1051);
        }
    }
}
