1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-23 16:18:50 -05:00

Merge pull request #485 from haselwarter

Conflicts:
	src/com/fsck/k9/preferences/Settings.java
This commit is contained in:
cketti 2014-09-04 23:55:30 +02:00
commit 5f0f4e9c21
12 changed files with 193 additions and 12 deletions

View File

@ -231,6 +231,22 @@
<item>1000</item>
</string-array>
<string-array name="account_settings_folder_notify_new_mail_mode_entries">
<item>@string/account_settings_folder_notify_new_mail_mode_all</item>
<item>@string/account_settings_folder_notify_new_mail_mode_first_class</item>
<item>@string/account_settings_folder_notify_new_mail_mode_first_and_second_class</item>
<item>@string/account_settings_folder_notify_new_mail_mode_not_second_class</item>
<item>@string/account_settings_folder_notify_new_mail_mode_none</item>
</string-array>
<string-array name="account_settings_folder_notify_new_mail_mode_values" translatable="false">
<item>ALL</item>
<item>FIRST_CLASS</item>
<item>FIRST_AND_SECOND_CLASS</item>
<item>NOT_SECOND_CLASS</item>
<item>NONE</item>
</string-array>
<string-array name="account_settings_folder_target_mode_entries">
<item>@string/account_settings_folder_target_mode_all</item>
<item>@string/account_settings_folder_target_mode_first_class</item>
@ -285,6 +301,20 @@
<item>INHERITED</item>
</string-array>
<string-array name="folder_settings_folder_notify_mode_entries">
<item>@string/folder_settings_folder_notify_mode_normal</item>
<item>@string/folder_settings_folder_notify_mode_first_class</item>
<item>@string/folder_settings_folder_notify_mode_second_class</item>
<item>@string/folder_settings_folder_notify_mode_inherited</item>
</string-array>
<string-array name="folder_settings_folder_notify_mode_values" translatable="false">
<item>NO_CLASS</item>
<item>FIRST_CLASS</item>
<item>SECOND_CLASS</item>
<item>INHERITED</item>
</string-array>
<string-array name="account_setup_delete_policy_entries">
<item>@string/account_setup_incoming_delete_policy_never_label</item>
<item>@string/account_setup_incoming_delete_policy_delete_label</item>

View File

@ -509,6 +509,14 @@ Please submit bug reports, contribute new features and ask questions at
<string name="account_settings_default_label">Default account</string>
<string name="account_settings_default_summary">Send mail from this account by default</string>
<string name="account_settings_notify_label">New mail notifications</string>
<string name="account_settings_folder_notify_new_mail_mode_label">Notifications folders</string>
<string name="account_settings_folder_notify_new_mail_mode_all">All</string>
<string name="account_settings_folder_notify_new_mail_mode_first_class">Only 1st Class folders</string>
<string name="account_settings_folder_notify_new_mail_mode_first_and_second_class">1st and 2nd Class folders</string>
<string name="account_settings_folder_notify_new_mail_mode_not_second_class">All except 2nd Class folders</string>
<string name="account_settings_folder_notify_new_mail_mode_none">None</string>
<string name="account_settings_notify_sync_label">Sync notifications</string>
<string name="account_settings_email_label">Your email address</string>
<string name="account_settings_notify_summary">Notify in status bar when mail arrives</string>
@ -658,6 +666,12 @@ Please submit bug reports, contribute new features and ask questions at
<string name="folder_settings_folder_push_mode_second_class">2nd Class</string>
<string name="folder_settings_folder_push_mode_inherited">Same as sync class</string>
<string name="folder_settings_folder_notify_mode_label">Folder notification class</string>
<string name="folder_settings_folder_notify_mode_normal">None</string>
<string name="folder_settings_folder_notify_mode_first_class">1st Class</string>
<string name="folder_settings_folder_notify_mode_second_class">2nd Class</string>
<string name="folder_settings_folder_notify_mode_inherited">Same as push class</string>
<string name="account_settings_incoming_label">Incoming server</string>
<string name="account_settings_incoming_summary">Configure the incoming mail server</string>
<string name="account_settings_outgoing_label">Outgoing server</string>

