Extended setting to hide subject in notification area (never, when locked, always)

Fixed issue 2595
This commit is contained in:
Bernhard Redl 2012-08-02 01:41:40 +02:00 committed by cketti
parent f3e74d5321
commit 4028505d69
8 changed files with 94 additions and 25 deletions

View file

@ -323,8 +323,19 @@ http://k9mail.googlecode.com/.
<string name="global_settings_confirm_action_mark_all_as_read">Alle als gelesen markieren</string>
<string name="global_settings_confirm_action_send">Senden</string>
<string name="global_settings_privacy_mode_title">Vertrauliche Benachrichtigung</string>
<string name="global_settings_privacy_mode_summary">Der Betreff der Nachricht wird nicht in der Benachrichtigungszeile angezeigt</string>
<string name="global_settings_notification_hide_subject_mode_title">Betreff in Benachrichtigungen verbergen</string>
<string name="global_settings_notification_hide_subject_mode_summary">Verbergen des Betreffes in Benachrichtigungen</string>
<string-array name="global_settings_notification_hide_subject_mode">
<item name="1">Niemals verbergen</item>
<item name="2">Nur, wenn Gerät gesperrt ist</item>
<item name="3">Immer verbergen</item>
</string-array>
<string-array name="global_settings_notification_hide_subject_mode_values">
<item name="1">NEVER</item>
<item name="2">WHEN_LOCKED</item>
<item name="3">ALWAYS</item>
</string-array>
<string name="global_settings_batch_buttons">Gruppenoperationen-Schaltflächen</string>
<string name="global_settings_batch_buttons_summary">Zeige folgende Schaltflächen in der Nachrichtenliste an</string>

View file

@ -326,9 +326,20 @@ http://k9mail.googlecode.com/
<string name="global_settings_confirm_action_mark_all_as_read">Mark all as read</string>
<string name="global_settings_confirm_action_send">Send</string>
<string name="global_settings_privacy_mode_title">Lock-screen notifications</string>
<string name="global_settings_privacy_mode_summary">Don\'t display message subject in notification bar when system is locked</string>
<string name="global_settings_notification_hide_subject_mode_title">Hide subject in notifications</string>
<string name="global_settings_notification_hide_subject_mode_summary">When to hide the subject in the notification bar.</string>
<string-array name="global_settings_notification_hide_subject_mode">
<item name="1">Never</item>
<item name="2">When phone is locked</item>
<item name="3">Always</item>
</string-array>
<string-array name="global_settings_notification_hide_subject_mode_values">
<item name="1">NEVER</item>
<item name="2">WHEN_LOCKED</item>
<item name="3">ALWAYS</item>
</string-array>
<string name="global_settings_batch_buttons">Batch buttons</string>
<string name="global_settings_batch_buttons_summary">Configure message list batch buttons</string>
<string name="global_settings_mark_read">Mark read/unread</string>

View file

@ -348,11 +348,14 @@
android:title="@string/privacy_preferences"
android:key="privacy_preferences">
<CheckBoxPreference
<ListPreference
android:persistent="false"
android:key="privacy_mode"
android:title="@string/global_settings_privacy_mode_title"
android:summary="@string/global_settings_privacy_mode_summary"/>
android:key="notification_hide_subject"
android:defaultValue="NEVER"
android:entries="@array/global_settings_notification_hide_subject_mode"
android:entryValues="@array/global_settings_notification_hide_subject_mode_values"
android:title="@string/global_settings_notification_hide_subject_mode_title"
android:summary="@string/global_settings_notification_hide_subject_mode_summary"/>
</PreferenceScreen>

View file

