package com.google.android.material.datepicker;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.internal.ads.p80;
import java.util.Calendar;
import java.util.Collection;

/* JADX INFO: loaded from: classes2.dex */
public final class s extends BaseAdapter {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final int f22504e = z.getUtcCalendarOf(null).getMaximum(4);

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final int f22505f = (z.getUtcCalendarOf(null).getMaximum(7) + z.getUtcCalendarOf(null).getMaximum(5)) - 1;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Collection f22507b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final c f22509d;

    @Nullable
    final g dayViewDecorator;

    public s(r rVar, e eVar, c cVar, @Nullable g gVar) {
        this.f22506a = rVar;
        this.f22509d = cVar;
        this.f22507b = eVar.q();
    }

    private void updateSelectedState(@Nullable TextView textView, long j10, int i10) {
        if (textView == null) {
            return;
        }
        textView.getContext();
        z.c().getTimeInMillis();
        throw null;
    }

    public final int a() {
        int firstDayOfWeek = this.f22509d.f22468d;
        r rVar = this.f22506a;
        Calendar calendar = rVar.f22498a;
        int i10 = calendar.get(7);
        if (firstDayOfWeek <= 0) {
            firstDayOfWeek = calendar.getFirstDayOfWeek();
        }
        int i11 = i10 - firstDayOfWeek;
        return i11 < 0 ? i11 + rVar.f22501d : i11;
    }

    public final int b() {
        return (a() + this.f22506a.f22502e) - 1;
    }

    public final void c(MaterialCalendarGridView materialCalendarGridView, long j10) {
        r rVarB = r.b(j10);
        r rVar = this.f22506a;
        if (rVarB.equals(rVar)) {
            Calendar calendarB = z.b(rVar.f22498a);
            calendarB.setTimeInMillis(j10);
            int i10 = calendarB.get(5);
            updateSelectedState((TextView) materialCalendarGridView.getChildAt((materialCalendarGridView.a().a() + (i10 - 1)) - materialCalendarGridView.getFirstVisiblePosition()), j10, i10);
        }
    }

    @Override // android.widget.Adapter
    public final int getCount() {
        return f22505f;
    }

    @Override // android.widget.Adapter
    public final long getItemId(int i10) {
        return i10 / this.f22506a.f22501d;
    }

    @Override // android.widget.BaseAdapter, android.widget.Adapter
    public final boolean hasStableIds() {
        return true;
    }

    @Override // android.widget.Adapter
    @Nullable
    public Long getItem(int i10) {
        if (i10 < a() || i10 > b()) {
            return null;
        }
        int iA = (i10 - a()) + 1;
        Calendar calendarB = z.b(this.f22506a.f22498a);
        calendarB.set(5, iA);
        return Long.valueOf(calendarB.getTimeInMillis());
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x005c  */
    @Override // android.widget.Adapter
    @NonNull
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public TextView getView(int i10, @Nullable View view, @NonNull ViewGroup viewGroup) {
        int i11;
        Context context = viewGroup.getContext();
        if (this.f22508c == null) {
            this.f22508c = new p80(context);
        }
        TextView textView = (TextView) view;
        if (view == null) {
            textView = (TextView) LayoutInflater.from(viewGroup.getContext()).inflate(x8.i.mtrl_calendar_day, viewGroup, false);
        }
        int iA = i10 - a();
        if (iA >= 0) {
            r rVar = this.f22506a;
            if (iA >= rVar.f22502e) {
                textView.setVisibility(8);
                textView.setEnabled(false);
                i11 = -1;
            } else {
                i11 = iA + 1;
                textView.setTag(rVar);
                textView.setText(String.format(textView.getResources().getConfiguration().locale, "%d", Integer.valueOf(i11)));
                textView.setVisibility(0);
                textView.setEnabled(true);
            }
        }
        Long item = getItem(i10);
        if (item == null) {
            return textView;
        }
        updateSelectedState(textView, item.longValue(), i11);
        return textView;
    }
}
