package com.google.android.material.datepicker;

import android.R;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.core.view.s1;
import com.google.android.gms.measurement.internal.u1;
import com.google.android.material.internal.CheckableImageButton;
import com.google.android.material.internal.w0;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Iterator;
import java.util.LinkedHashSet;

/* JADX INFO: loaded from: classes2.dex */
public class MaterialDatePicker<S> extends androidx.fragment.app.u {

    /* JADX INFO: renamed from: m1, reason: collision with root package name */
    public static final /* synthetic */ int f22449m1 = 0;
    public final LinkedHashSet S0;
    public final LinkedHashSet T0;
    public int U0;
    public w V0;
    public MaterialCalendar W0;
    public int X0;
    public CharSequence Y0;
    public boolean Z0;
    public int a1;

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

    @Nullable
    private com.google.android.material.shape.k background;

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

    @Nullable
    private c calendarConstraints;

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

    @Nullable
    private e dateSelector;

    @Nullable
    private g dayViewDecorator;

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

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

    @Nullable
    private CharSequence fullTitleText;

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

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

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

    /* JADX INFO: renamed from: j1, reason: collision with root package name */
    public TextView f22458j1;

    /* JADX INFO: renamed from: k1, reason: collision with root package name */
    public CheckableImageButton f22459k1;

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

    @Nullable
    private CharSequence singleLineTitleText;

    @Retention(RetentionPolicy.SOURCE)
    @RestrictTo({RestrictTo.Scope.f556b})
    public @interface InputMode {
    }

    public MaterialDatePicker() {
        new LinkedHashSet();
        new LinkedHashSet();
        this.S0 = new LinkedHashSet();
        this.T0 = new LinkedHashSet();
    }

    public static int N(Context context) {
        Resources resources = context.getResources();
        int dimensionPixelOffset = resources.getDimensionPixelOffset(x8.e.mtrl_calendar_content_padding);
        r rVar = new r(z.c());
        int dimensionPixelSize = resources.getDimensionPixelSize(x8.e.mtrl_calendar_day_width);
        int dimensionPixelOffset2 = resources.getDimensionPixelOffset(x8.e.mtrl_calendar_month_horizontal_padding);
        int i10 = rVar.f22501d;
        return ((i10 - 1) * dimensionPixelOffset2) + (dimensionPixelSize * i10) + (dimensionPixelOffset * 2);
    }

    public static boolean O(Context context, int i10) {
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(q9.c.c(context, x8.c.materialCalendarStyle, MaterialCalendar.class.getCanonicalName()).data, new int[]{i10});
        boolean z10 = typedArrayObtainStyledAttributes.getBoolean(0, false);
        typedArrayObtainStyledAttributes.recycle();
        return z10;
    }

    @Nullable
    private static CharSequence getFirstLineBySeparator(@Nullable CharSequence charSequence) {
        if (charSequence == null) {
            return null;
        }
        String[] strArrSplit = TextUtils.split(String.valueOf(charSequence), "\n");
        return strArrSplit.length > 1 ? strArrSplit[0] : charSequence;
    }

    public final void M() {
        u1.u(getArguments().getParcelable("DATE_SELECTOR_KEY"));
    }

    @Nullable
    public final S getSelection() {
        M();
        throw null;
    }

    @Override // androidx.fragment.app.u, android.content.DialogInterface.OnCancelListener
    public final void onCancel(DialogInterface dialogInterface) {
        Iterator it = this.S0.iterator();
        while (it.hasNext()) {
            ((DialogInterface.OnCancelListener) it.next()).onCancel(dialogInterface);
        }
    }

