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 java.util.Collection;
import java.util.Iterator;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public class p extends BaseAdapter {

    /* renamed from: u, reason: collision with root package name */
    static final int f13177u = w.l().getMaximum(4);

    /* renamed from: p, reason: collision with root package name */
    final o f13178p;

    /* renamed from: q, reason: collision with root package name */
    final f f13179q;

    /* renamed from: r, reason: collision with root package name */
    private Collection f13180r;

    /* renamed from: s, reason: collision with root package name */
    c f13181s;

    /* renamed from: t, reason: collision with root package name */
    final a f13182t;

    /* JADX INFO: Access modifiers changed from: package-private */
    public p(o oVar, f fVar, a aVar) {
        this.f13178p = oVar;
        this.f13179q = fVar;
        this.f13182t = aVar;
        this.f13180r = fVar.y0();
    }

    private void e(Context context) {
        if (this.f13181s == null) {
            this.f13181s = new c(context);
        }
    }

    private boolean h(long j10) {
        Iterator it = this.f13179q.y0().iterator();
        while (it.hasNext()) {
            if (w.a(j10) == w.a(((Long) it.next()).longValue())) {
                return true;
            }
        }
        return false;
    }

    private void k(TextView textView, long j10) {
        b bVar;
        if (textView == null) {
            return;
        }
        if (this.f13182t.f().n0(j10)) {
            textView.setEnabled(true);
            bVar = h(j10) ? this.f13181s.f13083b : w.j().getTimeInMillis() == j10 ? this.f13181s.f13084c : this.f13181s.f13082a;
        } else {
            textView.setEnabled(false);
            bVar = this.f13181s.f13088g;
        }
        bVar.d(textView);
    }

    private void l(MaterialCalendarGridView materialCalendarGridView, long j10) {
        if (o.g(j10).equals(this.f13178p)) {
            k((TextView) materialCalendarGridView.getChildAt(materialCalendarGridView.getAdapter().a(this.f13178p.u(j10)) - materialCalendarGridView.getFirstVisiblePosition()), j10);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int a(int i10) {
        return b() + (i10 - 1);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int b() {
        return this.f13178p.r();
    }

    @Override // android.widget.Adapter
    /* renamed from: c, reason: merged with bridge method [inline-methods] */
    public Long getItem(int i10) {
        if (i10 < this.f13178p.r() || i10 > i()) {
            return null;
        }
        return Long.valueOf(this.f13178p.t(j(i10)));
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x0083 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:16:0x0084  */
    @Override // android.widget.Adapter
    /* renamed from: d, reason: merged with bridge method [inline-methods] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public TextView getView(int i10, View view, ViewGroup viewGroup) {
        Long item;
        e(viewGroup.getContext());
        TextView textView = (TextView) view;
        if (view == null) {
            textView = (TextView) LayoutInflater.from(viewGroup.getContext()).inflate(vi.h.f39849q, viewGroup, false);
        }
        int b10 = i10 - b();
        if (b10 >= 0) {
            o oVar = this.f13178p;
            if (b10 < oVar.f13174t) {
                int i11 = b10 + 1;
                textView.setTag(oVar);
                textView.setText(String.format(textView.getResources().getConfiguration().locale, "%d", Integer.valueOf(i11)));
                long t10 = this.f13178p.t(i11);
                if (this.f13178p.f13172r == o.m().f13172r) {
                    textView.setContentDescription(g.e(t10));
                } else {
                    textView.setContentDescription(g.j(t10));
                }
                textView.setVisibility(0);
                textView.setEnabled(true);
                item = getItem(i10);
                if (item != null) {
                    return textView;
                }
                k(textView, item.longValue());
                return textView;
            }
        }
        textView.setVisibility(8);
        textView.setEnabled(false);
        item = getItem(i10);
        if (item != null) {
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean f(int i10) {
        return i10 % this.f13178p.f13173s == 0;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean g(int i10) {
        return (i10 + 1) % this.f13178p.f13173s == 0;
    }

    @Override // android.widget.Adapter
    public int getCount() {
        return this.f13178p.f13174t + b();
    }

    @Override // android.widget.Adapter
    public long getItemId(int i10) {
        return i10 / this.f13178p.f13173s;
    }

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

    /* JADX INFO: Access modifiers changed from: package-private */
    public int i() {
        return (this.f13178p.r() + this.f13178p.f13174t) - 1;
    }

    int j(int i10) {
        return (i10 - this.f13178p.r()) + 1;
    }

    public void m(MaterialCalendarGridView materialCalendarGridView) {
        Iterator it = this.f13180r.iterator();
        while (it.hasNext()) {
            l(materialCalendarGridView, ((Long) it.next()).longValue());
        }
        f fVar = this.f13179q;
        if (fVar != null) {
            Iterator it2 = fVar.y0().iterator();
            while (it2.hasNext()) {
                l(materialCalendarGridView, ((Long) it2.next()).longValue());
            }
            this.f13180r = this.f13179q.y0();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean n(int i10) {
        return i10 >= b() && i10 <= i();
    }
}
