1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-24 02:12: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 * The default value for this preference
*/ */
private String defaultValue; 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 context
* @param attrs * @param attrs
@ -64,11 +75,12 @@ public class TimePickerPreference extends DialogPreference implements
TimePicker tp = new TimePicker(getContext()); TimePicker tp = new TimePicker(getContext());
tp.setOnTimeChangedListener(this); tp.setOnTimeChangedListener(this);
int h = getHour(); originalHour = getHour();
int m = getMinute(); originalMinute = getMinute();
if (h >= 0 && m >= 0) { if (originalHour >= 0 && originalMinute >= 0)
tp.setCurrentHour(h); {
tp.setCurrentMinute(m); tp.setCurrentHour(originalHour);
tp.setCurrentMinute(originalMinute);
} }
return tp; return tp;
@ -88,6 +100,17 @@ public class TimePickerPreference extends DialogPreference implements
callChangeListener(String.format("%02d:%02d", hour, minute)); 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) * (non-Javadoc)
* *