diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/NotificationService.java | 6 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/TimePreference.java | 39 |
2 files changed, 20 insertions, 25 deletions
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index ca6c8bc42..6e93145b8 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -209,9 +209,9 @@ public class NotificationService { return false; } final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService); - final long startTime = preferences.getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY; - final long endTime = preferences.getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY; - final long nowTime = Calendar.getInstance().getTimeInMillis() % Config.MILLISECONDS_IN_DAY; + final long startTime = TimePreference.minutesToTimestamp(preferences.getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE)); + final long endTime = TimePreference.minutesToTimestamp(preferences.getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE)); + final long nowTime = Calendar.getInstance().getTimeInMillis(); if (endTime < startTime) { return nowTime > startTime || nowTime < endTime; diff --git a/src/main/java/de/pixart/messenger/ui/TimePreference.java b/src/main/java/de/pixart/messenger/ui/TimePreference.java index 731a3bb50..d3149a531 100644 --- a/src/main/java/de/pixart/messenger/ui/TimePreference.java +++ b/src/main/java/de/pixart/messenger/ui/TimePreference.java @@ -25,11 +25,12 @@ public class TimePreference extends DialogPreference implements Preference.OnPre persistLong(time); notifyDependencyChange(shouldDisableDependents()); notifyChanged(); + updateSummary(time); } - protected void updateSummary(final long time) { + private void updateSummary(final long time) { final DateFormat dateFormat = android.text.format.DateFormat.getTimeFormat(getContext()); - final Date date = new Date(time); + final Date date = minutesToCalender(time).getTime(); setSummary(dateFormat.format(date.getTime())); } @@ -40,21 +41,13 @@ public class TimePreference extends DialogPreference implements Preference.OnPre return picker; } - protected Calendar getPersistedTime() { - final Calendar c = Calendar.getInstance(); - c.setTimeInMillis(getPersistedLong(DEFAULT_VALUE)); - - return c; - } - @SuppressWarnings("NullableProblems") @Override protected void onBindDialogView(final View v) { super.onBindDialogView(v); - final Calendar c = getPersistedTime(); - - picker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY)); - picker.setCurrentMinute(c.get(Calendar.MINUTE)); + long time = getPersistedLong(DEFAULT_VALUE); + picker.setCurrentHour((int) (time / 60)); + picker.setCurrentMinute((int) (time % 60)); } @Override @@ -62,17 +55,19 @@ public class TimePreference extends DialogPreference implements Preference.OnPre super.onDialogClosed(positiveResult); if (positiveResult) { - final Calendar c = Calendar.getInstance(); - c.set(Calendar.MINUTE, picker.getCurrentMinute()); - c.set(Calendar.HOUR_OF_DAY, picker.getCurrentHour()); - + setTime(picker.getCurrentHour() * 60 + picker.getCurrentMinute()); + } + } - if (!callChangeListener(c.getTimeInMillis())) { - return; - } + private static Calendar minutesToCalender(long time) { + final Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, (int) ((time % (24 * 60)) / 60)); + c.set(Calendar.MINUTE, (int) ((time % (24 * 60)) % 60)); + return c; + } - setTime(c.getTimeInMillis()); - } + public static long minutesToTimestamp(long time) { + return minutesToCalender(time).getTimeInMillis(); } @Override |