aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-12-17 07:15:31 +0100
committerDaniel Gultsch <daniel@gultsch.de>2014-12-17 07:15:31 +0100
commit5603440a91e72ac4d5c7043b85ff211425a592b9 (patch)
treefc5edd016d58fcc6e0ebd4306d2ecc8074a5e2bd /src
parent1a7ed4ed7c56bc0af70ebdaf67f71da9205f6afd (diff)
parent0b4987581f6aeebd2b8c729b83aaebf9998ec0d6 (diff)
Merge pull request #783 from SamWhited/quiet-hours
Update summary in TimePreference change listener
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/Config.java2
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java19
-rw-r--r--src/main/java/eu/siacs/conversations/ui/TimePreference.java16
3 files changed, 19 insertions, 18 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java
index 698c403f..90e4a899 100644
--- a/src/main/java/eu/siacs/conversations/Config.java
+++ b/src/main/java/eu/siacs/conversations/Config.java
@@ -24,7 +24,7 @@ public final class Config {
public static final boolean NO_PROXY_LOOKUP = false; //useful to debug ibb
- private static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
+ public static final long MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
public static final long MAM_MAX_CATCHUP = MILLISECONDS_IN_DAY / 2;
public static final int MAM_MAX_MESSAGES = 500;
diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java
index 9e21d160..c27ab72a 100644
--- a/src/main/java/eu/siacs/conversations/services/NotificationService.java
+++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java
@@ -72,20 +72,15 @@ public class NotificationService {
if (!mXmppConnectionService.getPreferences().getBoolean("enable_quiet_hours", false)) {
return false;
}
- final Calendar startTime = Calendar.getInstance();
- startTime.setTimeInMillis(mXmppConnectionService.getPreferences().getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE));
- final Calendar endTime = Calendar.getInstance();
- endTime.setTimeInMillis(mXmppConnectionService.getPreferences().getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE));
- final Calendar nowTime = Calendar.getInstance();
+ final long startTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_start", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
+ final long endTime = mXmppConnectionService.getPreferences().getLong("quiet_hours_end", TimePreference.DEFAULT_VALUE) % Config.MILLISECONDS_IN_DAY;
+ final long nowTime = Calendar.getInstance().getTimeInMillis() % Config.MILLISECONDS_IN_DAY;
- startTime.set(nowTime.get(Calendar.YEAR), nowTime.get(Calendar.MONTH), nowTime.get(Calendar.DATE));
- endTime.set(nowTime.get(Calendar.YEAR), nowTime.get(Calendar.MONTH), nowTime.get(Calendar.DATE));
-
- if (endTime.before(startTime)) {
- endTime.add(Calendar.DATE, 1);
+ if (endTime < startTime) {
+ return nowTime > startTime || nowTime < endTime;
+ } else {
+ return nowTime > startTime && nowTime < endTime;
}
-
- return nowTime.after(startTime) && nowTime.before(endTime);
}
public boolean conferenceNotificationsEnabled() {
diff --git a/src/main/java/eu/siacs/conversations/ui/TimePreference.java b/src/main/java/eu/siacs/conversations/ui/TimePreference.java
index 44a36224..e32b068c 100644
--- a/src/main/java/eu/siacs/conversations/ui/TimePreference.java
+++ b/src/main/java/eu/siacs/conversations/ui/TimePreference.java
@@ -3,6 +3,7 @@ package eu.siacs.conversations.ui;
import android.content.Context;
import android.content.res.TypedArray;
import android.preference.DialogPreference;
+import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TimePicker;
@@ -11,12 +12,13 @@ import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
-public class TimePreference extends DialogPreference {
+public class TimePreference extends DialogPreference implements Preference.OnPreferenceChangeListener {
private TimePicker picker = null;
public final static long DEFAULT_VALUE = 0;
public TimePreference(final Context context, final AttributeSet attrs) {
super(context, attrs, 0);
+ this.setOnPreferenceChangeListener(this);
}
protected void setTime(final long time) {
@@ -25,8 +27,7 @@ public class TimePreference extends DialogPreference {
notifyChanged();
}
- protected void updateSummary() {
- final long time = getPersistedLong(DEFAULT_VALUE);
+ protected void updateSummary(final long time) {
final DateFormat dateFormat = android.text.format.DateFormat.getTimeFormat(getContext());
final Date date = new Date(time);
setSummary(dateFormat.format(date.getTime()));
@@ -71,7 +72,6 @@ public class TimePreference extends DialogPreference {
}
setTime(c.getTimeInMillis());
- updateSummary();
}
}
@@ -94,6 +94,12 @@ public class TimePreference extends DialogPreference {
}
setTime(time);
- updateSummary();
+ updateSummary(time);
+ }
+
+ @Override
+ public boolean onPreferenceChange(final Preference preference, final Object newValue) {
+ ((TimePreference) preference).updateSummary((Long)newValue);
+ return true;
}
}