1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

BUGFIX: time changes are still honored even if the user choose the

[abort] button of the DialogPreference.
This commit is contained in:
mwolschon 2011-04-13 12:18:07 +02:00
parent d68d3c1ea3
commit 9bdfb0d023

View File

@ -25,7 +25,18 @@ public class TimePickerPreference extends DialogPreference implements
* The default value for this preference
*/
private String defaultValue;
/**
* Store the original value, in case the user
* chooses to abort the {@link DialogPreference}
* after making a change.
*/
private int originalHour = 0;
/**
* Store the original value, in case the user
* chooses to abort the {@link DialogPreference}
* after making a change.
*/
private int originalMinute = 0;
/**
* @param context
* @param attrs
@ -64,11 +75,12 @@ public class TimePickerPreference extends DialogPreference implements
TimePicker tp = new TimePicker(getContext());
tp.setOnTimeChangedListener(this);
int h = getHour();
int m = getMinute();
if (h >= 0 && m >= 0) {
tp.setCurrentHour(h);
tp.setCurrentMinute(m);
originalHour = getHour();
originalMinute = getMinute();
if (originalHour >= 0 && originalMinute >= 0)
{
tp.setCurrentHour(originalHour);
tp.setCurrentMinute(originalMinute);
}
return tp;
@ -88,6 +100,17 @@ public class TimePickerPreference extends DialogPreference implements
callChangeListener(String.format("%02d:%02d", hour, minute));
}
@Override
protected void onDialogClosed(boolean positiveResult) {
// Bug #1185 "[SE-QS] GMX: Nach Abbruch der Einstellungen der Ruhezeiten werden diese trotzdem uebernommen"
if (!positiveResult) {
persistString(String.format("%02d:%02d", originalHour, originalMinute));
callChangeListener(String.format("%02d:%02d", originalHour, originalMinute));
}
super.onDialogClosed(positiveResult);
}
/*
* (non-Javadoc)
*