@ -155,7 +155,17 @@ public class K9 extends Application {
private static boolean mConfirmDeleteStarred = false;
private static boolean mConfirmSpam = false;
private static boolean mConfirmMarkAllAsRead = true;
private static boolean mKeyguardPrivacy = false;
private static NotificationHideSubject mNotificationHideSubject = NotificationHideSubject.NEVER;
/**
* controls when to show the subject
* in the notification area
* -> Global Settings -> Privacy -> Notification
*/
public enum NotificationHideSubject {
ALWAYS,
WHEN_LOCKED,
NEVER
}
private static boolean mMessageListStars = true;
private static boolean mMessageListCheckboxes = false;
@ -465,7 +475,7 @@ public class K9 extends Application {
editor.putString("sortTypeEnum", mSortType.name());
editor.putBoolean("sortAscending", mSortAscending.get(mSortType));
editor.putBoolean("keyguardPrivacy", mKeyguardPrivacy);
editor.putString("notificationHideSubjectMode", mNotificationHideSubject.toString());
editor.putBoolean("compactLayouts", compactLayouts);
editor.putString("attachmentdefaultpath", mAttachmentDefaultPath);
@ -629,8 +639,8 @@ public class K9 extends Application {
boolean sortAscending = sprefs.getBoolean("sortAscending", Account.DEFAULT_SORT_ASCENDING);
mSortAscending.put(mSortType, sortAscending);
mKeyguardPrivacy = sprefs.getBoolean("keyguardPrivacy", false);
mNotificationHideSubject = NotificationHideSubject.valueOf(sprefs.getString("notificationHideSubjectMode", NotificationHideSubject.NEVER.toString()));
compactLayouts = sprefs.getBoolean("compactLayouts", false);
mAttachmentDefaultPath = sprefs.getString("attachmentdefaultpath", Environment.getExternalStorageDirectory().toString());
fontSizes.load(sprefs);
@ -1050,12 +1060,12 @@ public class K9 extends Application {
/**
* @return Whether privacy rules should be applied when system is locked
*/
public static boolean keyguardPrivacy() {
return mKeyguardPrivacy;
public static NotificationHideSubject getNotificationHideSubjectMode() {
return mNotificationHideSubject;
}
public static void setKeyguardPrivacy(final boolean state) {
mKeyguardPrivacy = state;
public static void setNotificationHideSubjectMode(final NotificationHideSubject mode) {
mNotificationHideSubject = mode;
}
public static boolean useCompactLayouts() {

View file

@ -21,6 +21,7 @@ import android.widget.Toast;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.K9.NotificationHideSubject;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.activity.Accounts;
@ -56,7 +57,7 @@ public class Prefs extends K9PreferenceActivity {
private static final String PREFERENCE_MANAGE_BACK = "manage_back";
private static final String PREFERENCE_START_INTEGRATED_INBOX = "start_integrated_inbox";
private static final String PREFERENCE_CONFIRM_ACTIONS = "confirm_actions";
private static final String PREFERENCE_PRIVACY_MODE = "privacy_mode";
private static final String PREFERENCE_NOTIFICATION_HIDE_SUBJECT = "notification_hide_subject";
private static final String PREFERENCE_MEASURE_ACCOUNTS = "measure_accounts";
private static final String PREFERENCE_COUNT_SEARCH = "count_search";
private static final String PREFERENCE_HIDE_SPECIAL_ACCOUNTS = "hide_special_accounts";
@ -101,7 +102,7 @@ public class Prefs extends K9PreferenceActivity {
private CheckBoxPreference mManageBack;
private CheckBoxPreference mStartIntegratedInbox;
private CheckBoxListPreference mConfirmActions;
private CheckBoxPreference mPrivacyMode;
private ListPreference mNotificationHideSubjectMode;
private CheckBoxPreference mMeasureAccounts;
private CheckBoxPreference mCountSearch;
private CheckBoxPreference mHideSpecialAccounts;
@ -216,8 +217,8 @@ public class Prefs extends K9PreferenceActivity {
K9.confirmMarkAllAsRead()
});
mPrivacyMode = (CheckBoxPreference) findPreference(PREFERENCE_PRIVACY_MODE);
mPrivacyMode.setChecked(K9.keyguardPrivacy());
mNotificationHideSubjectMode = (ListPreference) findPreference(PREFERENCE_NOTIFICATION_HIDE_SUBJECT);
mNotificationHideSubjectMode.setValue(K9.getNotificationHideSubjectMode().toString());
mMeasureAccounts = (CheckBoxPreference)findPreference(PREFERENCE_MEASURE_ACCOUNTS);
mMeasureAccounts.setChecked(K9.measureAccounts());
@ -426,7 +427,8 @@ public class Prefs extends K9PreferenceActivity {
K9.setConfirmDeleteStarred(mConfirmActions.getCheckedItems()[1]);
K9.setConfirmSpam(mConfirmActions.getCheckedItems()[2]);
K9.setConfirmMarkAllAsRead(mConfirmActions.getCheckedItems()[3]);
K9.setKeyguardPrivacy(mPrivacyMode.isChecked());
K9.setNotificationHideSubjectMode(NotificationHideSubject.valueOf(mNotificationHideSubjectMode.getValue()));
K9.setMeasureAccounts(mMeasureAccounts.isChecked());
K9.setCountSearchMessages(mCountSearch.isChecked());
K9.setHideSpecialAccounts(mHideSpecialAccounts.isChecked());

View file

@ -30,6 +30,7 @@ import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.AccountStats;
import com.fsck.k9.K9;
import com.fsck.k9.K9.NotificationHideSubject;
import com.fsck.k9.NotificationSetting;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
@ -4175,8 +4176,10 @@ public class MessagingController implements Runnable {
// If privacy mode active and keyguard active
// OR
// GlobalPreference is ALWAYS hide subject
// OR
// If we could not set a per-message notification, revert to a default message
if ((K9.keyguardPrivacy() && keyguardService.inKeyguardRestrictedInputMode()) || messageNotice.length() == 0) {
if ((K9.getNotificationHideSubjectMode() == NotificationHideSubject.WHEN_LOCKED && keyguardService.inKeyguardRestrictedInputMode()) || (K9.getNotificationHideSubjectMode() == NotificationHideSubject.ALWAYS) || messageNotice.length() == 0) {
messageNotice = new StringBuilder(context.getString(R.string.notification_new_title));
}

View file

@ -2,8 +2,10 @@ package com.fsck.k9.preferences;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@ -15,6 +17,7 @@ import android.os.Environment;
import com.fsck.k9.Account;
import com.fsck.k9.FontSizes;
import com.fsck.k9.K9;
import com.fsck.k9.K9.NotificationHideSubject;
import com.fsck.k9.R;
import com.fsck.k9.Account.SortType;
import com.fsck.k9.helper.DateFormatter;
@ -131,7 +134,8 @@ public class GlobalSettings {
new V(1, new BooleanSetting(false))
));
s.put("keyguardPrivacy", Settings.versions(
new V(1, new BooleanSetting(false))
new V(1, new BooleanSetting(false)),
new V(12, null)
));
s.put("language", Settings.versions(
new V(1, new LanguageSetting())
@ -227,10 +231,14 @@ public class GlobalSettings {
s.put("batchButtonsUnselect", Settings.versions(
new V(8, new BooleanSetting(true))
));
s.put("notificationHideSubjectMode", Settings.versions(
new V(12, new EnumSetting(NotificationHideSubject.class, NotificationHideSubject.NEVER))
));
SETTINGS = Collections.unmodifiableMap(s);
Map<Integer, SettingsUpgrader> u = new HashMap<Integer, SettingsUpgrader>();
u.put(12, new SettingsUpgraderv12());
UPGRADERS = Collections.unmodifiableMap(u);
}
@ -257,6 +265,27 @@ public class GlobalSettings {
return result;
}
/**
* Upgrades the settings from 11 -> 12
* get the value from keyguardPrivacy
* and map it to the new enum based options
*/
public static class SettingsUpgraderv12 implements SettingsUpgrader {
@Override
public Set<String> upgrade(Map<String, Object> settings) {
Boolean keyguardPrivacy = (Boolean) settings.get("keyguardPrivacy");
if (keyguardPrivacy != null && keyguardPrivacy) {
// current setting: only show subject when unlocked
settings.put("hideSubjectMode", NotificationHideSubject.WHEN_LOCKED);
} else {
// always show subject [old default]
settings.put("hideSubjectMode", NotificationHideSubject.NEVER);
}
return new HashSet<String>(Arrays.asList("hideSubjectMode"));
}
}
/**
* The gallery bug work-around setting.
*

View file

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