<commit_before>package org.openlmis.core.view.listener;

import android.app.DatePickerDialog;
import android.widget.DatePicker;
import android.widget.TextView;

import org.openlmis.core.R;
import org.openlmis.core.utils.DateUtil;
import org.openlmis.core.utils.ToastUtil;
import org.openlmis.core.view.viewmodel.StockMovementViewModel;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class MovementDateListener implements DatePickerDialog.OnDateSetListener {

    private Date previousMovementDate;
    private StockMovementViewModel model;
    TextView movementDateField;

    public MovementDateListener(StockMovementViewModel model, Date previousMovementDate, TextView movementDateField) {
        this.previousMovementDate = previousMovementDate;
        this.model = model;
        this.movementDateField = movementDateField;
    }

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

        Date chosenDate = new GregorianCalendar(year, monthOfYear, dayOfMonth).getTime();
        if (validateStockMovementDate(previousMovementDate, chosenDate)) {
            movementDateField.setText(DateUtil.formatDate(chosenDate));
            model.setMovementDate(DateUtil.formatDate(chosenDate));
        } else {
            ToastUtil.show(R.string.msg_invalid_stock_movement_date);
        }
    }

    private boolean validateStockMovementDate(Date previousMovementDate, Date chosenDate) {
        Calendar today = GregorianCalendar.getInstance();

        return previousMovementDate == null || !previousMovementDate.after(chosenDate) && !chosenDate.after(today.getTime());
    }
}<commit_msg>TK - #1101 - fix movement date validation<commit_after>package org.openlmis.core.view.listener;

import android.app.DatePickerDialog;
import android.widget.DatePicker;
import android.widget.TextView;

import org.openlmis.core.R;
import org.openlmis.core.utils.DateUtil;
import org.openlmis.core.utils.ToastUtil;
import org.openlmis.core.view.viewmodel.StockMovementViewModel;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class MovementDateListener implements DatePickerDialog.OnDateSetListener {

    private Date previousMovementDate;
    private StockMovementViewModel model;
    TextView movementDateField;

    public MovementDateListener(StockMovementViewModel model, Date previousMovementDate, TextView movementDateField) {
        this.previousMovementDate = previousMovementDate;
        this.model = model;
        this.movementDateField = movementDateField;
    }

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

        Date chosenDate = new GregorianCalendar(year, monthOfYear, dayOfMonth).getTime();
        if (validateStockMovementDate(previousMovementDate, chosenDate)) {
            movementDateField.setText(DateUtil.formatDate(chosenDate));
            model.setMovementDate(DateUtil.formatDate(chosenDate));
        } else {
            ToastUtil.show(R.string.msg_invalid_stock_movement_date);
        }
    }

    private boolean validateStockMovementDate(Date previousMovementDate, Date chosenDate) {
        Calendar today = GregorianCalendar.getInstance();

        return (previousMovementDate == null || !previousMovementDate.after(chosenDate)) && !chosenDate.after(today.getTime());
    }
}
{'fraction_non_alphanumeric': 0.08401639344262295, 'fraction_numerical': 0.00117096018735363, 'mean_word_length': 4.406645569620253, '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': '3635757', 'n_tokens_mistral': 978, 'n_tokens_neox': 934, 'n_words': 177}