package androidx.preference;

import a3.d0;
import a3.f0;
import a3.i0;
import a3.j0;
import a3.l0;
import a3.m;
import a3.m0;
import a3.n;
import a3.o;
import a3.p;
import a3.p0;
import a3.q;
import a3.s;
import a3.z;
import android.R;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.AbsSavedState;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.s1;
import e.f;
import e.s0;
import f.a;
import java.util.ArrayList;
import java.util.Set;

/* JADX INFO: loaded from: classes.dex */
public class Preference implements Comparable<Preference> {
    public final boolean Q;
    public final boolean R;
    public final boolean S;
    public String T;
    public final Object U;
    public boolean V;
    public boolean W;
    public final boolean X;
    public final boolean Y;
    public final boolean Z;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f3566a;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public final boolean f3567a0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public long f3568b;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public final boolean f3569b0;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f3570c;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public final boolean f3571c0;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public o f3572d;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public final boolean f3573d0;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f3574e;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public final boolean f3575e0;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public CharSequence f3576f;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public int f3577f0;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public CharSequence f3578g;

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    public final int f3579g0;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f3580h;

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    public m f3581h0;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public Drawable f3582i;

    /* JADX INFO: renamed from: i0, reason: collision with root package name */
    public ArrayList f3583i0;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final String f3584j;

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    public PreferenceGroup f3585j0;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public Intent f3586k;

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    public boolean f3587k0;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public String f3588l;

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    public p f3589l0;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public Bundle f3590m;

    /* JADX INFO: renamed from: m0, reason: collision with root package name */
    public q f3591m0;

    @Nullable
    private s mPreferenceDataStore;

    @Nullable
    private f0 mPreferenceManager;

    /* JADX INFO: renamed from: n0, reason: collision with root package name */
    public final f f3592n0;

