Merge pull request #1485 from k9mail/notifications_only_from_contacts
Setting: only show notifications for messages from contacts
This commit is contained in:
commit
95c546d992
9 changed files with 67 additions and 6 deletions
|
@ -181,6 +181,7 @@ public class Account implements BaseAccount, StoreConfig {
|
|||
private boolean mNotifyNewMail;
|
||||
private FolderMode mFolderNotifyNewMailMode;
|
||||
private boolean mNotifySelfNewMail;
|
||||
private boolean mNotifyContactsMailOnly;
|
||||
private String mInboxFolderName;
|
||||
private String mDraftsFolderName;
|
||||
private String mSentFolderName;
|
||||
|
@ -289,6 +290,7 @@ public class Account implements BaseAccount, StoreConfig {
|
|||
mFolderNotifyNewMailMode = FolderMode.ALL;
|
||||
mNotifySync = true;
|
||||
mNotifySelfNewMail = true;
|
||||
mNotifyContactsMailOnly = false;
|
||||
mFolderDisplayMode = FolderMode.NOT_SECOND_CLASS;
|
||||
mFolderSyncMode = FolderMode.FIRST_CLASS;
|
||||
mFolderPushMode = FolderMode.FIRST_CLASS;
|
||||
|
@ -397,6 +399,7 @@ public class Account implements BaseAccount, StoreConfig {
|
|||
|
||||
mFolderNotifyNewMailMode = getEnumStringPref(storage, mUuid + ".folderNotifyNewMailMode", FolderMode.ALL);
|
||||
mNotifySelfNewMail = storage.getBoolean(mUuid + ".notifySelfNewMail", true);
|
||||
mNotifyContactsMailOnly = storage.getBoolean(mUuid + ".notifyContactsMailOnly", false);
|
||||
mNotifySync = storage.getBoolean(mUuid + ".notifyMailCheck", false);
|
||||
mDeletePolicy = DeletePolicy.fromInt(storage.getInt(mUuid + ".deletePolicy", DeletePolicy.NEVER.setting));
|
||||
mInboxFolderName = storage.getString(mUuid + ".inboxFolderName", INBOX);
|
||||
|
@ -684,6 +687,7 @@ public class Account implements BaseAccount, StoreConfig {
|
|||
editor.putBoolean(mUuid + ".notifyNewMail", mNotifyNewMail);
|
||||
editor.putString(mUuid + ".folderNotifyNewMailMode", mFolderNotifyNewMailMode.name());
|
||||
editor.putBoolean(mUuid + ".notifySelfNewMail", mNotifySelfNewMail);
|
||||
editor.putBoolean(mUuid + ".notifyContactsMailOnly", mNotifyContactsMailOnly);
|
||||
editor.putBoolean(mUuid + ".notifyMailCheck", mNotifySync);
|
||||
editor.putInt(mUuid + ".deletePolicy", mDeletePolicy.setting);
|
||||
editor.putString(mUuid + ".inboxFolderName", mInboxFolderName);
|
||||
|
@ -1252,6 +1256,14 @@ public class Account implements BaseAccount, StoreConfig {
|
|||
mNotifySelfNewMail = notifySelfNewMail;
|
||||
}
|
||||
|
||||
public synchronized boolean isNotifyContactsMailOnly() {
|
||||
return mNotifyContactsMailOnly;
|
||||
}
|
||||
|
||||
public synchronized void setNotifyContactsMailOnly(boolean notifyContactsMailOnly) {
|
||||
this.mNotifyContactsMailOnly = notifyContactsMailOnly;
|
||||
}
|
||||
|
||||
public synchronized Expunge getExpungePolicy() {
|
||||
return mExpungePolicy;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ public class AccountSettings extends K9PreferenceActivity {
|
|||
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_CONTACTS_MAIL_ONLY = "account_notify_contacts_mail_only";
|
||||
private static final String PREFERENCE_NOTIFY_SYNC = "account_notify_sync";
|
||||
private static final String PREFERENCE_VIBRATE = "account_vibrate";
|
||||
private static final String PREFERENCE_VIBRATE_PATTERN = "account_vibrate_pattern";
|
||||
|
@ -146,6 +147,7 @@ public class AccountSettings extends K9PreferenceActivity {
|
|||
private CheckBoxPreference mAccountNotify;
|
||||
private ListPreference mAccountNotifyNewMailMode;
|
||||
private CheckBoxPreference mAccountNotifySelf;
|
||||
private CheckBoxPreference mAccountNotifyContactsMailOnly;
|
||||
private ListPreference mAccountShowPictures;
|
||||
private CheckBoxPreference mAccountNotifySync;
|
||||
private CheckBoxPreference mAccountVibrate;
|
||||
|
@ -590,6 +592,9 @@ public class AccountSettings extends K9PreferenceActivity {
|
|||
mAccountNotifySelf = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SELF);
|
||||
mAccountNotifySelf.setChecked(mAccount.isNotifySelfNewMail());
|
||||
|
||||
mAccountNotifyContactsMailOnly = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_CONTACTS_MAIL_ONLY);
|
||||
mAccountNotifyContactsMailOnly.setChecked(mAccount.isNotifyContactsMailOnly());
|
||||
|
||||
mAccountNotifySync = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SYNC);
|
||||
mAccountNotifySync.setChecked(mAccount.isShowOngoing());
|
||||
|
||||
|
@ -753,6 +758,7 @@ public class AccountSettings extends K9PreferenceActivity {
|
|||
mAccount.setNotifyNewMail(mAccountNotify.isChecked());
|
||||
mAccount.setFolderNotifyNewMailMode(FolderMode.valueOf(mAccountNotifyNewMailMode.getValue()));
|
||||
mAccount.setNotifySelfNewMail(mAccountNotifySelf.isChecked());
|
||||
mAccount.setNotifyContactsMailOnly(mAccountNotifyContactsMailOnly.isChecked());
|
||||
mAccount.setShowOngoing(mAccountNotifySync.isChecked());
|
||||
mAccount.setDisplayCount(Integer.parseInt(mDisplayCount.getValue()));
|
||||
mAccount.setMaximumAutoDownloadMessageSize(Integer.parseInt(mMessageSize.getValue()));
|
||||
|
|
|
@ -55,6 +55,7 @@ import com.fsck.k9.R;
|
|||
import com.fsck.k9.activity.MessageReference;
|
||||
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
|
||||
import com.fsck.k9.cache.EmailProviderCache;
|
||||
import com.fsck.k9.helper.Contacts;
|
||||
import com.fsck.k9.mail.Address;
|
||||
import com.fsck.k9.mail.AuthenticationFailedException;
|
||||
import com.fsck.k9.mail.CertificateValidationException;
|
||||
|
@ -151,6 +152,7 @@ public class MessagingController implements Runnable {
|
|||
|
||||
private final Context context;
|
||||
private final NotificationController notificationController;
|
||||
private final Contacts contacts;
|
||||
private volatile boolean stopped = false;
|
||||
|
||||
private static final Set<Flag> SYNC_FLAGS = EnumSet.of(Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED, Flag.FORWARDED);
|
||||
|
@ -209,9 +211,11 @@ public class MessagingController implements Runnable {
|
|||
|
||||
|
||||
@VisibleForTesting
|
||||
MessagingController(Context context, NotificationController notificationController) {
|
||||
MessagingController(Context context, NotificationController notificationController, Contacts contacts) {
|
||||
this.context = context;
|
||||
this.notificationController = notificationController;
|
||||
this.contacts = contacts;
|
||||
|
||||
mThread = new Thread(this);
|
||||
mThread.setName("MessagingController");
|
||||
mThread.start();
|
||||
|
@ -231,7 +235,8 @@ public class MessagingController implements Runnable {
|
|||
if (inst == null) {
|
||||
Context appContext = context.getApplicationContext();
|
||||
NotificationController notificationController = NotificationController.newInstance(appContext);
|
||||
inst = new MessagingController(appContext, notificationController);
|
||||
Contacts contacts = Contacts.getInstance(context);
|
||||
inst = new MessagingController(appContext, notificationController, contacts);
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
|
@ -4225,6 +4230,10 @@ public class MessagingController implements Runnable {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (account.isNotifyContactsMailOnly() && !contacts.isAnyInContacts(message.getFrom())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,6 +141,26 @@ public class Contacts {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether one of the provided addresses belongs to one of the contacts.
|
||||
*
|
||||
* @param addresses The addresses to search in contacts
|
||||
* @return <tt>true</tt>, if one address belongs to a contact.
|
||||
* <tt>false</tt>, otherwise.
|
||||
*/
|
||||
public boolean isAnyInContacts(final Address[] addresses) {
|
||||
if (addresses == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Address addr : addresses) {
|
||||
if (isInContacts(addr.getAddress())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the contact an email address belongs to.
|
||||
*
|
||||
|
|
|
@ -224,6 +224,9 @@ public class AccountSettings {
|
|||
s.put("remoteSearchFullText", Settings.versions(
|
||||
new V(18, new BooleanSetting(false))
|
||||
));
|
||||
s.put("notifyContactsMailOnly", Settings.versions(
|
||||
new V(42, new BooleanSetting(false))
|
||||
));
|
||||
|
||||
SETTINGS = Collections.unmodifiableMap(s);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public class Settings {
|
|||
*
|
||||
* @see SettingsExporter
|
||||
*/
|
||||
public static final int VERSION = 41;
|
||||
public static final int VERSION = 42;
|
||||
|
||||
public static Map<String, Object> validate(int version, Map<String,
|
||||
TreeMap<Integer, SettingsDescription>> settings,
|
||||
|
|
|
@ -533,6 +533,8 @@ Please submit bug reports, contribute new features and ask questions at
|
|||
<string name="account_settings_notify_sync_summary">Notify in status bar while mail is checked</string>
|
||||
<string name="account_settings_notify_self_label">Include outgoing mail</string>
|
||||
<string name="account_settings_notify_self_summary">Show a notification for messages I sent</string>
|
||||
<string name="account_notify_contacts_mail_only_label">Contacts only</string>
|
||||
<string name="account_notify_contacts_mail_only_summary">Show notifications only for messages from known contacts</string>
|
||||
<string name="account_settings_notification_opens_unread_label">Notification opens unread messages</string>
|
||||
<string name="account_settings_notification_opens_unread_summary">Searches for unread messages when Notification is opened</string>
|
||||
<string name="account_settings_mark_message_as_read_on_view_label">Mark as read when opened</string>
|
||||
|
|
|
@ -360,6 +360,14 @@
|
|||
android:defaultValue="true"
|
||||
android:summary="@string/account_settings_notify_self_summary" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:persistent="false"
|
||||
android:key="account_notify_contacts_mail_only"
|
||||
android:dependency="account_notify"
|
||||
android:title="@string/account_notify_contacts_mail_only_label"
|
||||
android:defaultValue="false"
|
||||
android:summary="@string/account_notify_contacts_mail_only_summary" />
|
||||
|
||||
<!--
|
||||
We can't disable persisting the ringtone value to SharedPreferences
|
||||
because it's needed to actually access the value.
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.lang.reflect.Field;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -14,6 +13,7 @@ import android.content.Context;
|
|||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.AccountStats;
|
||||
import com.fsck.k9.Preferences;
|
||||
import com.fsck.k9.helper.Contacts;
|
||||
import com.fsck.k9.mail.FetchProfile;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
|
@ -49,7 +49,6 @@ import static org.mockito.Matchers.anyInt;
|
|||
import static org.mockito.Matchers.anySet;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.isNull;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
|
@ -70,6 +69,8 @@ public class MessagingControllerTest {
|
|||
|
||||
private MessagingController controller;
|
||||
@Mock
|
||||
private Contacts contacts;
|
||||
@Mock
|
||||
private Account account;
|
||||
@Mock
|
||||
private AccountStats accountStats;
|
||||
|
@ -119,7 +120,7 @@ public class MessagingControllerTest {
|
|||
MockitoAnnotations.initMocks(this);
|
||||
appContext = ShadowApplication.getInstance().getApplicationContext();
|
||||
|
||||
controller = new MessagingController(appContext, notificationController);
|
||||
controller = new MessagingController(appContext, notificationController, contacts);
|
||||
|
||||
configureAccount();
|
||||
configureLocalStore();
|
||||
|
|
Loading…
Reference in a new issue