Skip to content

Commit

Permalink
Merge pull request #7094 from ashcoding/TIMOB-19192-Bug-Fix
Browse files Browse the repository at this point in the history
[TIMOB-19192] Android 5.0.X: Fix for event fired
  • Loading branch information
ashcoding committed Aug 31, 2015
2 parents ccb204b + 91885e6 commit fbb0119
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class TiUIDatePicker extends TiUIView

protected Date minDate, maxDate;
protected int minuteInterval;
protected int currentYear;
protected int currentMonth;
protected int currentDayOfMonth;

public TiUIDatePicker(TiViewProxy proxy)
{
Expand Down Expand Up @@ -120,7 +123,10 @@ public void processProperties(KrollDict d) {
}
}
suppressChangeEvent = true;
picker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), this);
currentYear = calendar.get(Calendar.YEAR);
currentMonth = calendar.get(Calendar.MONTH);
currentDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
picker.init(currentYear, currentMonth, currentDayOfMonth, this);
suppressChangeEvent = false;

if (!valueExistsInProxy) {
Expand Down Expand Up @@ -154,6 +160,20 @@ public void propertyChanged(String key, Object oldValue, Object newValue,

public void onDateChanged(DatePicker picker, int year, int monthOfYear, int dayOfMonth)
{
// TIMOB-19192 There seems to be a bug that calls onDateChanged twice on Android 5.0.X.
// This checks if the previous date and changed date is the same before firing any changes.
// If the dates are the same, nothing has changed, hence it is returned.
if ((picker.getYear() == currentYear)
&& (picker.getMonth() == currentMonth)
&& (picker.getDayOfMonth() == currentDayOfMonth)
&& (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP)) {
return;
} else {
currentYear = picker.getYear();
currentMonth = picker.getMonth();
currentDayOfMonth = picker.getDayOfMonth();
}

Calendar targetCalendar = Calendar.getInstance();
targetCalendar.set(Calendar.YEAR, year);
targetCalendar.set(Calendar.MONTH, monthOfYear);
Expand Down

0 comments on commit fbb0119

Please sign in to comment.