package androidx.preference;

import a3.b;
import a3.b0;
import a3.c0;
import a3.d0;
import a3.f0;
import a3.h0;
import a3.j0;
import a3.l0;
import a3.m0;
import a3.o0;
import a3.p0;
import a3.u;
import a3.v;
import a3.z;
import android.R;
import android.app.Fragment;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.XmlRes;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.gms.measurement.internal.u1;
import e.s0;
import i0.s;

/* JADX INFO: loaded from: classes.dex */
@Deprecated
public abstract class PreferenceFragment extends Fragment implements d0, b0, c0, b {

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

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

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

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

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final v f3601a = new v(this);

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f3607g = m0.preference_list_fragment;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final u f3608h = new u(this);

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final s0 f3609i = new s0(this, 11);

    @Override // a3.b
    public final Preference findPreference(CharSequence charSequence) {
        f0 f0Var = this.f3602b;
        if (f0Var == null) {
            return null;
        }
        return f0Var.findPreference(charSequence);
    }

    @Override // android.app.Fragment
    public void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        TypedValue typedValue = new TypedValue();
        getActivity().getTheme().resolveAttribute(j0.preferenceTheme, typedValue, true);
        int i10 = typedValue.resourceId;
        if (i10 == 0) {
            i10 = o0.PreferenceThemeOverlay;
        }
        ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(getActivity(), i10);
        this.f3606f = contextThemeWrapper;
        f0 f0Var = new f0(contextThemeWrapper);
        this.f3602b = f0Var;
        f0Var.setOnNavigateToScreenListener(this);
        onCreatePreferences(bundle, getArguments() != null ? getArguments().getString("androidx.preference.PreferenceFragmentCompat.PREFERENCE_ROOT") : null);
    }

    @Deprecated
    public abstract void onCreatePreferences(@Nullable Bundle bundle, String str);

    @NonNull
    @Deprecated
    public RecyclerView onCreateRecyclerView(@NonNull LayoutInflater layoutInflater, @NonNull ViewGroup viewGroup, @Nullable Bundle bundle) {
        RecyclerView recyclerView;
        if (this.f3606f.getPackageManager().hasSystemFeature("android.hardware.type.automotive") && (recyclerView = (RecyclerView) viewGroup.findViewById(l0.recycler_view)) != null) {
            return recyclerView;
        }
        RecyclerView recyclerView2 = (RecyclerView) layoutInflater.inflate(m0.preference_recyclerview, viewGroup, false);
        getActivity();
        recyclerView2.setLayoutManager(new LinearLayoutManager());
        recyclerView2.setAccessibilityDelegateCompat(new h0(recyclerView2));
        return recyclerView2;
    }

    @Override // android.app.Fragment
    @NonNull
    public View onCreateView(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
        ContextThemeWrapper contextThemeWrapper = this.f3606f;
        TypedArray typedArrayObtainStyledAttributes = contextThemeWrapper.obtainStyledAttributes(null, p0.PreferenceFragment, s.a(contextThemeWrapper, j0.preferenceFragmentStyle, R.attr.preferenceFragmentStyle), 0);
        this.f3607g = typedArrayObtainStyledAttributes.getResourceId(p0.PreferenceFragment_android_layout, this.f3607g);
        Drawable drawable = typedArrayObtainStyledAttributes.getDrawable(p0.PreferenceFragment_android_divider);
        int dimensionPixelSize = typedArrayObtainStyledAttributes.getDimensionPixelSize(p0.PreferenceFragment_android_dividerHeight, -1);
        boolean z10 = typedArrayObtainStyledAttributes.getBoolean(p0.PreferenceFragment_allowDividerAfterLastItem, true);
        typedArrayObtainStyledAttributes.recycle();
        LayoutInflater layoutInflaterCloneInContext = layoutInflater.cloneInContext(this.f3606f);
        View viewInflate = layoutInflaterCloneInContext.inflate(this.f3607g, viewGroup, false);
        View viewFindViewById = viewInflate.findViewById(R.id.list_container);
        if (!(viewFindViewById instanceof ViewGroup)) {
            throw new RuntimeException("Content has view with id attribute 'android.R.id.list_container' that is not a ViewGroup class");
        }
        ViewGroup viewGroup2 = (ViewGroup) viewFindViewById;
        RecyclerView recyclerViewOnCreateRecyclerView = onCreateRecyclerView(layoutInflaterCloneInContext, viewGroup2, bundle);
        if (recyclerViewOnCreateRecyclerView == null) {
            throw new RuntimeException("Could not create RecyclerView");
        }
        this.f3603c = recyclerViewOnCreateRecyclerView;
        v vVar = this.f3601a;
        recyclerViewOnCreateRecyclerView.addItemDecoration(vVar);
        setDivider(drawable);
        if (dimensionPixelSize != -1) {
            vVar.f282b = dimensionPixelSize;
            vVar.f284d.f3603c.invalidateItemDecorations();
        }
        vVar.f283c = z10;
        if (this.f3603c.getParent() == null) {
            viewGroup2.addView(this.f3603c);
        }
        this.f3608h.post(this.f3609i);
        return viewInflate;
    }

    @Override // android.app.Fragment
    public final void onDestroyView() {
        PreferenceScreen preferenceScreen;
        s0 s0Var = this.f3609i;
        u uVar = this.f3608h;
        uVar.removeCallbacks(s0Var);
        uVar.removeMessages(1);
        if (this.f3604d && (preferenceScreen = this.f3602b.f253e) != null) {
            preferenceScreen.p();
        }
        this.f3603c = null;
        super.onDestroyView();
    }

    @Override // android.app.Fragment
    public final void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        PreferenceScreen preferenceScreen = this.f3602b.f253e;
        if (preferenceScreen != null) {
            Bundle bundle2 = new Bundle();
            preferenceScreen.b(bundle2);
            bundle.putBundle("android:preferences", bundle2);
        }
    }

    @Override // android.app.Fragment
    public final void onStart() {
        super.onStart();
        this.f3602b.setOnPreferenceTreeClickListener(this);
        this.f3602b.setOnDisplayPreferenceDialogListener(this);
    }

    @Override // android.app.Fragment
    public final void onStop() {
        super.onStop();
        this.f3602b.setOnPreferenceTreeClickListener(null);
        this.f3602b.setOnDisplayPreferenceDialogListener(null);
    }

    @Override // android.app.Fragment
    public void onViewCreated(@NonNull View view, @Nullable Bundle bundle) {
        PreferenceScreen preferenceScreen;
        Bundle bundle2;
        PreferenceScreen preferenceScreen2;
        super.onViewCreated(view, bundle);
        if (bundle != null && (bundle2 = bundle.getBundle("android:preferences")) != null && (preferenceScreen2 = this.f3602b.f253e) != null) {
            preferenceScreen2.a(bundle2);
        }
        if (this.f3604d && (preferenceScreen = this.f3602b.f253e) != null) {
            this.f3603c.setAdapter(new z(preferenceScreen));
            preferenceScreen.l();
        }
        this.f3605e = true;
    }

    @Deprecated
    public void setDivider(@Nullable Drawable drawable) {
        this.f3601a.setDivider(drawable);
    }

    @Deprecated
    public void setPreferencesFromResource(@XmlRes int i10, @Nullable String str) {
        f0 f0Var = this.f3602b;
        if (f0Var == null) {
            throw new RuntimeException("This should be called after super.onCreate.");
        }
        PreferenceScreen preferenceScreenInflateFromResource = f0Var.inflateFromResource(this.f3606f, i10, null);
        Preference preference = preferenceScreenInflateFromResource;
        if (str != null) {
            Preference preferenceFindPreference = preferenceScreenInflateFromResource.findPreference(str);
            boolean z10 = preferenceFindPreference instanceof PreferenceScreen;
            preference = preferenceFindPreference;
            if (!z10) {
                throw new IllegalArgumentException(u1.k("Preference object with key ", str, " is not a PreferenceScreen"));
            }
        }
        PreferenceScreen preferenceScreen = (PreferenceScreen) preference;
        f0 f0Var2 = this.f3602b;
        PreferenceScreen preferenceScreen2 = f0Var2.f253e;
        if (preferenceScreen != preferenceScreen2) {
            if (preferenceScreen2 != null) {
                preferenceScreen2.p();
            }
            f0Var2.f253e = preferenceScreen;
            if (preferenceScreen != null) {
                this.f3604d = true;
                if (this.f3605e) {
                    u uVar = this.f3608h;
                    if (uVar.hasMessages(1)) {
                        return;
                    }
                    uVar.obtainMessage(1).sendToTarget();
                }
            }
        }
    }
}
