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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.core.view.j0;
import androidx.core.view.y;
import androidx.fragment.app.v;
import com.google.android.material.datepicker.a;
import com.google.android.material.internal.CheckableImageButton;
import java.util.Iterator;
import java.util.LinkedHashSet;

/* JADX INFO: compiled from: MaterialDatePicker.java */
/* JADX INFO: loaded from: classes.dex */
public final class i<S> extends androidx.fragment.app.d {
    static final Object O0 = "CONFIRM_BUTTON_TAG";
    static final Object P0 = "CANCEL_BUTTON_TAG";
    static final Object Q0 = "TOGGLE_BUTTON_TAG";
    private h<S> A0;
    private int B0;
    private CharSequence C0;
    private boolean D0;
    private int E0;
    private int F0;
    private CharSequence G0;
    private int H0;
    private CharSequence I0;
    private TextView J0;
    private CheckableImageButton K0;
    private c1.g L0;
    private Button M0;
    private boolean N0;

    /* JADX INFO: renamed from: s0, reason: collision with root package name */
    private final LinkedHashSet<j<? super S>> f3878s0 = new LinkedHashSet<>();

    /* JADX INFO: renamed from: t0, reason: collision with root package name */
    private final LinkedHashSet<View.OnClickListener> f3879t0 = new LinkedHashSet<>();

    /* JADX INFO: renamed from: u0, reason: collision with root package name */
    private final LinkedHashSet<DialogInterface.OnCancelListener> f3880u0 = new LinkedHashSet<>();

    /* JADX INFO: renamed from: v0, reason: collision with root package name */
    private final LinkedHashSet<DialogInterface.OnDismissListener> f3881v0 = new LinkedHashSet<>();

    /* JADX INFO: renamed from: w0, reason: collision with root package name */
    private int f3882w0;

    /* JADX INFO: renamed from: x0, reason: collision with root package name */
    private com.google.android.material.datepicker.d<S> f3883x0;

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    private p<S> f3884y0;

    /* JADX INFO: renamed from: z0, reason: collision with root package name */
    private com.google.android.material.datepicker.a f3885z0;

    /* JADX INFO: compiled from: MaterialDatePicker.java */
    class a implements View.OnClickListener {
        a() {
        }