View File

@ -343,6 +343,15 @@
android:defaultValue="true"
android:summary="@string/account_settings_notify_summary" />
<ListPreference
android:persistent="false"
android:key="folder_notify_new_mail_mode"
android:dependency="account_notify"
android:title="@string/account_settings_folder_notify_new_mail_mode_label"
android:entries="@array/account_settings_folder_notify_new_mail_mode_entries"
android:entryValues="@array/account_settings_folder_notify_new_mail_mode_values"
android:dialogTitle="@string/account_settings_folder_notify_new_mail_mode_label" />
<CheckBoxPreference
android:persistent="false"
android:key="account_notify_self"

View File

@ -58,6 +58,14 @@
android:entryValues="@array/folder_settings_folder_push_mode_values"
android:dialogTitle="@string/folder_settings_folder_push_mode_label" />
<ListPreference
android:persistent="false"
android:key="folder_settings_folder_notify_mode"
android:title="@string/folder_settings_folder_notify_mode_label"
android:entries="@array/folder_settings_folder_notify_mode_entries"
android:entryValues="@array/folder_settings_folder_notify_mode_values"
android:dialogTitle="@string/folder_settings_folder_notify_mode_label" />
<CheckBoxPreference
android:persistent="false"
android:key="folder_settings_include_in_integrated_inbox"

View File

