package androidx.leanback.widget.picker;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.AttributeSet;
import ar.tvplayer.tv.R;
import defpackage.AbstractC2873;
import defpackage.AbstractC4459;
import defpackage.C1140;
import defpackage.RunnableC2802;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;

/* loaded from: classes3.dex */
public class DatePicker extends Picker {

    /* renamed from: ᵫᵮʾ, reason: contains not printable characters */
    public static final int[] f502 = {5, 2, 1};

    /* renamed from: ˀᵗᵩ, reason: contains not printable characters */
    public int f503;

    /* renamed from: ˆᵼᵷˊ, reason: contains not printable characters */
    public int f504;

    /* renamed from: ˊʽˎ, reason: contains not printable characters */
    public final Calendar f505;

    /* renamed from: ˊᵸˊ, reason: contains not printable characters */
    public int f506;

    /* renamed from: ˌᵪ, reason: contains not printable characters */
    public final ᵶˉᵹʣ f507;

    /* renamed from: ˎᵬˀ, reason: contains not printable characters */
    public final Calendar f508;

    /* renamed from: ˑᵝﹳᵜ, reason: contains not printable characters */
    public C1140 f509;

    /* renamed from: ᵙᵢᵨᵳ, reason: contains not printable characters */
    public C1140 f510;

    /* renamed from: ᵛˈᵤ, reason: contains not printable characters */
    public final SimpleDateFormat f511;

    /* renamed from: ᵡᵘˎʽ, reason: contains not printable characters */
    public C1140 f512;

    /* renamed from: ᵡᵶᵡ, reason: contains not printable characters */
    public final Calendar f513;

    /* renamed from: ᵳᵹᵺˋ, reason: contains not printable characters */
    public final Calendar f514;

    /* renamed from: ﾞⁱ, reason: contains not printable characters */
    public String f515;

