From 7aa4c1308e4e17844d81a85485a0e03d619962b6 Mon Sep 17 00:00:00 2001 From: Philipp Haselwarter Date: Wed, 6 Aug 2014 11:04:07 +0200 Subject: [PATCH 1/6] Configure mail notifications by folder class In response to Issue 1794, - add a configuration option in the account preferences to show notifications only for 1st/2nd/etc class folders - add an option in the folder preferences to set the notification class as 1st, 2nd or inherited from the folder's push class The default behaviour remains unchanged. --- res/values/arrays.xml | 30 ++++++ res/values/strings.xml | 14 +++ res/xml/account_settings_preferences.xml | 9 ++ res/xml/folder_settings_preferences.xml | 8 ++ src/com/fsck/k9/Account.java | 17 +++ .../k9/activity/setup/AccountSettings.java | 16 +++ .../k9/activity/setup/FolderSettings.java | 16 +++ .../k9/controller/MessagingController.java | 25 +++++ src/com/fsck/k9/mail/Folder.java | 3 + src/com/fsck/k9/mail/store/LocalStore.java | 100 +++++++++++++++++- .../fsck/k9/preferences/AccountSettings.java | 3 + .../fsck/k9/preferences/FolderSettings.java | 3 + src/com/fsck/k9/preferences/Settings.java | 2 +- 13 files changed, 241 insertions(+), 5 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 45e0314e1..185dfcdd4 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -231,6 +231,22 @@ 1000 + + @string/account_settings_folder_notify_new_mail_mode_all + @string/account_settings_folder_notify_new_mail_mode_first_class + @string/account_settings_folder_notify_new_mail_mode_first_and_second_class + @string/account_settings_folder_notify_new_mail_mode_not_second_class + @string/account_settings_folder_notify_new_mail_mode_none + + + + ALL + FIRST_CLASS + FIRST_AND_SECOND_CLASS + NOT_SECOND_CLASS + NONE + + @string/account_settings_folder_target_mode_all @string/account_settings_folder_target_mode_first_class @@ -285,6 +301,20 @@ INHERITED + + @string/folder_settings_folder_notify_mode_normal + @string/folder_settings_folder_notify_mode_first_class + @string/folder_settings_folder_notify_mode_second_class + @string/folder_settings_folder_notify_mode_inherited + + + + NO_CLASS + FIRST_CLASS + SECOND_CLASS + INHERITED + + @string/account_setup_incoming_delete_policy_never_label @string/account_setup_incoming_delete_policy_delete_label diff --git a/res/values/strings.xml b/res/values/strings.xml index 6e509193c..040c1166c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -504,6 +504,14 @@ Please submit bug reports, contribute new features and ask questions at Default account Send mail from this account by default New mail notifications + + Notifications folders + All + Only 1st Class folders + 1st and 2nd Class folders + All except 2nd Class folders + None + Sync notifications Your email address Notify in status bar when mail arrives @@ -655,6 +663,12 @@ Please submit bug reports, contribute new features and ask questions at 2nd Class Same as sync class + Folder notification class + None + 1st Class + 2nd Class + Same as push class + Incoming server Configure the incoming mail server Outgoing server diff --git a/res/xml/account_settings_preferences.xml b/res/xml/account_settings_preferences.xml index b0f487b1f..9940c3ccf 100644 --- a/res/xml/account_settings_preferences.xml +++ b/res/xml/account_settings_preferences.xml @@ -343,6 +343,15 @@ android:defaultValue="true" android:summary="@string/account_settings_notify_summary" /> + + + + (FolderMode.class, FolderMode.ALL)) + )); s.put("notifySelfNewMail", Settings.versions( new V(1, new BooleanSetting(true)) )); diff --git a/src/com/fsck/k9/preferences/FolderSettings.java b/src/com/fsck/k9/preferences/FolderSettings.java index aae048092..202d5f09d 100644 --- a/src/com/fsck/k9/preferences/FolderSettings.java +++ b/src/com/fsck/k9/preferences/FolderSettings.java @@ -28,6 +28,9 @@ public class FolderSettings { s.put("displayMode", Settings.versions( new V(1, new EnumSetting(FolderClass.class, FolderClass.NO_CLASS)) )); + s.put("notifyMode", Settings.versions( + new V(33, new EnumSetting(FolderClass.class, FolderClass.INHERITED)) + )); s.put("syncMode", Settings.versions( new V(1, new EnumSetting(FolderClass.class, FolderClass.INHERITED)) )); diff --git a/src/com/fsck/k9/preferences/Settings.java b/src/com/fsck/k9/preferences/Settings.java index b4dd8ef41..22ed1cb1f 100644 --- a/src/com/fsck/k9/preferences/Settings.java +++ b/src/com/fsck/k9/preferences/Settings.java @@ -35,7 +35,7 @@ public class Settings { * * @see SettingsExporter */ - public static final int VERSION = 32; + public static final int VERSION = 33; public static Map validate(int version, Map> settings, From cb67a21a9311d3c31f31c34bc74e7f45deae1eb1 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 4 Sep 2014 21:58:18 +0200 Subject: [PATCH 2/6] Remove commented-out code --- src/com/fsck/k9/controller/MessagingController.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index f9d2027ea..bd60912f6 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -4624,21 +4624,11 @@ public class MessagingController implements Runnable { if (modeMismatch(aDisplayMode, fDisplayClass)) { // Never notify a folder that isn't displayed - /* - if (K9.DEBUG) - Log.v(K9.LOG_TAG, "Not notifying folder " + localFolder.getName() + - " which is in display mode " + fDisplayClass + " while account is in display mode " + aDisplayMode); - */ return false; } if (modeMismatch(aNotifyMode, fNotifyClass)) { // Do not notify folders in the wrong class - /* - if (K9.DEBUG) - Log.v(K9.LOG_TAG, "Not notifying folder " + localFolder.getName() + - " which is in notify mode " + fNotifyClass + " while account is in notify mode " + aNotifyMode); - */ return false; } From bd9efa8d01a1127069b33190d270a013fde14259 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 4 Sep 2014 22:35:03 +0200 Subject: [PATCH 3/6] Whitespace fixes --- src/com/fsck/k9/mail/store/LocalStore.java | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index ba53ef700..2981ad5b4 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -425,10 +425,9 @@ public class LocalStore extends Store implements Serializable { throw e; } } + Cursor cursor = null; - try { - SharedPreferences prefs = getPreferences(); cursor = db.rawQuery("SELECT id, name FROM folders", null); while (cursor.moveToNext()) { @@ -440,12 +439,8 @@ public class LocalStore extends Store implements Serializable { Log.e(K9.LOG_TAG, " error trying to ugpgrade a folder class", e); } } - } - - - catch (SQLiteException e) { + } catch (SQLiteException e) { Log.e(K9.LOG_TAG, "Exception while upgrading database to v41. folder classes may have vanished", e); - } finally { Utility.closeQuietly(cursor); } @@ -712,10 +707,9 @@ public class LocalStore extends Store implements Serializable { throw e; } } + Cursor cursor = null; - try { - SharedPreferences prefs = getPreferences(); cursor = db.rawQuery("SELECT id, name FROM folders", null); while (cursor.moveToNext()) { @@ -727,12 +721,8 @@ public class LocalStore extends Store implements Serializable { Log.e(K9.LOG_TAG, " error trying to ugpgrade a folder notify class", e); } } - } - - - catch (SQLiteException e) { + } catch (SQLiteException e) { Log.e(K9.LOG_TAG, "Exception while upgrading database to v50. folder classes may have vanished", e); - } finally { Utility.closeQuietly(cursor); } @@ -1741,6 +1731,7 @@ public class LocalStore extends Store implements Serializable { public String getPushState() { return mPushState; } + @Override public FolderClass getDisplayClass() { return mDisplayClass; @@ -1783,10 +1774,12 @@ public class LocalStore extends Store implements Serializable { mSyncClass = syncClass; updateFolderColumn("poll_class", mSyncClass.name()); } + public void setPushClass(FolderClass pushClass) throws MessagingException { mPushClass = pushClass; updateFolderColumn("push_class", mPushClass.name()); } + public void setNotifyClass(FolderClass notifyClass) throws MessagingException { mNotifyClass = notifyClass; updateFolderColumn("notify_class", mNotifyClass.name()); @@ -1795,6 +1788,7 @@ public class LocalStore extends Store implements Serializable { public boolean isIntegrate() { return mIntegrate; } + public void setIntegrate(boolean integrate) throws MessagingException { mIntegrate = integrate; updateFolderColumn("integrate", mIntegrate ? 1 : 0); From 7edd1cb53cc2a0abbd08ac70ad5494076588ccd8 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 4 Sep 2014 22:48:13 +0200 Subject: [PATCH 4/6] Simplify database upgrade when adding 'notify_class' to 'folders' --- src/com/fsck/k9/mail/store/LocalStore.java | 49 ++++------------------ 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 2981ad5b4..232b9fce0 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -701,31 +701,19 @@ public class LocalStore extends Store implements Serializable { } if (db.getVersion() < 50) { try { - db.execSQL("ALTER TABLE folders ADD notify_class TEXT"); + db.execSQL("ALTER TABLE folders ADD notify_class TEXT default '" + + Folder.FolderClass.INHERITED.name() + "'"); } catch (SQLiteException e) { if (! e.getMessage().startsWith("duplicate column name:")) { throw e; } } - Cursor cursor = null; - try { - SharedPreferences prefs = getPreferences(); - cursor = db.rawQuery("SELECT id, name FROM folders", null); - while (cursor.moveToNext()) { - try { - int id = cursor.getInt(0); - String name = cursor.getString(1); - update50Metadata(db, prefs, id, name); - } catch (Exception e) { - Log.e(K9.LOG_TAG, " error trying to ugpgrade a folder notify class", e); - } - } - } catch (SQLiteException e) { - Log.e(K9.LOG_TAG, "Exception while upgrading database to v50. folder classes may have vanished", e); - } finally { - Utility.closeQuietly(cursor); - } + ContentValues cv = new ContentValues(); + cv.put("notify_class", Folder.FolderClass.FIRST_CLASS.name()); + + db.update("folders", cv, "name = ?", + new String[] { getAccount().getInboxFolderName() }); } } @@ -781,29 +769,6 @@ public class LocalStore extends Store implements Serializable { new Object[] { integrate, inTopGroup, syncClass, pushClass, displayClass, id }); } - - private void update50Metadata(final SQLiteDatabase db, SharedPreferences prefs, int id, String name) { - - Folder.FolderClass notifyClass = Folder.FolderClass.INHERITED; - - if (mAccount.getInboxFolderName().equals(name)) { - notifyClass = Folder.FolderClass.FIRST_CLASS; - } - - try { - notifyClass = Folder.FolderClass.valueOf(prefs.getString(uUid + "." + name + ".notifyMode", notifyClass.name())); - } catch (Exception e) { - Log.e(K9.LOG_TAG, " Throwing away an error while trying to upgrade folder metadata", e); - } - - if (notifyClass == Folder.FolderClass.NONE) { - notifyClass = Folder.FolderClass.INHERITED; - } - - db.execSQL("UPDATE folders SET notify_class=? WHERE id = ?", - new Object[] { notifyClass, id }); - - } } From 5802e6a36aeea8a27170f494d26a782c497d12a6 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 4 Sep 2014 22:56:29 +0200 Subject: [PATCH 5/6] Remove getNotifyClass() from Folder --- src/com/fsck/k9/mail/Folder.java | 3 --- src/com/fsck/k9/mail/store/LocalStore.java | 1 - 2 files changed, 4 deletions(-) diff --git a/src/com/fsck/k9/mail/Folder.java b/src/com/fsck/k9/mail/Folder.java index 5dd772ff6..d4bebf7da 100644 --- a/src/com/fsck/k9/mail/Folder.java +++ b/src/com/fsck/k9/mail/Folder.java @@ -222,9 +222,6 @@ public abstract class Folder { public FolderClass getPushClass() { return getSyncClass(); } - public FolderClass getNotifyClass() { - return getPushClass(); - } public void refresh(Preferences preferences) throws MessagingException { diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 232b9fce0..8e1aca3eb 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -1711,7 +1711,6 @@ public class LocalStore extends Store implements Serializable { return mSyncClass; } - @Override public FolderClass getNotifyClass() { return (FolderClass.INHERITED == mNotifyClass) ? getPushClass() : mNotifyClass; } From f5cfaceef4ade2ae711795ceeb476e99570d82c7 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 4 Sep 2014 23:00:29 +0200 Subject: [PATCH 6/6] Increase settings version in preparation of merge into master --- src/com/fsck/k9/preferences/AccountSettings.java | 2 +- src/com/fsck/k9/preferences/FolderSettings.java | 2 +- src/com/fsck/k9/preferences/Settings.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/fsck/k9/preferences/AccountSettings.java b/src/com/fsck/k9/preferences/AccountSettings.java index b2c6343aa..e93569c5f 100644 --- a/src/com/fsck/k9/preferences/AccountSettings.java +++ b/src/com/fsck/k9/preferences/AccountSettings.java @@ -139,7 +139,7 @@ public class AccountSettings { new V(1, new BooleanSetting(false)) )); s.put("folderNotifyNewMailMode", Settings.versions( - new V(33, new EnumSetting(FolderMode.class, FolderMode.ALL)) + new V(34, new EnumSetting(FolderMode.class, FolderMode.ALL)) )); s.put("notifySelfNewMail", Settings.versions( new V(1, new BooleanSetting(true)) diff --git a/src/com/fsck/k9/preferences/FolderSettings.java b/src/com/fsck/k9/preferences/FolderSettings.java index 202d5f09d..4aa2cb46a 100644 --- a/src/com/fsck/k9/preferences/FolderSettings.java +++ b/src/com/fsck/k9/preferences/FolderSettings.java @@ -29,7 +29,7 @@ public class FolderSettings { new V(1, new EnumSetting(FolderClass.class, FolderClass.NO_CLASS)) )); s.put("notifyMode", Settings.versions( - new V(33, new EnumSetting(FolderClass.class, FolderClass.INHERITED)) + new V(34, new EnumSetting(FolderClass.class, FolderClass.INHERITED)) )); s.put("syncMode", Settings.versions( new V(1, new EnumSetting(FolderClass.class, FolderClass.INHERITED)) diff --git a/src/com/fsck/k9/preferences/Settings.java b/src/com/fsck/k9/preferences/Settings.java index 22ed1cb1f..694730673 100644 --- a/src/com/fsck/k9/preferences/Settings.java +++ b/src/com/fsck/k9/preferences/Settings.java @@ -35,7 +35,7 @@ public class Settings { * * @see SettingsExporter */ - public static final int VERSION = 33; + public static final int VERSION = 34; public static Map validate(int version, Map> settings,