@ -164,6 +164,7 @@ public class Account implements BaseAccount {
private long mLastAutomaticCheckTime;
private long mLatestOldMessageSeenTime;
private boolean mNotifyNewMail;
private FolderMode mFolderNotifyNewMailMode;
private boolean mNotifySelfNewMail;
private String mInboxFolderName;
private String mDraftsFolderName;
@ -274,6 +275,7 @@ public class Account implements BaseAccount {
mDisplayCount = K9.DEFAULT_VISIBLE_LIMIT;
mAccountNumber = -1;
mNotifyNewMail = true;
mFolderNotifyNewMailMode = FolderMode.ALL;
mNotifySync = true;
mNotifySelfNewMail = true;
mFolderDisplayMode = FolderMode.NOT_SECOND_CLASS;
@ -382,6 +384,12 @@ public class Account implements BaseAccount {
mLastAutomaticCheckTime = prefs.getLong(mUuid + ".lastAutomaticCheckTime", 0);
mLatestOldMessageSeenTime = prefs.getLong(mUuid + ".latestOldMessageSeenTime", 0);
mNotifyNewMail = prefs.getBoolean(mUuid + ".notifyNewMail", false);
try {
mFolderNotifyNewMailMode = FolderMode.valueOf(prefs.getString(mUuid + ".folderNotifyNewMailMode",
FolderMode.ALL.name()));
} catch (Exception e) {
mFolderNotifyNewMailMode = FolderMode.ALL;
}
mNotifySelfNewMail = prefs.getBoolean(mUuid + ".notifySelfNewMail", true);
mNotifySync = prefs.getBoolean(mUuid + ".notifyMailCheck", false);
mDeletePolicy = prefs.getInt(mUuid + ".deletePolicy", 0);
@ -703,6 +711,7 @@ public class Account implements BaseAccount {
editor.putLong(mUuid + ".lastAutomaticCheckTime", mLastAutomaticCheckTime);
editor.putLong(mUuid + ".latestOldMessageSeenTime", mLatestOldMessageSeenTime);
editor.putBoolean(mUuid + ".notifyNewMail", mNotifyNewMail);
editor.putString(mUuid + ".folderNotifyNewMailMode", mFolderNotifyNewMailMode.name());
editor.putBoolean(mUuid + ".notifySelfNewMail", mNotifySelfNewMail);
editor.putBoolean(mUuid + ".notifyMailCheck", mNotifySync);
editor.putInt(mUuid + ".deletePolicy", mDeletePolicy);
@ -1057,6 +1066,14 @@ public class Account implements BaseAccount {
this.mNotifyNewMail = notifyNewMail;
}
public synchronized FolderMode getFolderNotifyNewMailMode() {
return mFolderNotifyNewMailMode;
}
public synchronized void setFolderNotifyNewMailMode(FolderMode folderNotifyNewMailMode) {
this.mFolderNotifyNewMailMode = folderNotifyNewMailMode;
}
public synchronized int getDeletePolicy() {
return mDeletePolicy;
}

View File

@ -71,6 +71,7 @@ public class AccountSettings extends K9PreferenceActivity {
private static final String PREFERENCE_DEFAULT = "account_default";
private static final String PREFERENCE_SHOW_PICTURES = "show_pictures_enum";
private static final String PREFERENCE_NOTIFY = "account_notify";
private static final String PREFERENCE_NOTIFY_NEW_MAIL_MODE = "folder_notify_new_mail_mode";
private static final String PREFERENCE_NOTIFY_SELF = "account_notify_self";
private static final String PREFERENCE_NOTIFY_SYNC = "account_notify_sync";
private static final String PREFERENCE_VIBRATE = "account_vibrate";
@ -139,6 +140,7 @@ public class AccountSettings extends K9PreferenceActivity {
private ListPreference mMessageSize;
private CheckBoxPreference mAccountDefault;
private CheckBoxPreference mAccountNotify;
private ListPreference mAccountNotifyNewMailMode;
private CheckBoxPreference mAccountNotifySelf;
private ListPreference mAccountShowPictures;
private CheckBoxPreference mAccountNotifySync;
@ -569,6 +571,19 @@ public class AccountSettings extends K9PreferenceActivity {
mAccountNotify = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY);
mAccountNotify.setChecked(mAccount.isNotifyNewMail());
mAccountNotifyNewMailMode = (ListPreference) findPreference(PREFERENCE_NOTIFY_NEW_MAIL_MODE);
mAccountNotifyNewMailMode.setValue(mAccount.getFolderNotifyNewMailMode().name());
mAccountNotifyNewMailMode.setSummary(mAccountNotifyNewMailMode.getEntry());
mAccountNotifyNewMailMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mAccountNotifyNewMailMode.findIndexOfValue(summary);
mAccountNotifyNewMailMode.setSummary(mAccountNotifyNewMailMode.getEntries()[index]);
mAccountNotifyNewMailMode.setValue(summary);
return false;
}
});
mAccountNotifySelf = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SELF);
mAccountNotifySelf.setChecked(mAccount.isNotifySelfNewMail());
@ -747,6 +762,7 @@ public class AccountSettings extends K9PreferenceActivity {
mAccount.setDescription(mAccountDescription.getText());
mAccount.setMarkMessageAsReadOnView(mMarkMessageAsReadOnView.isChecked());
mAccount.setNotifyNewMail(mAccountNotify.isChecked());
mAccount.setFolderNotifyNewMailMode(Account.FolderMode.valueOf(mAccountNotifyNewMailMode.getValue()));
mAccount.setNotifySelfNewMail(mAccountNotifySelf.isChecked());
mAccount.setShowOngoing(mAccountNotifySync.isChecked());
mAccount.setDisplayCount(Integer.parseInt(mDisplayCount.getValue()));

View File

@ -29,6 +29,7 @@ public class FolderSettings extends K9PreferenceActivity {
private static final String PREFERENCE_DISPLAY_CLASS = "folder_settings_folder_display_mode";
private static final String PREFERENCE_SYNC_CLASS = "folder_settings_folder_sync_mode";
private static final String PREFERENCE_PUSH_CLASS = "folder_settings_folder_push_mode";
private static final String PREFERENCE_NOTIFY_CLASS = "folder_settings_folder_notify_mode";
private static final String PREFERENCE_IN_TOP_GROUP = "folder_settings_in_top_group";
private static final String PREFERENCE_INTEGRATE = "folder_settings_include_in_integrated_inbox";
@ -39,6 +40,7 @@ public class FolderSettings extends K9PreferenceActivity {
private ListPreference mDisplayClass;
private ListPreference mSyncClass;
private ListPreference mPushClass;
private ListPreference mNotifyClass;
public static void actionSettings(Context context, Account account, String folderName) {
Intent i = new Intent(context, FolderSettings.class);
@ -124,6 +126,19 @@ public class FolderSettings extends K9PreferenceActivity {
return false;
}
});
mNotifyClass = (ListPreference) findPreference(PREFERENCE_NOTIFY_CLASS);
mNotifyClass.setValue(mFolder.getRawNotifyClass().name());
mNotifyClass.setSummary(mNotifyClass.getEntry());
mNotifyClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mNotifyClass.findIndexOfValue(summary);
mNotifyClass.setSummary(mNotifyClass.getEntries()[index]);
mNotifyClass.setValue(summary);
return false;
}
});
}
private void saveSettings() throws MessagingException {
@ -135,6 +150,7 @@ public class FolderSettings extends K9PreferenceActivity {
mFolder.setDisplayClass(FolderClass.valueOf(mDisplayClass.getValue()));
mFolder.setSyncClass(FolderClass.valueOf(mSyncClass.getValue()));
mFolder.setPushClass(FolderClass.valueOf(mPushClass.getValue()));
mFolder.setNotifyClass(FolderClass.valueOf(mNotifyClass.getValue()));
mFolder.save();

View File

@ -4616,6 +4616,21 @@ public class MessagingController implements Runnable {
return false;
}
Account.FolderMode aDisplayMode = account.getFolderDisplayMode();
Account.FolderMode aNotifyMode = account.getFolderNotifyNewMailMode();
Folder.FolderClass fDisplayClass = localFolder.getDisplayClass();
Folder.FolderClass fNotifyClass = localFolder.getNotifyClass();
if (modeMismatch(aDisplayMode, fDisplayClass)) {
// Never notify a folder that isn't displayed
return false;
}
if (modeMismatch(aNotifyMode, fNotifyClass)) {
// Do not notify folders in the wrong class
return false;
}
// If the account is a POP3 account and the message is older than the oldest message we've
// previously seen, then don't notify about it.
if (account.getStoreUri().startsWith("pop3") &&

View File

@ -108,7 +108,7 @@ public class LocalStore extends Store implements Serializable {
private static final String GET_FOLDER_COLS =
"folders.id, name, visible_limit, last_updated, status, push_state, last_pushed, " +
"integrate, top_group, poll_class, push_class, display_class";
"integrate, top_group, poll_class, push_class, display_class, notify_class";
private static final int FOLDER_ID_INDEX = 0;
private static final int FOLDER_NAME_INDEX = 1;
@ -122,6 +122,7 @@ public class LocalStore extends Store implements Serializable {
private static final int FOLDER_SYNC_CLASS_INDEX = 9;
private static final int FOLDER_PUSH_CLASS_INDEX = 10;
private static final int FOLDER_DISPLAY_CLASS_INDEX = 11;
private static final int FOLDER_NOTIFY_CLASS_INDEX = 12;
private static final String[] UID_CHECK_PROJECTION = { "uid" };
@ -146,7 +147,7 @@ public class LocalStore extends Store implements Serializable {
*/
private static final int THREAD_FLAG_UPDATE_BATCH_SIZE = 500;
public static final int DB_VERSION = 49;
public static final int DB_VERSION = 50;
public static String getColumnNameForFlag(Flag flag) {
@ -238,7 +239,7 @@ public class LocalStore extends Store implements Serializable {
db.execSQL("CREATE TABLE folders (id INTEGER PRIMARY KEY, name TEXT, "
+ "last_updated INTEGER, unread_count INTEGER, visible_limit INTEGER, status TEXT, "
+ "push_state TEXT, last_pushed INTEGER, flagged_count INTEGER default 0, "
+ "integrate INTEGER, top_group INTEGER, poll_class TEXT, push_class TEXT, display_class TEXT"
+ "integrate INTEGER, top_group INTEGER, poll_class TEXT, push_class TEXT, display_class TEXT, notify_class TEXT"
+ ")");
db.execSQL("CREATE INDEX IF NOT EXISTS folder_name ON folders (name)");
@ -424,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()) {
@ -439,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);
}
@ -703,6 +699,22 @@ public class LocalStore extends Store implements Serializable {
db.execSQL("CREATE INDEX IF NOT EXISTS msg_composite ON messages (deleted, empty,folder_id,flagged,read)");
}
if (db.getVersion() < 50) {
try {
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;
}
}
ContentValues cv = new ContentValues();
cv.put("notify_class", Folder.FolderClass.FIRST_CLASS.name());
db.update("folders", cv, "name = ?",
new String[] { getAccount().getInboxFolderName() });
}
}
db.setVersion(DB_VERSION);
@ -1274,6 +1286,7 @@ public class LocalStore extends Store implements Serializable {
prefHolder.displayClass = LocalFolder.FolderClass.FIRST_CLASS;
if (name.equalsIgnoreCase(mAccount.getInboxFolderName())) {
prefHolder.integrate = true;
prefHolder.notifyClass = LocalFolder.FolderClass.FIRST_CLASS;
prefHolder.pushClass = LocalFolder.FolderClass.FIRST_CLASS;
} else {
prefHolder.pushClass = LocalFolder.FolderClass.INHERITED;
@ -1288,12 +1301,13 @@ public class LocalStore extends Store implements Serializable {
}
folder.refresh(name, prefHolder); // Recover settings from Preferences
db.execSQL("INSERT INTO folders (name, visible_limit, top_group, display_class, poll_class, push_class, integrate) VALUES (?, ?, ?, ?, ?, ?, ?)", new Object[] {
db.execSQL("INSERT INTO folders (name, visible_limit, top_group, display_class, poll_class, notify_class, push_class, integrate) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", new Object[] {
name,
visibleLimit,
prefHolder.inTopGroup ? 1 : 0,
prefHolder.displayClass.name(),
prefHolder.syncClass.name(),
prefHolder.notifyClass.name(),
prefHolder.pushClass.name(),
prefHolder.integrate ? 1 : 0,
});
@ -1338,6 +1352,7 @@ public class LocalStore extends Store implements Serializable {
private FolderClass mDisplayClass = FolderClass.NO_CLASS;
private FolderClass mSyncClass = FolderClass.INHERITED;
private FolderClass mPushClass = FolderClass.SECOND_CLASS;
private FolderClass mNotifyClass = FolderClass.INHERITED;
private boolean mInTopGroup = false;
private String mPushState = null;
private boolean mIntegrate = false;
@ -1431,6 +1446,8 @@ public class LocalStore extends Store implements Serializable {
String noClass = FolderClass.NO_CLASS.toString();
String displayClass = cursor.getString(FOLDER_DISPLAY_CLASS_INDEX);
mDisplayClass = Folder.FolderClass.valueOf((displayClass == null) ? noClass : displayClass);
String notifyClass = cursor.getString(FOLDER_NOTIFY_CLASS_INDEX);
mNotifyClass = Folder.FolderClass.valueOf((notifyClass == null) ? noClass : notifyClass);
String pushClass = cursor.getString(FOLDER_PUSH_CLASS_INDEX);
mPushClass = Folder.FolderClass.valueOf((pushClass == null) ? noClass : pushClass);
String syncClass = cursor.getString(FOLDER_SYNC_CLASS_INDEX);
@ -1496,6 +1513,7 @@ public class LocalStore extends Store implements Serializable {
private class PreferencesHolder {
FolderClass displayClass = mDisplayClass;
FolderClass syncClass = mSyncClass;
FolderClass notifyClass = mNotifyClass;
FolderClass pushClass = mPushClass;
boolean inTopGroup = mInTopGroup;
boolean integrate = mIntegrate;
@ -1678,6 +1696,7 @@ public class LocalStore extends Store implements Serializable {
public String getPushState() {
return mPushState;
}
@Override
public FolderClass getDisplayClass() {
return mDisplayClass;
@ -1692,6 +1711,14 @@ public class LocalStore extends Store implements Serializable {
return mSyncClass;
}
public FolderClass getNotifyClass() {
return (FolderClass.INHERITED == mNotifyClass) ? getPushClass() : mNotifyClass;
}
public FolderClass getRawNotifyClass() {
return mNotifyClass;
}
@Override
public FolderClass getPushClass() {
return (FolderClass.INHERITED == mPushClass) ? getSyncClass() : mPushClass;
@ -1711,14 +1738,21 @@ 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());
}
public boolean isIntegrate() {
return mIntegrate;
}
public void setIntegrate(boolean integrate) throws MessagingException {
mIntegrate = integrate;
updateFolderColumn("integrate", mIntegrate ? 1 : 0);
@ -1774,6 +1808,12 @@ public class LocalStore extends Store implements Serializable {
editor.putString(id + ".syncMode", mSyncClass.name());
}
if (mNotifyClass == FolderClass.INHERITED && !mAccount.getInboxFolderName().equals(getName())) {
editor.remove(id + ".notifyMode");
} else {
editor.putString(id + ".notifyMode", mNotifyClass.name());
}
if (mPushClass == FolderClass.SECOND_CLASS && !mAccount.getInboxFolderName().equals(getName())) {
editor.remove(id + ".pushMode");
} else {
@ -1811,6 +1851,16 @@ public class LocalStore extends Store implements Serializable {
prefHolder.syncClass = FolderClass.INHERITED;
}
try {
prefHolder.notifyClass = FolderClass.valueOf(preferences.getString(id + ".notifyMode",
prefHolder.notifyClass.name()));
} catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to load notifyMode for " + getName(), e);
}
if (prefHolder.notifyClass == FolderClass.NONE) {
prefHolder.notifyClass = FolderClass.INHERITED;
}
try {
prefHolder.pushClass = FolderClass.valueOf(preferences.getString(id + ".pushMode",
prefHolder.pushClass.name()));

View File

@ -135,6 +135,9 @@ public class AccountSettings {
s.put("notifyNewMail", Settings.versions(
new V(1, new BooleanSetting(false))
));
s.put("folderNotifyNewMailMode", Settings.versions(
new V(34, new EnumSetting<FolderMode>(FolderMode.class, FolderMode.ALL))
));
s.put("notifySelfNewMail", Settings.versions(
new V(1, new BooleanSetting(true))
));

View File

@ -28,6 +28,9 @@ public class FolderSettings {
s.put("displayMode", Settings.versions(
new V(1, new EnumSetting<FolderClass>(FolderClass.class, FolderClass.NO_CLASS))
));
s.put("notifyMode", Settings.versions(
new V(34, new EnumSetting<FolderClass>(FolderClass.class, FolderClass.INHERITED))
));
s.put("syncMode", Settings.versions(
new V(1, new EnumSetting<FolderClass>(FolderClass.class, FolderClass.INHERITED))
));

View File

@ -35,7 +35,7 @@ public class Settings {
*
* @see SettingsExporter
*/
public static final int VERSION = 33;
public static final int VERSION = 34;
public static Map<String, Object> validate(int version, Map<String,
TreeMap<Integer, SettingsDescription>> settings,