    public Preference(@NonNull Context context, @Nullable AttributeSet attributeSet, int i10, int i11) {
        this.f3574e = Integer.MAX_VALUE;
        this.Q = true;
        this.R = true;
        this.S = true;
        this.V = true;
        this.W = true;
        this.X = true;
        this.Y = true;
        this.Z = true;
        this.f3569b0 = true;
        this.f3575e0 = true;
        int i12 = m0.preference;
        this.f3577f0 = i12;
        this.f3592n0 = new f(this, 3);
        this.f3566a = context;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, p0.Preference, i10, i11);
        this.f3580h = typedArrayObtainStyledAttributes.getResourceId(p0.Preference_icon, typedArrayObtainStyledAttributes.getResourceId(p0.Preference_android_icon, 0));
        this.f3584j = i0.s.getString(typedArrayObtainStyledAttributes, p0.Preference_key, p0.Preference_android_key);
        this.f3576f = i0.s.getText(typedArrayObtainStyledAttributes, p0.Preference_title, p0.Preference_android_title);
        this.f3578g = i0.s.getText(typedArrayObtainStyledAttributes, p0.Preference_summary, p0.Preference_android_summary);
        this.f3574e = typedArrayObtainStyledAttributes.getInt(p0.Preference_order, typedArrayObtainStyledAttributes.getInt(p0.Preference_android_order, Integer.MAX_VALUE));
        this.f3588l = i0.s.getString(typedArrayObtainStyledAttributes, p0.Preference_fragment, p0.Preference_android_fragment);
        this.f3577f0 = typedArrayObtainStyledAttributes.getResourceId(p0.Preference_layout, typedArrayObtainStyledAttributes.getResourceId(p0.Preference_android_layout, i12));
        this.f3579g0 = typedArrayObtainStyledAttributes.getResourceId(p0.Preference_widgetLayout, typedArrayObtainStyledAttributes.getResourceId(p0.Preference_android_widgetLayout, 0));
        this.Q = typedArrayObtainStyledAttributes.getBoolean(p0.Preference_enabled, typedArrayObtainStyledAttributes.getBoolean(p0.Preference_android_enabled, true));
        boolean z10 = typedArrayObtainStyledAttributes.getBoolean(p0.Preference_selectable, typedArrayObtainStyledAttributes.getBoolean(p0.Preference_android_selectable, true));
        this.R = z10;
        this.S = typedArrayObtainStyledAttributes.getBoolean(p0.Preference_persistent, typedArrayObtainStyledAttributes.getBoolean(p0.Preference_android_persistent, true));
        this.T = i0.s.getString(typedArrayObtainStyledAttributes, p0.Preference_dependency, p0.Preference_android_dependency);
        int i13 = p0.Preference_allowDividerAbove;
        this.Y = typedArrayObtainStyledAttributes.getBoolean(i13, typedArrayObtainStyledAttributes.getBoolean(i13, z10));
        int i14 = p0.Preference_allowDividerBelow;
        this.Z = typedArrayObtainStyledAttributes.getBoolean(i14, typedArrayObtainStyledAttributes.getBoolean(i14, z10));
        int i15 = p0.Preference_defaultValue;
        if (typedArrayObtainStyledAttributes.hasValue(i15)) {
            this.U = onGetDefaultValue(typedArrayObtainStyledAttributes, i15);
        } else {
            int i16 = p0.Preference_android_defaultValue;
            if (typedArrayObtainStyledAttributes.hasValue(i16)) {
                this.U = onGetDefaultValue(typedArrayObtainStyledAttributes, i16);
            }
        }
        this.f3575e0 = typedArrayObtainStyledAttributes.getBoolean(p0.Preference_shouldDisableView, typedArrayObtainStyledAttributes.getBoolean(p0.Preference_android_shouldDisableView, true));
        int i17 = p0.Preference_singleLineTitle;
        boolean zHasValue = typedArrayObtainStyledAttributes.hasValue(i17);
        this.f3567a0 = zHasValue;
        if (zHasValue) {
            this.f3569b0 = typedArrayObtainStyledAttributes.getBoolean(i17, typedArrayObtainStyledAttributes.getBoolean(p0.Preference_android_singleLineTitle, true));
        }
        this.f3571c0 = typedArrayObtainStyledAttributes.getBoolean(p0.Preference_iconSpaceReserved, typedArrayObtainStyledAttributes.getBoolean(p0.Preference_android_iconSpaceReserved, false));
        int i18 = p0.Preference_isPreferenceVisible;
        this.X = typedArrayObtainStyledAttributes.getBoolean(i18, typedArrayObtainStyledAttributes.getBoolean(i18, true));
        int i19 = p0.Preference_enableCopying;
        this.f3573d0 = typedArrayObtainStyledAttributes.getBoolean(i19, typedArrayObtainStyledAttributes.getBoolean(i19, false));
        typedArrayObtainStyledAttributes.recycle();
    }

    public static void w(View view, boolean z10) {
        view.setEnabled(z10);
        if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            for (int childCount = viewGroup.getChildCount() - 1; childCount >= 0; childCount--) {
                w(viewGroup.getChildAt(childCount), z10);
            }
        }
    }

    public final void A() {
        Preference preferenceFindPreferenceInHierarchy;
        ArrayList arrayList;
        String str = this.T;
        if (str == null || (preferenceFindPreferenceInHierarchy = findPreferenceInHierarchy(str)) == null || (arrayList = preferenceFindPreferenceInHierarchy.f3583i0) == null) {
            return;
        }
        arrayList.remove(this);
    }

    public void a(Bundle bundle) {
        Parcelable parcelable;
        if (!(!TextUtils.isEmpty(this.f3584j)) || (parcelable = bundle.getParcelable(this.f3584j)) == null) {
            return;
        }
        this.f3587k0 = false;
        onRestoreInstanceState(parcelable);
        if (!this.f3587k0) {
            throw new IllegalStateException("Derived class did not call super.onRestoreInstanceState()");
        }
    }

    public void assignParent(@Nullable PreferenceGroup preferenceGroup) {
        if (preferenceGroup != null && this.f3585j0 != null) {
            throw new IllegalStateException("This preference already has a parent. You must remove the existing parent before assigning a new one.");
        }
        this.f3585j0 = preferenceGroup;
    }

    public void b(Bundle bundle) {
        if (!TextUtils.isEmpty(this.f3584j)) {
            this.f3587k0 = false;
            Parcelable parcelableOnSaveInstanceState = onSaveInstanceState();
            if (!this.f3587k0) {
                throw new IllegalStateException("Derived class did not call super.onSaveInstanceState()");
            }
            if (parcelableOnSaveInstanceState != null) {
                bundle.putParcelable(this.f3584j, parcelableOnSaveInstanceState);
            }
        }
    }

    public long c() {
        return this.f3568b;
    }

    @Override // java.lang.Comparable
    public final int compareTo(Preference preference) {
        Preference preference2 = preference;
        int i10 = this.f3574e;
        int i11 = preference2.f3574e;
        if (i10 != i11) {
            return i10 - i11;
        }
        CharSequence charSequence = this.f3576f;
        CharSequence charSequence2 = preference2.f3576f;
        if (charSequence == charSequence2) {
            return 0;
        }
        if (charSequence == null) {
            return 1;
        }
        if (charSequence2 == null) {
            return -1;
        }
        return charSequence.toString().compareToIgnoreCase(preference2.f3576f.toString());
    }

    public final boolean d(boolean z10) {
        if (!y()) {
            return z10;
        }
        getPreferenceDataStore();
        return this.mPreferenceManager.getSharedPreferences().getBoolean(this.f3584j, z10);
    }

    public final int e(int i10) {
        if (!y()) {
            return i10;
        }
        getPreferenceDataStore();
        return this.mPreferenceManager.getSharedPreferences().getInt(this.f3584j, i10);
    }

    public final String f(String str) {
        if (!y()) {
            return str;
        }
        getPreferenceDataStore();
        return this.mPreferenceManager.getSharedPreferences().getString(this.f3584j, str);
    }

    @Nullable
    public <T extends Preference> T findPreferenceInHierarchy(@NonNull String str) {
        f0 f0Var = this.mPreferenceManager;
        if (f0Var == null) {
            return null;
        }
        return (T) f0Var.findPreference(str);
    }

    public final Set g(Set set) {
        if (!y()) {
            return set;
        }
        getPreferenceDataStore();
        return this.mPreferenceManager.getSharedPreferences().getStringSet(this.f3584j, set);
    }

    @Nullable
    public String getDependency() {
        return this.T;
    }

    @Nullable
    public String getFragment() {
        return this.f3588l;
    }

    @Nullable
    public Drawable getIcon() {
        int i10;
        if (this.f3582i == null && (i10 = this.f3580h) != 0) {
            this.f3582i = a.getDrawable(this.f3566a, i10);
        }
        return this.f3582i;
    }

    @Nullable
    public Intent getIntent() {
        return this.f3586k;
    }

    @Nullable
    public n getOnPreferenceChangeListener() {
        return null;
    }

    @Nullable
    public o getOnPreferenceClickListener() {
        return this.f3572d;
    }

    @Nullable
    public PreferenceGroup getParent() {
        return this.f3585j0;
    }

    @Nullable
    public s getPreferenceDataStore() {
        f0 f0Var = this.mPreferenceManager;
        if (f0Var != null) {
            f0Var.getPreferenceDataStore();
        }
        return null;
    }

    @Nullable
    public SharedPreferences getSharedPreferences() {
        if (this.mPreferenceManager == null) {
            return null;
        }
        getPreferenceDataStore();
        return this.mPreferenceManager.getSharedPreferences();
    }

    @Nullable
    public CharSequence getSummary() {
        return getSummaryProvider() != null ? getSummaryProvider().provideSummary(this) : this.f3578g;
    }

    @Nullable
    public final q getSummaryProvider() {
        return this.f3591m0;
    }

    @Nullable
    public CharSequence getTitle() {
        return this.f3576f;
    }

    public final f0 h() {
        return this.mPreferenceManager;
    }

    public boolean i() {
        return this.Q && this.V && this.W;
    }

    public void j() {
        m mVar = this.f3581h0;
        if (mVar != null) {
            z zVar = (z) mVar;
            int iIndexOf = zVar.f291c.indexOf(this);
            if (iIndexOf != -1) {
                zVar.notifyItemChanged(iIndexOf, this);
            }
        }
    }

    public void k(boolean z10) {
        ArrayList arrayList = this.f3583i0;
        if (arrayList == null) {
            return;
        }
        int size = arrayList.size();
        for (int i10 = 0; i10 < size; i10++) {
            Preference preference = (Preference) arrayList.get(i10);
            if (preference.V == z10) {
                preference.V = !z10;
                preference.k(preference.x());
                preference.j();
            }
        }
    }

    public void l() {
        v();
    }

    public final void m(f0 f0Var) {
        long j10;
        this.mPreferenceManager = f0Var;
        if (!this.f3570c) {
            synchronized (f0Var) {
                j10 = f0Var.f250b;
                f0Var.f250b = 1 + j10;
            }
            this.f3568b = j10;
        }
        getPreferenceDataStore();
        if (y() && getSharedPreferences().contains(this.f3584j)) {
            onSetInitialValue(null);
            return;
        }
        Object obj = this.U;
        if (obj != null) {
            onSetInitialValue(obj);
        }
    }

    public void n(i0 i0Var) {
        Integer numValueOf;
        View view = i0Var.itemView;
        view.setOnClickListener(this.f3592n0);
        view.setId(0);
        TextView textView = (TextView) i0Var.a(R.id.summary);
        if (textView != null) {
            CharSequence summary = getSummary();
            if (TextUtils.isEmpty(summary)) {
                textView.setVisibility(8);
                numValueOf = null;
            } else {
                textView.setText(summary);
                textView.setVisibility(0);
                numValueOf = Integer.valueOf(textView.getCurrentTextColor());
            }
        } else {
            numValueOf = null;
        }
        TextView textView2 = (TextView) i0Var.a(R.id.title);
        boolean z10 = this.R;
        if (textView2 != null) {
            CharSequence title = getTitle();
            if (TextUtils.isEmpty(title)) {
                textView2.setVisibility(8);
            } else {
                textView2.setText(title);
                textView2.setVisibility(0);
                if (this.f3567a0) {
                    textView2.setSingleLine(this.f3569b0);
                }
                if (!z10 && i() && numValueOf != null) {
                    textView2.setTextColor(numValueOf.intValue());
                }
            }
        }
        ImageView imageView = (ImageView) i0Var.a(R.id.icon);
        boolean z11 = this.f3571c0;
        if (imageView != null) {
            int i10 = this.f3580h;
            if (i10 != 0 || this.f3582i != null) {
                if (this.f3582i == null) {
                    this.f3582i = a.getDrawable(this.f3566a, i10);
                }
                Drawable drawable = this.f3582i;
                if (drawable != null) {
                    imageView.setImageDrawable(drawable);
                }
            }
            if (this.f3582i != null) {
                imageView.setVisibility(0);
            } else {
                imageView.setVisibility(z11 ? 4 : 8);
            }
        }
        View viewA = i0Var.a(l0.icon_frame);
        if (viewA == null) {
            viewA = i0Var.a(R.id.icon_frame);
        }
        if (viewA != null) {
            if (this.f3582i != null) {
                viewA.setVisibility(0);
            } else {
                viewA.setVisibility(z11 ? 4 : 8);
            }
        }
        if (this.f3575e0) {
            w(view, i());
        } else {
            w(view, true);
        }
        view.setFocusable(z10);
        view.setClickable(z10);
        i0Var.f268d = this.Y;
        i0Var.f269e = this.Z;
        boolean z12 = this.f3573d0;
        if (z12 && this.f3589l0 == null) {
            this.f3589l0 = new p(this);
        }
        view.setOnCreateContextMenuListener(z12 ? this.f3589l0 : null);
        view.setLongClickable(z12);
        if (!z12 || z10) {
            return;
        }
        s1.setBackground(view, null);
    }

    public void o() {
    }

    @Nullable
    public Object onGetDefaultValue(@NonNull TypedArray typedArray, int i10) {
        return null;
    }

    public void onRestoreInstanceState(@Nullable Parcelable parcelable) {
        this.f3587k0 = true;
        if (parcelable != AbsSavedState.EMPTY_STATE && parcelable != null) {
            throw new IllegalArgumentException("Wrong state class -- expecting Preference State");
        }
    }

    @Nullable
    public Parcelable onSaveInstanceState() {
        this.f3587k0 = true;
        return AbsSavedState.EMPTY_STATE;
    }

    public void onSetInitialValue(@Nullable Object obj) {
    }

    public void p() {
        A();
    }

    @Nullable
    public Bundle peekExtras() {
        return this.f3590m;
    }

    public void q(View view) {
        d0 onPreferenceTreeClickListener;
        if (i() && this.R) {
            o();
            o oVar = this.f3572d;
            if (oVar != null) {
                xyz.stream.utils.f fVar = (xyz.stream.utils.f) oVar;
                ((PreferenceGroup) fVar.f36132b).f3615t0 = Integer.MAX_VALUE;
                z zVar = (z) fVar.f36133c;
                Handler handler = zVar.f293e;
                s0 s0Var = zVar.f294f;
                handler.removeCallbacks(s0Var);
                handler.post(s0Var);
                ((PreferenceGroup) fVar.f36132b).getOnExpandButtonClickListener();
                return;
            }
            f0 f0Var = this.mPreferenceManager;
            if (f0Var != null && (onPreferenceTreeClickListener = f0Var.getOnPreferenceTreeClickListener()) != null) {
                PreferenceFragment preferenceFragment = (PreferenceFragment) onPreferenceTreeClickListener;
                if (getFragment() != null) {
                    preferenceFragment.getActivity();
                }
            }
            Intent intent = this.f3586k;
            if (intent != null) {
                this.f3566a.startActivity(intent);
            }
        }
    }

    public final void r(boolean z10) {
        if (y() && z10 != d(!z10)) {
            getPreferenceDataStore();
            SharedPreferences.Editor editor = this.mPreferenceManager.getEditor();
            editor.putBoolean(this.f3584j, z10);
            z(editor);
        }
    }

    public final void s(int i10) {
        if (y() && i10 != e(~i10)) {
            getPreferenceDataStore();
            SharedPreferences.Editor editor = this.mPreferenceManager.getEditor();
            editor.putInt(this.f3584j, i10);
            z(editor);
        }
    }

    public void setDependency(@Nullable String str) {
        A();
        this.T = str;
        v();
    }

    public void setFragment(@Nullable String str) {
        this.f3588l = str;
    }

    public void setIcon(@Nullable Drawable drawable) {
        if (this.f3582i != drawable) {
            this.f3582i = drawable;
            this.f3580h = 0;
            j();
        }
    }

    public void setIntent(@Nullable Intent intent) {
        this.f3586k = intent;
    }

    public final void setOnPreferenceChangeInternalListener(@Nullable m mVar) {
        this.f3581h0 = mVar;
    }

    public void setOnPreferenceChangeListener(@Nullable n nVar) {
    }

    public void setOnPreferenceClickListener(@Nullable o oVar) {
        this.f3572d = oVar;
    }

    public void setPreferenceDataStore(@Nullable s sVar) {
    }

    public void setSummary(@Nullable CharSequence charSequence) {
        if (getSummaryProvider() != null) {
            throw new IllegalStateException("Preference already has a SummaryProvider set.");
        }
        if (TextUtils.equals(this.f3578g, charSequence)) {
            return;
        }
        this.f3578g = charSequence;
        j();
    }

    public final void setSummaryProvider(@Nullable q qVar) {
        this.f3591m0 = qVar;
        j();
    }

    public void setTitle(@Nullable CharSequence charSequence) {
        if (TextUtils.equals(charSequence, this.f3576f)) {
            return;
        }
        this.f3576f = charSequence;
        j();
    }

    public final void t(String str) {
        if (y() && !TextUtils.equals(str, f(null))) {
            getPreferenceDataStore();
            SharedPreferences.Editor editor = this.mPreferenceManager.getEditor();
            editor.putString(this.f3584j, str);
            z(editor);
        }
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder();
        CharSequence title = getTitle();
        if (!TextUtils.isEmpty(title)) {
            sb.append(title);
            sb.append(' ');
        }
        CharSequence summary = getSummary();
        if (!TextUtils.isEmpty(summary)) {
            sb.append(summary);
            sb.append(' ');
        }
        if (sb.length() > 0) {
            sb.setLength(sb.length() - 1);
        }
        return sb.toString();
    }

    public final void u(Set set) {
        if (y() && !set.equals(g(null))) {
            getPreferenceDataStore();
            SharedPreferences.Editor editor = this.mPreferenceManager.getEditor();
            editor.putStringSet(this.f3584j, set);
            z(editor);
        }
    }

    public final void v() {
        if (TextUtils.isEmpty(this.T)) {
            return;
        }
        Preference preferenceFindPreferenceInHierarchy = findPreferenceInHierarchy(this.T);
        if (preferenceFindPreferenceInHierarchy == null) {
            throw new IllegalStateException("Dependency \"" + this.T + "\" not found for preference \"" + this.f3584j + "\" (title: \"" + ((Object) this.f3576f) + "\"");
        }
        if (preferenceFindPreferenceInHierarchy.f3583i0 == null) {
            preferenceFindPreferenceInHierarchy.f3583i0 = new ArrayList();
        }
        preferenceFindPreferenceInHierarchy.f3583i0.add(this);
        boolean zX = preferenceFindPreferenceInHierarchy.x();
        if (this.V == zX) {
            this.V = !zX;
            k(x());
            j();
        }
    }

    public boolean x() {
        return !i();
    }

    public final boolean y() {
        return this.mPreferenceManager != null && this.S && (TextUtils.isEmpty(this.f3584j) ^ true);
    }

    public final void z(SharedPreferences.Editor editor) {
        if (!this.mPreferenceManager.f251c) {
            editor.apply();
        }
    }

    public Preference(@NonNull Context context, @Nullable AttributeSet attributeSet, int i10) {
        this(context, attributeSet, i10, 0);
    }

    public Preference(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, i0.s.a(context, j0.preferenceStyle, R.attr.preferenceStyle));
    }
}
