Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-19192] Android 5.0.X: Fix for event fired #7094

Merged
merged 1 commit into from
Aug 31, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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