package com.google.android.material.datepicker;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import com.google.android.material.textfield.TextInputLayout;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

/* loaded from: classes3.dex */
abstract class e extends com.google.android.material.internal.n {

    /* renamed from: p, reason: collision with root package name */
    private final TextInputLayout f13094p;

    /* renamed from: q, reason: collision with root package name */
    private final DateFormat f13095q;

    /* renamed from: r, reason: collision with root package name */
    private final com.google.android.material.datepicker.a f13096r;

    /* renamed from: s, reason: collision with root package name */
    private final String f13097s;

    /* renamed from: t, reason: collision with root package name */
    private final Runnable f13098t;

    /* renamed from: u, reason: collision with root package name */
    private Runnable f13099u;

    /* loaded from: classes3.dex */
    class a implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ String f13100p;

        a(String str) {
            this.f13100p = str;
        }

        @Override // java.lang.Runnable
        public void run() {
            TextInputLayout textInputLayout = e.this.f13094p;
            DateFormat dateFormat = e.this.f13095q;
            Context context = textInputLayout.getContext();
            textInputLayout.setError(context.getString(vi.j.f39877r) + "\n" + String.format(context.getString(vi.j.f39879t), this.f13100p) + "\n" + String.format(context.getString(vi.j.f39878s), dateFormat.format(new Date(w.j().getTimeInMillis()))));
            e.this.e();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class b implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ long f13102p;

        b(long j10) {
            this.f13102p = j10;
        }

        @Override // java.lang.Runnable
        public void run() {
            e.this.f13094p.setError(String.format(e.this.f13097s, g.a(this.f13102p)));
            e.this.e();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public e(String str, DateFormat dateFormat, TextInputLayout textInputLayout, com.google.android.material.datepicker.a aVar) {
        this.f13095q = dateFormat;
        this.f13094p = textInputLayout;
        this.f13096r = aVar;
        this.f13097s = textInputLayout.getContext().getString(vi.j.f39881v);
        this.f13098t = new a(str);
    }

    private Runnable d(long j10) {
        return new b(j10);
    }

    abstract void e();

    abstract void f(Long l10);

    public void g(View view, Runnable runnable) {
        view.postDelayed(runnable, 1000L);
    }

    @Override // com.google.android.material.internal.n, android.text.TextWatcher
    public void onTextChanged(CharSequence charSequence, int i10, int i11, int i12) {
        this.f13094p.removeCallbacks(this.f13098t);
        this.f13094p.removeCallbacks(this.f13099u);
        this.f13094p.setError(null);
        f(null);
        if (TextUtils.isEmpty(charSequence)) {
            return;
        }
        try {
            Date parse = this.f13095q.parse(charSequence.toString());
            this.f13094p.setError(null);
            long time = parse.getTime();
            if (this.f13096r.f().n0(time) && this.f13096r.l(time)) {
                f(Long.valueOf(parse.getTime()));
                return;
            }
            Runnable d10 = d(time);
            this.f13099u = d10;
            g(this.f13094p, d10);
        } catch (ParseException unused) {
            g(this.f13094p, this.f13098t);
        }
    }
}
