<commit_before>package com.alexstyl.specialdates.addevent.ui;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.transition.TransitionManager;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckedTextView;
import android.widget.LinearLayout;

import com.alexstyl.specialdates.R;
import com.alexstyl.specialdates.contact.Birthday;
import com.alexstyl.specialdates.date.DayDate;
import com.alexstyl.specialdates.upcoming.MonthLabels;
import com.alexstyl.specialdates.util.Utils;
import com.novoda.notils.caster.Views;

import java.util.Locale;

import net.simonvt.numberpicker.NumberPicker;

public class BirthdayDatePicker extends LinearLayout {

    private MonthLabels labels;

    private NumberPicker dayPicker;
    private NumberPicker monthPicker;
    private NumberPicker yearPicker;

    private CheckedTextView includesYearCheckbox;

    private DayDate today;

    public BirthdayDatePicker(Context context, AttributeSet attrs) {
        super(context, attrs);
        super.setOrientation(HORIZONTAL);
        labels = MonthLabels.forLocale(Locale.getDefault());
        today = DayDate.today();
        inflate(getContext(), R.layout.merge_birthday_picker, this);

        dayPicker = Views.findById(this, R.id.day_picker);
        setupDayPicker();

        monthPicker = Views.findById(this, R.id.month_picker);
        setupMonthPicker();

        yearPicker = Views.findById(this, R.id.year_picker);
        setupYearPicker();

        includesYearCheckbox = Views.findById(this, R.id.include_year_checkbox);
        includesYearCheckbox.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean checked = includesYearCheckbox.isChecked();
                includesYearCheckbox.setChecked(!checked);

                if (includesYearCheckbox.isChecked()) {
                    showYearPicker();
                } else {
                    hideYearPicker();
                }
            }

            @TargetApi(Build.VERSION_CODES.KITKAT)
            private void hideYearPicker() {
                if (Utils.hasKitKat()) {
                    TransitionManager.beginDelayedTransition(BirthdayDatePicker.this);
                }
                yearPicker.setVisibility(GONE);
            }

            @TargetApi(Build.VERSION_CODES.KITKAT)
            private void showYearPicker() {
                if (Utils.hasKitKat()) {
                    TransitionManager.beginDelayedTransition(BirthdayDatePicker.this);
                }
                yearPicker.setVisibility(VISIBLE);
            }
        });
    }

    private void setupDayPicker() {
        dayPicker.setMinValue(1);
        dayPicker.setMaxValue(31);

        dayPicker.setValue(today.getDayOfMonth());

    }

    private void setupMonthPicker() {
        monthPicker.setMinValue(1);
        monthPicker.setMaxValue(12);

        monthPicker.setDisplayedValues(labels.getMonthsOfYear());

        monthPicker.setValue(today.getMonth());
    }

    private void setupYearPicker() {
        yearPicker.setMinValue(1900);
        yearPicker.setMaxValue(today.getYear());

        yearPicker.setValue(today.getYear());
    }

    public void setDisplayingDate(Birthday dateToDisplay) {
        if (dateToDisplay.includesYear()) {
            dayPicker.setValue(dateToDisplay.getDayOfMonth());
            monthPicker.setValue(dateToDisplay.getMonth());
            yearPicker.setValue(dateToDisplay.getYear());
            includesYearCheckbox.setChecked(true);
        } else {
            dayPicker.setValue(dateToDisplay.getDayOfMonth());
            monthPicker.setValue(dateToDisplay.getMonth());
            yearPicker.setValue(DayDate.today().getYear());
            includesYearCheckbox.setChecked(false);
        }
    }

    public Birthday getDisplayingBirthday() {<commit_msg>Hide or show the year picker depending on birthday year<commit_after>package com.alexstyl.specialdates.addevent.ui;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.transition.TransitionManager;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckedTextView;
import android.widget.LinearLayout;

import com.alexstyl.specialdates.R;
import com.alexstyl.specialdates.contact.Birthday;
import com.alexstyl.specialdates.date.DayDate;
import com.alexstyl.specialdates.upcoming.MonthLabels;
import com.alexstyl.specialdates.util.Utils;
import com.novoda.notils.caster.Views;

import java.util.Locale;

import net.simonvt.numberpicker.NumberPicker;

public class BirthdayDatePicker extends LinearLayout {

    private MonthLabels labels;

    private NumberPicker dayPicker;
    private NumberPicker monthPicker;
    private NumberPicker yearPicker;

    private CheckedTextView includesYearCheckbox;

    private DayDate today;

    public BirthdayDatePicker(Context context, AttributeSet attrs) {
        super(context, attrs);
        super.setOrientation(HORIZONTAL);
        labels = MonthLabels.forLocale(Locale.getDefault());
        today = DayDate.today();
        inflate(getContext(), R.layout.merge_birthday_picker, this);

        dayPicker = Views.findById(this, R.id.day_picker);
        setupDayPicker();

        monthPicker = Views.findById(this, R.id.month_picker);
        setupMonthPicker();

        yearPicker = Views.findById(this, R.id.year_picker);
        setupYearPicker();

        includesYearCheckbox = Views.findById(this, R.id.include_year_checkbox);
        includesYearCheckbox.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean checked = includesYearCheckbox.isChecked();
                includesYearCheckbox.setChecked(!checked);

                if (includesYearCheckbox.isChecked()) {
                    showYearPicker();
                } else {
                    hideYearPicker();
                }
            }

            @TargetApi(Build.VERSION_CODES.KITKAT)
            private void hideYearPicker() {
                if (Utils.hasKitKat()) {
                    TransitionManager.beginDelayedTransition(BirthdayDatePicker.this);
                }
                yearPicker.setVisibility(GONE);
            }

            @TargetApi(Build.VERSION_CODES.KITKAT)
            private void showYearPicker() {
                if (Utils.hasKitKat()) {
                    TransitionManager.beginDelayedTransition(BirthdayDatePicker.this);
                }
                yearPicker.setVisibility(VISIBLE);
            }
        });
    }

    private void setupDayPicker() {
        dayPicker.setMinValue(1);
        dayPicker.setMaxValue(31);

        dayPicker.setValue(today.getDayOfMonth());

    }

    private void setupMonthPicker() {
        monthPicker.setMinValue(1);
        monthPicker.setMaxValue(12);

        monthPicker.setDisplayedValues(labels.getMonthsOfYear());

        monthPicker.setValue(today.getMonth());
    }

    private void setupYearPicker() {
        yearPicker.setMinValue(1900);
        yearPicker.setMaxValue(today.getYear());

        yearPicker.setValue(today.getYear());
    }

    public void setDisplayingDate(Birthday dateToDisplay) {
        if (dateToDisplay.includesYear()) {
            dayPicker.setValue(dateToDisplay.getDayOfMonth());
            monthPicker.setValue(dateToDisplay.getMonth());
            yearPicker.setValue(dateToDisplay.getYear());
            yearPicker.setVisibility(VISIBLE);
            includesYearCheckbox.setChecked(true);
        } else {
            dayPicker.setValue(dateToDisplay.getDayOfMonth());
            monthPicker.setValue(dateToDisplay.getMonth());
            yearPicker.setValue(DayDate.today().getYear());
            yearPicker.setVisibility(GONE);
            includesYearCheckbox.setChecked(false);
        }
    }

    public Birthday getDisplayingBirthday() {
{'fraction_non_alphanumeric': 0.09457267623206488, 'fraction_numerical': 0.002495321272613849, 'mean_word_length': 2.6536007292616226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2501075', 'n_tokens_mistral': 2216, 'n_tokens_neox': 2106, 'n_words': 323}