    @Override // androidx.fragment.app.u, androidx.fragment.app.e0
    public final void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        if (bundle == null) {
            bundle = getArguments();
        }
        this.U0 = bundle.getInt("OVERRIDE_THEME_RES_ID");
        u1.u(bundle.getParcelable("DATE_SELECTOR_KEY"));
        this.calendarConstraints = (c) bundle.getParcelable("CALENDAR_CONSTRAINTS_KEY");
        u1.u(bundle.getParcelable("DAY_VIEW_DECORATOR_KEY"));
        this.X0 = bundle.getInt("TITLE_TEXT_RES_ID_KEY");
        this.Y0 = bundle.getCharSequence("TITLE_TEXT_KEY");
        this.a1 = bundle.getInt("INPUT_MODE_KEY");
        this.f22450b1 = bundle.getInt("POSITIVE_BUTTON_TEXT_RES_ID_KEY");
        this.f22451c1 = bundle.getCharSequence("POSITIVE_BUTTON_TEXT_KEY");
        this.f22452d1 = bundle.getInt("POSITIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY");
        this.f22453e1 = bundle.getCharSequence("POSITIVE_BUTTON_CONTENT_DESCRIPTION_KEY");
        this.f22454f1 = bundle.getInt("NEGATIVE_BUTTON_TEXT_RES_ID_KEY");
        this.f22455g1 = bundle.getCharSequence("NEGATIVE_BUTTON_TEXT_KEY");
        this.f22456h1 = bundle.getInt("NEGATIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY");
        this.f22457i1 = bundle.getCharSequence("NEGATIVE_BUTTON_CONTENT_DESCRIPTION_KEY");
        CharSequence text = this.Y0;
        if (text == null) {
            text = requireContext().getResources().getText(this.X0);
        }
        this.fullTitleText = text;
        this.singleLineTitleText = getFirstLineBySeparator(text);
    }

    @Override // androidx.fragment.app.u
    @NonNull
    public final Dialog onCreateDialog(@Nullable Bundle bundle) {
        Context contextRequireContext = requireContext();
        requireContext();
        int i10 = this.U0;
        if (i10 == 0) {
            M();
            throw null;
        }
        Dialog dialog = new Dialog(contextRequireContext, i10);
        Context context = dialog.getContext();
        this.Z0 = O(context, R.attr.windowFullscreen);
        int i11 = x8.c.materialCalendarStyle;
        int i12 = x8.l.Widget_MaterialComponents_MaterialCalendar;
        this.background = new com.google.android.material.shape.k(context, null, i11, i12);
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(null, x8.m.MaterialCalendar, i11, i12);
        int color = typedArrayObtainStyledAttributes.getColor(x8.m.MaterialCalendar_backgroundTint, 0);
        typedArrayObtainStyledAttributes.recycle();
        this.background.s(context);
        this.background.setFillColor(ColorStateList.valueOf(color));
        this.background.w(dialog.getWindow().getDecorView().getElevation());
        return dialog;
    }

    @Override // androidx.fragment.app.e0
    @NonNull
    public final View onCreateView(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
        View viewInflate = layoutInflater.inflate(this.Z0 ? x8.i.mtrl_picker_fullscreen : x8.i.mtrl_picker_dialog, viewGroup);
        Context context = viewInflate.getContext();
        if (this.Z0) {
            viewInflate.findViewById(x8.g.mtrl_calendar_frame).setLayoutParams(new LinearLayout.LayoutParams(N(context), -2));
        } else {
            viewInflate.findViewById(x8.g.mtrl_calendar_main_pane).setLayoutParams(new LinearLayout.LayoutParams(N(context), -1));
        }
        ((TextView) viewInflate.findViewById(x8.g.mtrl_picker_header_selection_text)).setAccessibilityLiveRegion(1);
        this.f22459k1 = (CheckableImageButton) viewInflate.findViewById(x8.g.mtrl_picker_header_toggle);
        this.f22458j1 = (TextView) viewInflate.findViewById(x8.g.mtrl_picker_title_text);
        this.f22459k1.setTag("TOGGLE_BUTTON_TAG");
        CheckableImageButton checkableImageButton = this.f22459k1;
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[]{R.attr.state_checked}, f.a.getDrawable(context, x8.f.material_ic_calendar_black_24dp));
        stateListDrawable.addState(new int[0], f.a.getDrawable(context, x8.f.material_ic_edit_black_24dp));
        checkableImageButton.setImageDrawable(stateListDrawable);
        this.f22459k1.setChecked(this.a1 != 0);
        s1.setAccessibilityDelegate(this.f22459k1, null);
        CheckableImageButton checkableImageButton2 = this.f22459k1;
        this.f22459k1.setContentDescription(this.a1 == 1 ? checkableImageButton2.getContext().getString(x8.k.mtrl_picker_toggle_to_calendar_input_mode) : checkableImageButton2.getContext().getString(x8.k.mtrl_picker_toggle_to_text_input_mode));
        this.f22459k1.setOnClickListener(new View.OnClickListener() { // from class: com.google.android.material.datepicker.o
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                int i10 = MaterialDatePicker.f22449m1;
                this.f22492a.M();
                throw null;
            }
        });
        M();
        throw null;
    }

    @Override // androidx.fragment.app.u, android.content.DialogInterface.OnDismissListener
    public final void onDismiss(DialogInterface dialogInterface) {
        Iterator it = this.T0.iterator();
        while (it.hasNext()) {
            ((DialogInterface.OnDismissListener) it.next()).onDismiss(dialogInterface);
        }
        ViewGroup viewGroup = (ViewGroup) getView();
        if (viewGroup != null) {
            viewGroup.removeAllViews();
        }
        super.onDismiss(dialogInterface);
    }

    @Override // androidx.fragment.app.u, androidx.fragment.app.e0
    public final void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putInt("OVERRIDE_THEME_RES_ID", this.U0);
        bundle.putParcelable("DATE_SELECTOR_KEY", null);
        c cVar = this.calendarConstraints;
        a aVar = new a();
        int i10 = a.f22461b;
        int i11 = a.f22461b;
        long j10 = cVar.f22465a.f22503f;
        long j11 = cVar.f22466b.f22503f;
        aVar.f22462a = Long.valueOf(cVar.openAt.f22503f);
        int i12 = cVar.f22468d;
        MaterialCalendar materialCalendar = this.W0;
        r currentMonth = materialCalendar == null ? null : materialCalendar.getCurrentMonth();
        if (currentMonth != null) {
            aVar.f22462a = Long.valueOf(currentMonth.f22503f);
        }
        Bundle bundle2 = new Bundle();
        bundle2.putParcelable("DEEP_COPY_VALIDATOR_KEY", cVar.f22467c);
        r rVarB = r.b(j10);
        r rVarB2 = r.b(j11);
        b bVar = (b) bundle2.getParcelable("DEEP_COPY_VALIDATOR_KEY");
        Long l10 = aVar.f22462a;
        bundle.putParcelable("CALENDAR_CONSTRAINTS_KEY", new c(rVarB, rVarB2, bVar, l10 == null ? null : r.b(l10.longValue()), i12, 0));
        bundle.putParcelable("DAY_VIEW_DECORATOR_KEY", null);
        bundle.putInt("TITLE_TEXT_RES_ID_KEY", this.X0);
        bundle.putCharSequence("TITLE_TEXT_KEY", this.Y0);
        bundle.putInt("INPUT_MODE_KEY", this.a1);
        bundle.putInt("POSITIVE_BUTTON_TEXT_RES_ID_KEY", this.f22450b1);
        bundle.putCharSequence("POSITIVE_BUTTON_TEXT_KEY", this.f22451c1);
        bundle.putInt("POSITIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY", this.f22452d1);
        bundle.putCharSequence("POSITIVE_BUTTON_CONTENT_DESCRIPTION_KEY", this.f22453e1);
        bundle.putInt("NEGATIVE_BUTTON_TEXT_RES_ID_KEY", this.f22454f1);
        bundle.putCharSequence("NEGATIVE_BUTTON_TEXT_KEY", this.f22455g1);
        bundle.putInt("NEGATIVE_BUTTON_CONTENT_DESCRIPTION_RES_ID_KEY", this.f22456h1);
        bundle.putCharSequence("NEGATIVE_BUTTON_CONTENT_DESCRIPTION_KEY", this.f22457i1);
    }

    @Override // androidx.fragment.app.u, androidx.fragment.app.e0
    public final void onStart() {
        super.onStart();
        Window window = L().getWindow();
        if (this.Z0) {
            window.setLayout(-1, -1);
            window.setBackgroundDrawable(this.background);
            if (!this.f22460l1) {
                View viewFindViewById = requireView().findViewById(x8.g.fullscreen_header);
                com.google.android.material.internal.h.applyEdgeToEdge(window, true, w0.getBackgroundColor(viewFindViewById), null);
                s1.setOnApplyWindowInsetsListener(viewFindViewById, new p(viewFindViewById.getLayoutParams().height, viewFindViewById, viewFindViewById.getPaddingLeft(), viewFindViewById.getPaddingTop(), viewFindViewById.getPaddingRight()));
                this.f22460l1 = true;
            }
        } else {
            window.setLayout(-2, -2);
            int dimensionPixelOffset = getResources().getDimensionPixelOffset(x8.e.mtrl_calendar_dialog_background_inset);
            Rect rect = new Rect(dimensionPixelOffset, dimensionPixelOffset, dimensionPixelOffset, dimensionPixelOffset);
            window.setBackgroundDrawable(new InsetDrawable((Drawable) this.background, dimensionPixelOffset, dimensionPixelOffset, dimensionPixelOffset, dimensionPixelOffset));
            window.getDecorView().setOnTouchListener(new i9.a(L(), rect));
        }
        requireContext();
        int i10 = this.U0;
        if (i10 == 0) {
            M();
            throw null;
        }
        M();
        MaterialCalendar materialCalendarNewInstance = MaterialCalendar.newInstance(null, i10, this.calendarConstraints, null);
        this.W0 = materialCalendarNewInstance;
        w wVar = materialCalendarNewInstance;
        if (this.a1 == 1) {
            M();
            c cVar = this.calendarConstraints;
            q qVar = new q();
            Bundle bundle = new Bundle();
            bundle.putInt("THEME_RES_ID_KEY", i10);
            bundle.putParcelable("DATE_SELECTOR_KEY", null);
            bundle.putParcelable("CALENDAR_CONSTRAINTS_KEY", cVar);
            qVar.setArguments(bundle);
            wVar = qVar;
        }
        this.V0 = wVar;
        this.f22458j1.setText((this.a1 == 1 && getResources().getConfiguration().orientation == 2) ? this.singleLineTitleText : this.fullTitleText);
        M();
        getContext();
        throw null;
    }

    @Override // androidx.fragment.app.u, androidx.fragment.app.e0
    public final void onStop() {
        this.V0.D0.clear();
        super.onStop();
    }
}