    public DatePicker(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, R.attr._11_res_0x7f0401d8);
    }

    public DatePicker(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
        this.f511 = simpleDateFormat;
        Locale locale = Locale.getDefault();
        getContext().getResources();
        this.f507 = new ᵶˉᵹʣ(locale);
        this.f508 = ᵭʝʜ.ˌʾˀ(this.f508, locale);
        this.f514 = ᵭʝʜ.ˌʾˀ(this.f514, (Locale) this.f507.ᵢˇᵭ);
        this.f513 = ᵭʝʜ.ˌʾˀ(this.f513, (Locale) this.f507.ᵢˇᵭ);
        this.f505 = ᵭʝʜ.ˌʾˀ(this.f505, (Locale) this.f507.ᵢˇᵭ);
        C1140 c1140 = this.f510;
        if (c1140 != null) {
            c1140.f4887 = (String[]) this.f507.ᵿʗᵝʽ;
            m352(this.f506, c1140);
        }
        int[] iArr = AbstractC4459.f16641;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, iArr);
        AbstractC2873.m7025(this, context, iArr, attributeSet, typedArrayObtainStyledAttributes, 0);
        try {
            String string = typedArrayObtainStyledAttributes.getString(0);
            String string2 = typedArrayObtainStyledAttributes.getString(1);
            String string3 = typedArrayObtainStyledAttributes.getString(2);
            typedArrayObtainStyledAttributes.recycle();
            this.f508.clear();
            boolean zIsEmpty = TextUtils.isEmpty(string);
            Calendar calendar = this.f508;
            if (zIsEmpty) {
                calendar.set(1900, 0, 1);
            } else {
                try {
                    calendar.setTime(simpleDateFormat.parse(string));
                } catch (ParseException unused) {
                    this.f508.set(1900, 0, 1);
                }
            }
            this.f514.setTimeInMillis(this.f508.getTimeInMillis());
            this.f508.clear();
            boolean zIsEmpty2 = TextUtils.isEmpty(string2);
            Calendar calendar2 = this.f508;
            if (zIsEmpty2) {
                calendar2.set(2100, 0, 1);
            } else {
                try {
                    calendar2.setTime(this.f511.parse(string2));
                } catch (ParseException unused2) {
                    this.f508.set(2100, 0, 1);
                }
            }
            this.f513.setTimeInMillis(this.f508.getTimeInMillis());
            setDatePickerFormat(TextUtils.isEmpty(string3) ? new String(DateFormat.getDateFormatOrder(context)) : string3);
        } catch (Throwable th) {
            typedArrayObtainStyledAttributes.recycle();
            throw th;
        }
    }

    public long getDate() {
        return this.f505.getTimeInMillis();
    }

    public String getDatePickerFormat() {
        return this.f515;
    }

    public long getMaxDate() {
        return this.f513.getTimeInMillis();
    }

    public long getMinDate() {
        return this.f514.getTimeInMillis();
    }

    public void setDate(long j) {
        this.f508.setTimeInMillis(j);
        m343(this.f508.get(1), this.f508.get(2), this.f508.get(5));
    }

    public void setDatePickerFormat(String str) {
        if (TextUtils.isEmpty(str)) {
            str = new String(DateFormat.getDateFormatOrder(getContext()));
        }
        if (TextUtils.equals(this.f515, str)) {
            return;
        }
        this.f515 = str;
        ᵶˉᵹʣ r0 = this.f507;
        String bestDateTimePattern = DateFormat.getBestDateTimePattern((Locale) r0.ᵢˇᵭ, str);
        if (TextUtils.isEmpty(bestDateTimePattern)) {
            bestDateTimePattern = "MM/dd/yyyy";
        }
        ArrayList arrayList = new ArrayList();
        StringBuilder sb = new StringBuilder();
        char[] cArr = {'Y', 'y', 'M', 'm', 'D', 'd'};
        boolean z = false;
        char c = 0;
        for (int i = 0; i < bestDateTimePattern.length(); i++) {
            char cCharAt = bestDateTimePattern.charAt(i);
            if (cCharAt != ' ') {
                if (cCharAt != '\'') {
                    if (!z) {
                        int i2 = 0;
                        while (true) {
                            if (i2 >= 6) {
                                sb.append(cCharAt);
                                break;
                            } else if (cCharAt != cArr[i2]) {
                                i2++;
                            } else if (cCharAt != c) {
                                arrayList.add(sb.toString());
                                sb.setLength(0);
                            }
                        }
                    } else {
                        sb.append(cCharAt);
                    }
                    c = cCharAt;
                } else if (z) {
                    z = false;
                } else {
                    sb.setLength(0);
                    z = true;
                }
            }
        }
        arrayList.add(sb.toString());
        if (arrayList.size() != str.length() + 1) {
            ᵨᴵᵺ.ˇʼʤˎ(arrayList.size(), str.length(), " must equal the size of datePickerFormat: ");
            return;
        }
        setSeparators(arrayList);
        this.f512 = null;
        this.f510 = null;
        this.f509 = null;
        this.f506 = -1;
        this.f503 = -1;
        this.f504 = -1;
        String upperCase = str.toUpperCase((Locale) r0.ᵢˇᵭ);
        ArrayList arrayList2 = new ArrayList(3);
        for (int i3 = 0; i3 < upperCase.length(); i3++) {
            char cCharAt2 = upperCase.charAt(i3);
            if (cCharAt2 == 'D') {
                if (this.f512 != null) {
                    ᵹˉᵞ.ˌᵜᵹᵩ("datePicker format error");
                    return;
                }
                C1140 c1140 = new C1140();
                this.f512 = c1140;
                arrayList2.add(c1140);
                this.f512.f4883 = "%02d";
                this.f503 = i3;
            } else if (cCharAt2 != 'M') {
                if (cCharAt2 != 'Y') {
                    ᵹˉᵞ.ˌᵜᵹᵩ("datePicker format error");
                    return;
                }
                if (this.f509 != null) {
                    ᵹˉᵞ.ˌᵜᵹᵩ("datePicker format error");
                    return;
                }
                C1140 c11402 = new C1140();
                this.f509 = c11402;
                arrayList2.add(c11402);
                this.f504 = i3;
                this.f509.f4883 = "%d";
            } else {
                if (this.f510 != null) {
                    ᵹˉᵞ.ˌᵜᵹᵩ("datePicker format error");
                    return;
                }
                C1140 c11403 = new C1140();
                this.f510 = c11403;
                arrayList2.add(c11403);
                this.f510.f4887 = (String[]) r0.ᵿʗᵝʽ;
                this.f506 = i3;
            }
        }
        setColumns(arrayList2);
        post(new RunnableC2802(5, this));
    }

    public void setMaxDate(long j) {
        this.f508.setTimeInMillis(j);
        if (this.f508.get(1) != this.f513.get(1) || this.f508.get(6) == this.f513.get(6)) {
            this.f513.setTimeInMillis(j);
            if (this.f505.after(this.f513)) {
                this.f505.setTimeInMillis(this.f513.getTimeInMillis());
            }
            post(new RunnableC2802(5, this));
        }
    }

    public void setMinDate(long j) {
        this.f508.setTimeInMillis(j);
        if (this.f508.get(1) != this.f514.get(1) || this.f508.get(6) == this.f514.get(6)) {
            this.f514.setTimeInMillis(j);
            if (this.f505.before(this.f514)) {
                this.f505.setTimeInMillis(this.f514.getTimeInMillis());
            }
            post(new RunnableC2802(5, this));
        }
    }

    @Override // androidx.leanback.widget.picker.Picker
    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final void mo342(int i, int i2) {
        this.f508.setTimeInMillis(this.f505.getTimeInMillis());
        int i3 = m348(i).f4885;
        if (i == this.f503) {
            this.f508.add(5, i2 - i3);
        } else if (i == this.f506) {
            this.f508.add(2, i2 - i3);
        } else {
            if (i != this.f504) {
                ᵨᴵᵺ.ᵻᵢﹳᵰ();
                return;
            }
            this.f508.add(1, i2 - i3);
        }
        m343(this.f508.get(1), this.f508.get(2), this.f508.get(5));
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final void m343(int i, int i2, int i3) {
        if (this.f505.get(1) == i && this.f505.get(2) == i3 && this.f505.get(5) == i2) {
            return;
        }
        this.f505.set(i, i2, i3);
        boolean zBefore = this.f505.before(this.f514);
        Calendar calendar = this.f505;
        if (zBefore) {
            calendar.setTimeInMillis(this.f514.getTimeInMillis());
        } else if (calendar.after(this.f513)) {
            this.f505.setTimeInMillis(this.f513.getTimeInMillis());
        }
        post(new RunnableC2802(5, this));
    }
}