        /* JADX WARN: Multi-variable type inference failed */
        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            Iterator it = i.this.f3878s0.iterator();
            while (it.hasNext()) {
                ((j) it.next()).a(i.this.c2());
            }
            i.this.F1();
        }
    }

    /* JADX INFO: compiled from: MaterialDatePicker.java */
    class b implements View.OnClickListener {
        b() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            Iterator it = i.this.f3879t0.iterator();
            while (it.hasNext()) {
                ((View.OnClickListener) it.next()).onClick(view);
            }
            i.this.F1();
        }
    }

    /* JADX INFO: compiled from: MaterialDatePicker.java */
    class c implements androidx.core.view.s {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ int f3888a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ View f3889b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ int f3890c;

        c(i iVar, int i3, View view, int i4) {
            this.f3888a = i3;
            this.f3889b = view;
            this.f3890c = i4;
        }

        @Override // androidx.core.view.s
        public j0 a(View view, j0 j0Var) {
            int i3 = j0Var.f(j0.m.c()).f1686b;
            if (this.f3888a >= 0) {
                this.f3889b.getLayoutParams().height = this.f3888a + i3;
                View view2 = this.f3889b;
                view2.setLayoutParams(view2.getLayoutParams());
            }
            View view3 = this.f3889b;
            view3.setPadding(view3.getPaddingLeft(), this.f3890c + i3, this.f3889b.getPaddingRight(), this.f3889b.getPaddingBottom());
            return j0Var;
        }
    }

    /* JADX INFO: compiled from: MaterialDatePicker.java */
    class d extends o<S> {
        d() {
        }

        @Override // com.google.android.material.datepicker.o
        public void a(S s2) {
            i.this.j2();
            i.this.M0.setEnabled(i.this.Z1().f());
        }
    }

    /* JADX INFO: compiled from: MaterialDatePicker.java */
    class e implements View.OnClickListener {
        e() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            i.this.M0.setEnabled(i.this.Z1().f());
            i.this.K0.toggle();
            i iVar = i.this;
            iVar.k2(iVar.K0);
            i.this.i2();
        }
    }

    private static Drawable X1(Context context) {
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[]{R.attr.state_checked}, d.a.b(context, l0.e.f5377b));
        stateListDrawable.addState(new int[0], d.a.b(context, l0.e.f5378c));
        return stateListDrawable;
    }

    private void Y1(Window window) {
        if (this.N0) {
            return;
        }
        View viewFindViewById = m1().findViewById(l0.f.f5388f);
        com.google.android.material.internal.d.a(window, true, com.google.android.material.internal.o.c(viewFindViewById), null);
        y.D0(viewFindViewById, new c(this, viewFindViewById.getLayoutParams().height, viewFindViewById, viewFindViewById.getPaddingTop()));
        this.N0 = true;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public com.google.android.material.datepicker.d<S> Z1() {
        if (this.f3883x0 == null) {
            this.f3883x0 = (com.google.android.material.datepicker.d) p().getParcelable("DATE_SELECTOR_KEY");
        }
        return this.f3883x0;
    }

    private static int b2(Context context) {
        Resources resources = context.getResources();
        int dimensionPixelOffset = resources.getDimensionPixelOffset(l0.d.A);
        int i3 = l.m().f3900h;
        return (dimensionPixelOffset * 2) + (resources.getDimensionPixelSize(l0.d.C) * i3) + ((i3 - 1) * resources.getDimensionPixelOffset(l0.d.F));
    }

    private int d2(Context context) {
        int i3 = this.f3882w0;
        return i3 != 0 ? i3 : Z1().c(context);
    }

    private void e2(Context context) {
        this.K0.setTag(Q0);
        this.K0.setImageDrawable(X1(context));
        this.K0.setChecked(this.E0 != 0);
        y.r0(this.K0, null);
        k2(this.K0);
        this.K0.setOnClickListener(new e());
    }

    static boolean f2(Context context) {
        return h2(context, R.attr.windowFullscreen);
    }

    static boolean g2(Context context) {
        return h2(context, l0.b.f5341x);
    }

    static boolean h2(Context context, int i3) {
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(z0.b.d(context, l0.b.f5336s, h.class.getCanonicalName()), new int[]{i3});
        boolean z2 = typedArrayObtainStyledAttributes.getBoolean(0, false);
        typedArrayObtainStyledAttributes.recycle();
        return z2;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void i2() {
        int iD2 = d2(l1());
        this.A0 = h.U1(Z1(), iD2, this.f3885z0);
        this.f3884y0 = this.K0.isChecked() ? k.E1(Z1(), iD2, this.f3885z0) : this.A0;
        j2();
        v vVarL = q().l();
        vVarL.l(l0.f.f5405w, this.f3884y0);
        vVarL.g();
        this.f3884y0.C1(new d());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void j2() {
        String strA2 = a2();
        this.J0.setContentDescription(String.format(Q(l0.i.f5438i), strA2));
        this.J0.setText(strA2);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void k2(CheckableImageButton checkableImageButton) {
        this.K0.setContentDescription(this.K0.isChecked() ? checkableImageButton.getContext().getString(l0.i.f5441l) : checkableImageButton.getContext().getString(l0.i.f5443n));
    }

    @Override // androidx.fragment.app.d, androidx.fragment.app.Fragment
    public final void H0(Bundle bundle) {
        super.H0(bundle);
        bundle.putInt("OVERRIDE_THEME_RES_ID", this.f3882w0);
        bundle.putParcelable("DATE_SELECTOR_KEY", this.f3883x0);
        a.b bVar = new a.b(this.f3885z0);
        if (this.A0.P1() != null) {
            bVar.b(this.A0.P1().f3902j);
        }
        bundle.putParcelable("CALENDAR_CONSTRAINTS_KEY", bVar.a());
        bundle.putInt("TITLE_TEXT_RES_ID_KEY", this.B0);
        bundle.putCharSequence("TITLE_TEXT_KEY", this.C0);
        bundle.putInt("POSITIVE_BUTTON_TEXT_RES_ID_KEY", this.F0);
        bundle.putCharSequence("POSITIVE_BUTTON_TEXT_KEY", this.G0);
        bundle.putInt("NEGATIVE_BUTTON_TEXT_RES_ID_KEY", this.H0);
        bundle.putCharSequence("NEGATIVE_BUTTON_TEXT_KEY", this.I0);
    }

    @Override // androidx.fragment.app.d, androidx.fragment.app.Fragment
    public void I0() {
        super.I0();
        Window window = N1().getWindow();
        if (this.D0) {
            window.setLayout(-1, -1);
            window.setBackgroundDrawable(this.L0);
            Y1(window);
        } else {
            window.setLayout(-2, -2);
            int dimensionPixelOffset = K().getDimensionPixelOffset(l0.d.E);
            Rect rect = new Rect(dimensionPixelOffset, dimensionPixelOffset, dimensionPixelOffset, dimensionPixelOffset);
            window.setBackgroundDrawable(new InsetDrawable((Drawable) this.L0, dimensionPixelOffset, dimensionPixelOffset, dimensionPixelOffset, dimensionPixelOffset));
            window.getDecorView().setOnTouchListener(new s0.a(N1(), rect));
        }
        i2();
    }

    @Override // androidx.fragment.app.d, androidx.fragment.app.Fragment
    public void J0() {
        this.f3884y0.D1();
        super.J0();
    }

    @Override // androidx.fragment.app.d
    public final Dialog J1(Bundle bundle) {
        Dialog dialog = new Dialog(l1(), d2(l1()));
        Context context = dialog.getContext();
        this.D0 = f2(context);
        int iD = z0.b.d(context, l0.b.f5328k, i.class.getCanonicalName());
        c1.g gVar = new c1.g(context, null, l0.b.f5336s, l0.j.f5457l);
        this.L0 = gVar;
        gVar.N(context);
        this.L0.X(ColorStateList.valueOf(iD));
        this.L0.W(y.y(dialog.getWindow().getDecorView()));
        return dialog;
    }

    public String a2() {
        return Z1().b(r());
    }

    public final S c2() {
        return Z1().a();
    }

    @Override // androidx.fragment.app.d, androidx.fragment.app.Fragment
    public final void l0(Bundle bundle) {
        super.l0(bundle);
        if (bundle == null) {
            bundle = p();
        }
        this.f3882w0 = bundle.getInt("OVERRIDE_THEME_RES_ID");
        this.f3883x0 = (com.google.android.material.datepicker.d) bundle.getParcelable("DATE_SELECTOR_KEY");
        this.f3885z0 = (com.google.android.material.datepicker.a) bundle.getParcelable("CALENDAR_CONSTRAINTS_KEY");
        this.B0 = bundle.getInt("TITLE_TEXT_RES_ID_KEY");
        this.C0 = bundle.getCharSequence("TITLE_TEXT_KEY");
        this.E0 = bundle.getInt("INPUT_MODE_KEY");
        this.F0 = bundle.getInt("POSITIVE_BUTTON_TEXT_RES_ID_KEY");
        this.G0 = bundle.getCharSequence("POSITIVE_BUTTON_TEXT_KEY");
        this.H0 = bundle.getInt("NEGATIVE_BUTTON_TEXT_RES_ID_KEY");
        this.I0 = bundle.getCharSequence("NEGATIVE_BUTTON_TEXT_KEY");
    }

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

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

    @Override // androidx.fragment.app.Fragment
    public final View p0(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View viewInflate = layoutInflater.inflate(this.D0 ? l0.h.f5429r : l0.h.f5428q, viewGroup);
        Context context = viewInflate.getContext();
        if (this.D0) {
            viewInflate.findViewById(l0.f.f5405w).setLayoutParams(new LinearLayout.LayoutParams(b2(context), -2));
        } else {
            viewInflate.findViewById(l0.f.f5406x).setLayoutParams(new LinearLayout.LayoutParams(b2(context), -1));
        }
        TextView textView = (TextView) viewInflate.findViewById(l0.f.C);
        this.J0 = textView;
        y.t0(textView, 1);
        this.K0 = (CheckableImageButton) viewInflate.findViewById(l0.f.D);
        TextView textView2 = (TextView) viewInflate.findViewById(l0.f.E);
        CharSequence charSequence = this.C0;
        if (charSequence != null) {
            textView2.setText(charSequence);
        } else {
            textView2.setText(this.B0);
        }
        e2(context);
        this.M0 = (Button) viewInflate.findViewById(l0.f.f5385c);
        if (Z1().f()) {
            this.M0.setEnabled(true);
        } else {
            this.M0.setEnabled(false);
        }
        this.M0.setTag(O0);
        CharSequence charSequence2 = this.G0;
        if (charSequence2 != null) {
            this.M0.setText(charSequence2);
        } else {
            int i3 = this.F0;
            if (i3 != 0) {
                this.M0.setText(i3);
            }
        }
        this.M0.setOnClickListener(new a());
        Button button = (Button) viewInflate.findViewById(l0.f.f5383a);
        button.setTag(P0);
        CharSequence charSequence3 = this.I0;
        if (charSequence3 != null) {
            button.setText(charSequence3);
        } else {
            int i4 = this.H0;
            if (i4 != 0) {
                button.setText(i4);
            }
        }
        button.setOnClickListener(new b());
        return viewInflate;
    }
}
