package com.google.android.material.datepicker; import android.content.Context; import android.graphics.Canvas; import android.os.Bundle; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.GridView; import android.widget.ListAdapter; import androidx.core.view.n0; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.button.MaterialButton; import java.util.Calendar; import z.a0; /* loaded from: classes2.dex */ public final class i extends p { /* renamed from: k, reason: collision with root package name */ static final Object f4494k = "MONTHS_VIEW_GROUP_TAG"; /* renamed from: l, reason: collision with root package name */ static final Object f4495l = "NAVIGATION_PREV_TAG"; /* renamed from: m, reason: collision with root package name */ static final Object f4496m = "NAVIGATION_NEXT_TAG"; /* renamed from: n, reason: collision with root package name */ static final Object f4497n = "SELECTOR_TOGGLE_TAG"; /* renamed from: b, reason: collision with root package name */ private int f4498b; /* renamed from: c, reason: collision with root package name */ private com.google.android.material.datepicker.a f4499c; /* renamed from: d, reason: collision with root package name */ private com.google.android.material.datepicker.l f4500d; /* renamed from: e, reason: collision with root package name */ private k f4501e; /* renamed from: f, reason: collision with root package name */ private com.google.android.material.datepicker.c f4502f; /* renamed from: g, reason: collision with root package name */ private RecyclerView f4503g; /* renamed from: h, reason: collision with root package name */ private RecyclerView f4504h; /* renamed from: i, reason: collision with root package name */ private View f4505i; /* renamed from: j, reason: collision with root package name */ private View f4506j; class a implements Runnable { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ int f4507a; a(int i10) { this.f4507a = i10; } @Override // java.lang.Runnable public void run() { i.this.f4504h.smoothScrollToPosition(this.f4507a); } } class b extends androidx.core.view.a { b() { } @Override // androidx.core.view.a public void g(View view, a0 a0Var) { super.g(view, a0Var); a0Var.Y(null); } } class c extends q { final /* synthetic */ int I; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ c(Context context, int i10, boolean z10, int i11) { super(context, i10, z10); this.I = i11; } @Override // androidx.recyclerview.widget.LinearLayoutManager protected void M1(RecyclerView.a0 a0Var, int[] iArr) { if (this.I == 0) { iArr[0] = i.this.f4504h.getWidth(); iArr[1] = i.this.f4504h.getWidth(); } else { iArr[0] = i.this.f4504h.getHeight(); iArr[1] = i.this.f4504h.getHeight(); } } } class d implements l { d() { } @Override // com.google.android.material.datepicker.i.l public void a(long j10) { if (i.this.f4499c.e().O(j10)) { i.k(i.this); throw null; } } } class e extends RecyclerView.n { /* renamed from: a, reason: collision with root package name */ private final Calendar f4511a = u.k(); /* renamed from: b, reason: collision with root package name */ private final Calendar f4512b = u.k(); e() { } @Override // androidx.recyclerview.widget.RecyclerView.n public void g(Canvas canvas, RecyclerView recyclerView, RecyclerView.a0 a0Var) { if ((recyclerView.getAdapter() instanceof v) && (recyclerView.getLayoutManager() instanceof GridLayoutManager)) { i.k(i.this); throw null; } } } class f extends androidx.core.view.a { f() { } @Override // androidx.core.view.a public void g(View view, a0 a0Var) { super.g(view, a0Var); a0Var.h0(i.this.f4506j.getVisibility() == 0 ? i.this.getString(c3.h.f3549n) : i.this.getString(c3.h.f3547l)); } } class g extends RecyclerView.t { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ n f4515a; /* renamed from: b, reason: collision with root package name */ final /* synthetic */ MaterialButton f4516b; g(n nVar, MaterialButton materialButton) { this.f4515a = nVar; this.f4516b = materialButton; } @Override // androidx.recyclerview.widget.RecyclerView.t public void a(RecyclerView recyclerView, int i10) { if (i10 == 0) { recyclerView.announceForAccessibility(this.f4516b.getText()); } } @Override // androidx.recyclerview.widget.RecyclerView.t public void b(RecyclerView recyclerView, int i10, int i11) { int Z1 = i10 < 0 ? i.this.u().Z1() : i.this.u().c2(); i.this.f4500d = this.f4515a.u(Z1); this.f4516b.setText(this.f4515a.v(Z1)); } } class h implements View.OnClickListener { h() { } @Override // android.view.View.OnClickListener public void onClick(View view) { i.this.z(); } } /* renamed from: com.google.android.material.datepicker.i$i, reason: collision with other inner class name */ class ViewOnClickListenerC0071i implements View.OnClickListener { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ n f4519a; ViewOnClickListenerC0071i(n nVar) { this.f4519a = nVar; } @Override // android.view.View.OnClickListener public void onClick(View view) { int Z1 = i.this.u().Z1() + 1; if (Z1 < i.this.f4504h.getAdapter().c()) { i.this.x(this.f4519a.u(Z1)); } } } class j implements View.OnClickListener { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ n f4521a; j(n nVar) { this.f4521a = nVar; } @Override // android.view.View.OnClickListener public void onClick(View view) { int c22 = i.this.u().c2() - 1; if (c22 >= 0) { i.this.x(this.f4521a.u(c22)); } } } enum k { DAY, YEAR } interface l { void a(long j10); } static /* synthetic */ com.google.android.material.datepicker.d k(i iVar) { iVar.getClass(); return null; } private void n(View view, n nVar) { MaterialButton materialButton = (MaterialButton) view.findViewById(c3.e.f3506f); materialButton.setTag(f4497n); n0.n0(materialButton, new f()); MaterialButton materialButton2 = (MaterialButton) view.findViewById(c3.e.f3508h); materialButton2.setTag(f4495l); MaterialButton materialButton3 = (MaterialButton) view.findViewById(c3.e.f3507g); materialButton3.setTag(f4496m); this.f4505i = view.findViewById(c3.e.f3515o); this.f4506j = view.findViewById(c3.e.f3510j); y(k.DAY); materialButton.setText(this.f4500d.f()); this.f4504h.addOnScrollListener(new g(nVar, materialButton)); materialButton.setOnClickListener(new h()); materialButton3.setOnClickListener(new ViewOnClickListenerC0071i(nVar)); materialButton2.setOnClickListener(new j(nVar)); } private RecyclerView.n o() { return new e(); } static int t(Context context) { return context.getResources().getDimensionPixelSize(c3.c.f3479h); } static i v(com.google.android.material.datepicker.d dVar, int i10, com.google.android.material.datepicker.a aVar) { i iVar = new i(); Bundle bundle = new Bundle(); bundle.putInt("THEME_RES_ID_KEY", i10); bundle.putParcelable("GRID_SELECTOR_KEY", dVar); bundle.putParcelable("CALENDAR_CONSTRAINTS_KEY", aVar); bundle.putParcelable("CURRENT_MONTH_KEY", aVar.h()); iVar.setArguments(bundle); return iVar; } private void w(int i10) { this.f4504h.post(new a(i10)); } @Override // androidx.fragment.app.Fragment public void onCreate(Bundle bundle) { super.onCreate(bundle); if (bundle == null) { bundle = getArguments(); } this.f4498b = bundle.getInt("THEME_RES_ID_KEY"); androidx.appcompat.app.m.a(bundle.getParcelable("GRID_SELECTOR_KEY")); this.f4499c = (com.google.android.material.datepicker.a) bundle.getParcelable("CALENDAR_CONSTRAINTS_KEY"); this.f4500d = (com.google.android.material.datepicker.l) bundle.getParcelable("CURRENT_MONTH_KEY"); } @Override // androidx.fragment.app.Fragment public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) { int i10; int i11; ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(getContext(), this.f4498b); this.f4502f = new com.google.android.material.datepicker.c(contextThemeWrapper); LayoutInflater cloneInContext = layoutInflater.cloneInContext(contextThemeWrapper); com.google.android.material.datepicker.l i12 = this.f4499c.i(); if (com.google.android.material.datepicker.j.r(contextThemeWrapper)) { i10 = c3.g.f3532h; i11 = 1; } else { i10 = c3.g.f3530f; i11 = 0; } View inflate = cloneInContext.inflate(i10, viewGroup, false); GridView gridView = (GridView) inflate.findViewById(c3.e.f3511k); n0.n0(gridView, new b()); gridView.setAdapter((ListAdapter) new com.google.android.material.datepicker.h()); gridView.setNumColumns(i12.f4552e); gridView.setEnabled(false); this.f4504h = (RecyclerView) inflate.findViewById(c3.e.f3514n); this.f4504h.setLayoutManager(new c(getContext(), i11, false, i11)); this.f4504h.setTag(f4494k); n nVar = new n(contextThemeWrapper, null, this.f4499c, new d()); this.f4504h.setAdapter(nVar); int integer = contextThemeWrapper.getResources().getInteger(c3.f.f3524a); RecyclerView recyclerView = (RecyclerView) inflate.findViewById(c3.e.f3515o); this.f4503g = recyclerView; if (recyclerView != null) { recyclerView.setHasFixedSize(true); this.f4503g.setLayoutManager(new GridLayoutManager((Context) contextThemeWrapper, integer, 1, false)); this.f4503g.setAdapter(new v(this)); this.f4503g.addItemDecoration(o()); } if (inflate.findViewById(c3.e.f3506f) != null) { n(inflate, nVar); } if (!com.google.android.material.datepicker.j.r(contextThemeWrapper)) { new androidx.recyclerview.widget.h().b(this.f4504h); } this.f4504h.scrollToPosition(nVar.w(this.f4500d)); return inflate; } @Override // androidx.fragment.app.Fragment public void onSaveInstanceState(Bundle bundle) { super.onSaveInstanceState(bundle); bundle.putInt("THEME_RES_ID_KEY", this.f4498b); bundle.putParcelable("GRID_SELECTOR_KEY", null); bundle.putParcelable("CALENDAR_CONSTRAINTS_KEY", this.f4499c); bundle.putParcelable("CURRENT_MONTH_KEY", this.f4500d); } com.google.android.material.datepicker.a p() { return this.f4499c; } com.google.android.material.datepicker.c q() { return this.f4502f; } com.google.android.material.datepicker.l r() { return this.f4500d; } public com.google.android.material.datepicker.d s() { return null; } LinearLayoutManager u() { return (LinearLayoutManager) this.f4504h.getLayoutManager(); } void x(com.google.android.material.datepicker.l lVar) { n nVar = (n) this.f4504h.getAdapter(); int w10 = nVar.w(lVar); int w11 = w10 - nVar.w(this.f4500d); boolean z10 = Math.abs(w11) > 3; boolean z11 = w11 > 0; this.f4500d = lVar; if (z10 && z11) { this.f4504h.scrollToPosition(w10 - 3); w(w10); } else if (!z10) { w(w10); } else { this.f4504h.scrollToPosition(w10 + 3); w(w10); } } void y(k kVar) { this.f4501e = kVar; if (kVar == k.YEAR) { this.f4503g.getLayoutManager().x1(((v) this.f4503g.getAdapter()).t(this.f4500d.f4551d)); this.f4505i.setVisibility(0); this.f4506j.setVisibility(8); } else if (kVar == k.DAY) { this.f4505i.setVisibility(8); this.f4506j.setVisibility(0); x(this.f4500d); } } void z() { k kVar = this.f4501e; k kVar2 = k.YEAR; if (kVar == kVar2) { y(k.DAY); } else if (kVar == k.DAY) { y(kVar2); } } }