From 07c12e83d0dd7b1d8d9d84273878adf66d366383 Mon Sep 17 00:00:00 2001 From: Sander Baas Date: Wed, 27 May 2015 16:18:27 +0200 Subject: [PATCH 1/3] Add option to disable notifications in quiet time Fixes #661 --- k9mail/src/main/java/com/fsck/k9/K9.java | 11 +++++++++++ .../main/java/com/fsck/k9/activity/setup/Prefs.java | 5 +++++ .../com/fsck/k9/controller/MessagingController.java | 5 +++++ k9mail/src/main/res/values/strings.xml | 2 ++ k9mail/src/main/res/xml/global_preferences.xml | 7 +++++++ 5 files changed, 30 insertions(+) diff --git a/k9mail/src/main/java/com/fsck/k9/K9.java b/k9mail/src/main/java/com/fsck/k9/K9.java index 87fa1237d..b246c9675 100644 --- a/k9mail/src/main/java/com/fsck/k9/K9.java +++ b/k9mail/src/main/java/com/fsck/k9/K9.java @@ -237,6 +237,7 @@ public class K9 extends Application { private static boolean mHideSpecialAccounts = false; private static boolean mAutofitWidth; private static boolean mQuietTimeEnabled = false; + private static boolean mQuietTimeNotificationEnabled = false; private static String mQuietTimeStarts = null; private static String mQuietTimeEnds = null; private static String mAttachmentDefaultPath = ""; @@ -474,6 +475,7 @@ public class K9 extends Application { editor.putBoolean("useVolumeKeysForListNavigation", mUseVolumeKeysForListNavigation); editor.putBoolean("autofitWidth", mAutofitWidth); editor.putBoolean("quietTimeEnabled", mQuietTimeEnabled); + editor.putBoolean("quietTimeNotificationEnabled", mQuietTimeNotificationEnabled); editor.putString("quietTimeStarts", mQuietTimeStarts); editor.putString("quietTimeEnds", mQuietTimeEnds); @@ -708,6 +710,7 @@ public class K9 extends Application { mAutofitWidth = sprefs.getBoolean("autofitWidth", true); mQuietTimeEnabled = sprefs.getBoolean("quietTimeEnabled", false); + mQuietTimeNotificationEnabled = sprefs.getBoolean("quietTimeNotificationEnabled", false); mQuietTimeStarts = sprefs.getString("quietTimeStarts", "21:00"); mQuietTimeEnds = sprefs.getString("quietTimeEnds", "7:00"); @@ -970,6 +973,14 @@ public class K9 extends Application { mQuietTimeEnabled = quietTimeEnabled; } + public static boolean getQuietTimeNotificationEnabled() { + return mQuietTimeNotificationEnabled; + } + + public static void setQuietTimeNotificationEnabled(boolean quietTimeNotificationEnabled) { + mQuietTimeNotificationEnabled = quietTimeNotificationEnabled; + } + public static String getQuietTimeStarts() { return mQuietTimeStarts; } diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/Prefs.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/Prefs.java index 96d34846d..acd8d0a34 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/Prefs.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/Prefs.java @@ -79,6 +79,7 @@ public class Prefs extends K9PreferenceActivity { private static final String PREFERENCE_MESSAGEVIEW_RETURN_TO_LIST = "messageview_return_to_list"; private static final String PREFERENCE_MESSAGEVIEW_SHOW_NEXT = "messageview_show_next"; private static final String PREFERENCE_QUIET_TIME_ENABLED = "quiet_time_enabled"; + private static final String PREFERENCE_QUIET_TIME_NOTIFICATION_ENABLED = "quiet_time_notification_enabled"; private static final String PREFERENCE_QUIET_TIME_STARTS = "quiet_time_starts"; private static final String PREFERENCE_QUIET_TIME_ENDS = "quiet_time_ends"; private static final String PREFERENCE_NOTIF_QUICK_DELETE = "notification_quick_delete"; @@ -142,6 +143,7 @@ public class Prefs extends K9PreferenceActivity { private CheckBoxListPreference mVisibleRefileActions; private CheckBoxPreference mQuietTimeEnabled; + private CheckBoxPreference mQuietTimeNotificationEnabled; private com.fsck.k9.preferences.TimePickerPreference mQuietTimeStarts; private com.fsck.k9.preferences.TimePickerPreference mQuietTimeEnds; private ListPreference mNotificationQuickDelete; @@ -309,6 +311,8 @@ public class Prefs extends K9PreferenceActivity { mQuietTimeEnabled = (CheckBoxPreference) findPreference(PREFERENCE_QUIET_TIME_ENABLED); mQuietTimeEnabled.setChecked(K9.getQuietTimeEnabled()); + mQuietTimeNotificationEnabled = (CheckBoxPreference) findPreference(PREFERENCE_QUIET_TIME_NOTIFICATION_ENABLED); + mQuietTimeNotificationEnabled.setChecked(K9.getQuietTimeNotificationEnabled()); mQuietTimeStarts = (TimePickerPreference) findPreference(PREFERENCE_QUIET_TIME_STARTS); mQuietTimeStarts.setDefaultValue(K9.getQuietTimeStarts()); mQuietTimeStarts.setSummary(K9.getQuietTimeStarts()); @@ -485,6 +489,7 @@ public class Prefs extends K9PreferenceActivity { K9.setMessageViewCopyActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_COPY]); K9.setMessageViewSpamActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_SPAM]); + K9.setQuietTimeNotificationEnabled(mQuietTimeNotificationEnabled.isChecked()); K9.setQuietTimeStarts(mQuietTimeStarts.getTime()); K9.setQuietTimeEnds(mQuietTimeEnds.getTime()); K9.setWrapFolderNames(mWrapFolderNames.isChecked()); diff --git a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java index bc2f79108..94bf7fe55 100644 --- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -4685,6 +4685,11 @@ public class MessagingController implements Runnable { */ private void notifyAccount(Context context, Account account, LocalMessage message, int previousUnreadMessageCount) { + // if it's quiet time and notifications are disabled, then we shouldn't show a notification + if (K9.isQuietTime() && K9.getQuietTimeNotificationEnabled()) { + return; + } + final NotificationData data = getNotificationData(account, previousUnreadMessageCount); synchronized (data) { notifyAccountWithDataLocked(context, account, message, data); diff --git a/k9mail/src/main/res/values/strings.xml b/k9mail/src/main/res/values/strings.xml index 988750b5f..873f37b06 100644 --- a/k9mail/src/main/res/values/strings.xml +++ b/k9mail/src/main/res/values/strings.xml @@ -353,6 +353,8 @@ Please submit bug reports, contribute new features and ask questions at Quiet Time Disable ringing, buzzing and flashing at night + Quiet Time notifications + Disable notifications during quiet time Quiet Time starts Quiet Time ends diff --git a/k9mail/src/main/res/xml/global_preferences.xml b/k9mail/src/main/res/xml/global_preferences.xml index 70f23b192..77c18cc10 100644 --- a/k9mail/src/main/res/xml/global_preferences.xml +++ b/k9mail/src/main/res/xml/global_preferences.xml @@ -303,6 +303,13 @@ android:title="@string/quiet_time" android:summary="@string/quiet_time_description" /> + Date: Sun, 28 Jun 2015 05:08:31 +0200 Subject: [PATCH 2/3] Change naming/wording --- k9mail/src/main/java/com/fsck/k9/K9.java | 14 +++++++------- .../java/com/fsck/k9/activity/setup/Prefs.java | 12 +++++++----- .../fsck/k9/controller/MessagingController.java | 6 ++---- k9mail/src/main/res/values/strings.xml | 4 ++-- k9mail/src/main/res/xml/global_preferences.xml | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/K9.java b/k9mail/src/main/java/com/fsck/k9/K9.java index b246c9675..fedce1adb 100644 --- a/k9mail/src/main/java/com/fsck/k9/K9.java +++ b/k9mail/src/main/java/com/fsck/k9/K9.java @@ -237,7 +237,7 @@ public class K9 extends Application { private static boolean mHideSpecialAccounts = false; private static boolean mAutofitWidth; private static boolean mQuietTimeEnabled = false; - private static boolean mQuietTimeNotificationEnabled = false; + private static boolean mNotificationDuringQuietTimeEnabled = true; private static String mQuietTimeStarts = null; private static String mQuietTimeEnds = null; private static String mAttachmentDefaultPath = ""; @@ -475,7 +475,7 @@ public class K9 extends Application { editor.putBoolean("useVolumeKeysForListNavigation", mUseVolumeKeysForListNavigation); editor.putBoolean("autofitWidth", mAutofitWidth); editor.putBoolean("quietTimeEnabled", mQuietTimeEnabled); - editor.putBoolean("quietTimeNotificationEnabled", mQuietTimeNotificationEnabled); + editor.putBoolean("notificationDuringQuietTimeEnabled", mNotificationDuringQuietTimeEnabled); editor.putString("quietTimeStarts", mQuietTimeStarts); editor.putString("quietTimeEnds", mQuietTimeEnds); @@ -710,7 +710,7 @@ public class K9 extends Application { mAutofitWidth = sprefs.getBoolean("autofitWidth", true); mQuietTimeEnabled = sprefs.getBoolean("quietTimeEnabled", false); - mQuietTimeNotificationEnabled = sprefs.getBoolean("quietTimeNotificationEnabled", false); + mNotificationDuringQuietTimeEnabled = sprefs.getBoolean("notificationDuringQuietTimeEnabled", true); mQuietTimeStarts = sprefs.getString("quietTimeStarts", "21:00"); mQuietTimeEnds = sprefs.getString("quietTimeEnds", "7:00"); @@ -973,12 +973,12 @@ public class K9 extends Application { mQuietTimeEnabled = quietTimeEnabled; } - public static boolean getQuietTimeNotificationEnabled() { - return mQuietTimeNotificationEnabled; + public static boolean isNotificationDuringQuietTimeEnabled() { + return mNotificationDuringQuietTimeEnabled; } - public static void setQuietTimeNotificationEnabled(boolean quietTimeNotificationEnabled) { - mQuietTimeNotificationEnabled = quietTimeNotificationEnabled; + public static void setNotificationDuringQuietTimeEnabled(boolean notificationDuringQuietTimeEnabled) { + mNotificationDuringQuietTimeEnabled = notificationDuringQuietTimeEnabled; } public static String getQuietTimeStarts() { diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/Prefs.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/Prefs.java index acd8d0a34..c4482e9cf 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/Prefs.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/Prefs.java @@ -79,7 +79,8 @@ public class Prefs extends K9PreferenceActivity { private static final String PREFERENCE_MESSAGEVIEW_RETURN_TO_LIST = "messageview_return_to_list"; private static final String PREFERENCE_MESSAGEVIEW_SHOW_NEXT = "messageview_show_next"; private static final String PREFERENCE_QUIET_TIME_ENABLED = "quiet_time_enabled"; - private static final String PREFERENCE_QUIET_TIME_NOTIFICATION_ENABLED = "quiet_time_notification_enabled"; + private static final String PREFERENCE_DISABLE_NOTIFICATION_DURING_QUIET_TIME = + "disable_notifications_during_quiet_time"; private static final String PREFERENCE_QUIET_TIME_STARTS = "quiet_time_starts"; private static final String PREFERENCE_QUIET_TIME_ENDS = "quiet_time_ends"; private static final String PREFERENCE_NOTIF_QUICK_DELETE = "notification_quick_delete"; @@ -143,7 +144,7 @@ public class Prefs extends K9PreferenceActivity { private CheckBoxListPreference mVisibleRefileActions; private CheckBoxPreference mQuietTimeEnabled; - private CheckBoxPreference mQuietTimeNotificationEnabled; + private CheckBoxPreference mDisableNotificationDuringQuietTime; private com.fsck.k9.preferences.TimePickerPreference mQuietTimeStarts; private com.fsck.k9.preferences.TimePickerPreference mQuietTimeEnds; private ListPreference mNotificationQuickDelete; @@ -311,8 +312,9 @@ public class Prefs extends K9PreferenceActivity { mQuietTimeEnabled = (CheckBoxPreference) findPreference(PREFERENCE_QUIET_TIME_ENABLED); mQuietTimeEnabled.setChecked(K9.getQuietTimeEnabled()); - mQuietTimeNotificationEnabled = (CheckBoxPreference) findPreference(PREFERENCE_QUIET_TIME_NOTIFICATION_ENABLED); - mQuietTimeNotificationEnabled.setChecked(K9.getQuietTimeNotificationEnabled()); + mDisableNotificationDuringQuietTime = (CheckBoxPreference) findPreference( + PREFERENCE_DISABLE_NOTIFICATION_DURING_QUIET_TIME); + mDisableNotificationDuringQuietTime.setChecked(!K9.isNotificationDuringQuietTimeEnabled()); mQuietTimeStarts = (TimePickerPreference) findPreference(PREFERENCE_QUIET_TIME_STARTS); mQuietTimeStarts.setDefaultValue(K9.getQuietTimeStarts()); mQuietTimeStarts.setSummary(K9.getQuietTimeStarts()); @@ -489,7 +491,7 @@ public class Prefs extends K9PreferenceActivity { K9.setMessageViewCopyActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_COPY]); K9.setMessageViewSpamActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_SPAM]); - K9.setQuietTimeNotificationEnabled(mQuietTimeNotificationEnabled.isChecked()); + K9.setNotificationDuringQuietTimeEnabled(!mDisableNotificationDuringQuietTime.isChecked()); K9.setQuietTimeStarts(mQuietTimeStarts.getTime()); K9.setQuietTimeEnds(mQuietTimeEnds.getTime()); K9.setWrapFolderNames(mWrapFolderNames.isChecked()); diff --git a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java index 94bf7fe55..ba3e77ede 100644 --- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -4683,10 +4683,8 @@ public class MessagingController implements Runnable { /** * Creates a notification of a newly received message. */ - private void notifyAccount(Context context, Account account, - LocalMessage message, int previousUnreadMessageCount) { - // if it's quiet time and notifications are disabled, then we shouldn't show a notification - if (K9.isQuietTime() && K9.getQuietTimeNotificationEnabled()) { + private void notifyAccount(Context context, Account account, LocalMessage message, int previousUnreadMessageCount) { + if (K9.isQuietTime() && !K9.isNotificationDuringQuietTimeEnabled()) { return; } diff --git a/k9mail/src/main/res/values/strings.xml b/k9mail/src/main/res/values/strings.xml index 873f37b06..22a7ddc17 100644 --- a/k9mail/src/main/res/values/strings.xml +++ b/k9mail/src/main/res/values/strings.xml @@ -353,8 +353,8 @@ Please submit bug reports, contribute new features and ask questions at Quiet Time Disable ringing, buzzing and flashing at night - Quiet Time notifications - Disable notifications during quiet time + Disable notifications + Completely disable notifications during Quiet Time Quiet Time starts Quiet Time ends diff --git a/k9mail/src/main/res/xml/global_preferences.xml b/k9mail/src/main/res/xml/global_preferences.xml index 77c18cc10..9ce88ffca 100644 --- a/k9mail/src/main/res/xml/global_preferences.xml +++ b/k9mail/src/main/res/xml/global_preferences.xml @@ -304,7 +304,7 @@ android:summary="@string/quiet_time_description" /> Date: Sun, 28 Jun 2015 05:24:30 +0200 Subject: [PATCH 3/3] Add 'notificationDuringQuietTimeEnabled' to settings import/export --- .../src/main/java/com/fsck/k9/preferences/GlobalSettings.java | 3 +++ k9mail/src/main/java/com/fsck/k9/preferences/Settings.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java b/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java index be3de86d9..6ac2ac684 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java @@ -266,6 +266,9 @@ public class GlobalSettings { new V(38, new EnumSetting(NotificationQuickDelete.class, NotificationQuickDelete.NEVER)) )); + s.put("notificationDuringQuietTimeEnabled", Settings.versions( + new V(39, new BooleanSetting(true)) + )); SETTINGS = Collections.unmodifiableMap(s); diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java b/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java index 9c466dcf0..b9c55a7f3 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java @@ -35,7 +35,7 @@ public class Settings { * * @see SettingsExporter */ - public static final int VERSION = 38; + public static final int VERSION = 39; public static Map validate(int version, Map> settings,