clean up NotificationSetting

This commit is contained in:
Vincent Breitmoser 2017-03-27 11:25:48 +02:00
parent dd5a0cce98
commit 3bb3a5bdbd
5 changed files with 41 additions and 57 deletions

View file

@ -336,7 +336,7 @@ public class Account implements BaseAccount, StoreConfig {
notificationSetting.setVibrate(false); notificationSetting.setVibrate(false);
notificationSetting.setVibratePattern(0); notificationSetting.setVibratePattern(0);
notificationSetting.setVibrateTimes(5); notificationSetting.setVibrateTimes(5);
notificationSetting.setRing(true); notificationSetting.setRingEnabled(true);
notificationSetting.setRingtone("content://settings/system/notification_sound"); notificationSetting.setRingtone("content://settings/system/notification_sound");
notificationSetting.setLedColor(chipColor); notificationSetting.setLedColor(chipColor);
@ -444,7 +444,7 @@ public class Account implements BaseAccount, StoreConfig {
notificationSetting.setVibrate(storage.getBoolean(accountUuid + ".vibrate", false)); notificationSetting.setVibrate(storage.getBoolean(accountUuid + ".vibrate", false));
notificationSetting.setVibratePattern(storage.getInt(accountUuid + ".vibratePattern", 0)); notificationSetting.setVibratePattern(storage.getInt(accountUuid + ".vibratePattern", 0));
notificationSetting.setVibrateTimes(storage.getInt(accountUuid + ".vibrateTimes", 5)); notificationSetting.setVibrateTimes(storage.getInt(accountUuid + ".vibrateTimes", 5));
notificationSetting.setRing(storage.getBoolean(accountUuid + ".ring", true)); notificationSetting.setRingEnabled(storage.getBoolean(accountUuid + ".ring", true));
notificationSetting.setRingtone(storage.getString(accountUuid + ".ringtone", notificationSetting.setRingtone(storage.getString(accountUuid + ".ringtone",
"content://settings/system/notification_sound")); "content://settings/system/notification_sound"));
notificationSetting.setLed(storage.getBoolean(accountUuid + ".led", true)); notificationSetting.setLed(storage.getBoolean(accountUuid + ".led", true));
@ -737,12 +737,12 @@ public class Account implements BaseAccount, StoreConfig {
editor.putBoolean(accountUuid + ".markMessageAsReadOnView", markMessageAsReadOnView); editor.putBoolean(accountUuid + ".markMessageAsReadOnView", markMessageAsReadOnView);
editor.putBoolean(accountUuid + ".alwaysShowCcBcc", alwaysShowCcBcc); editor.putBoolean(accountUuid + ".alwaysShowCcBcc", alwaysShowCcBcc);
editor.putBoolean(accountUuid + ".vibrate", notificationSetting.shouldVibrate()); editor.putBoolean(accountUuid + ".vibrate", notificationSetting.isVibrateEnabled());
editor.putInt(accountUuid + ".vibratePattern", notificationSetting.getVibratePattern()); editor.putInt(accountUuid + ".vibratePattern", notificationSetting.getVibratePattern());
editor.putInt(accountUuid + ".vibrateTimes", notificationSetting.getVibrateTimes()); editor.putInt(accountUuid + ".vibrateTimes", notificationSetting.getVibrateTimes());
editor.putBoolean(accountUuid + ".ring", notificationSetting.shouldRing()); editor.putBoolean(accountUuid + ".ring", notificationSetting.isRingEnabled());
editor.putString(accountUuid + ".ringtone", notificationSetting.getRingtone()); editor.putString(accountUuid + ".ringtone", notificationSetting.getRingtone());
editor.putBoolean(accountUuid + ".led", notificationSetting.isLed()); editor.putBoolean(accountUuid + ".led", notificationSetting.isLedEnabled());
editor.putInt(accountUuid + ".ledColor", notificationSetting.getLedColor()); editor.putInt(accountUuid + ".ledColor", notificationSetting.getLedColor());
for (NetworkType type : NetworkType.values()) { for (NetworkType type : NetworkType.values()) {

View file

@ -4,97 +4,83 @@ package com.fsck.k9;
* Describes how a notification should behave. * Describes how a notification should behave.
*/ */
public class NotificationSetting { public class NotificationSetting {
private boolean ringEnabled;
private String ringtoneUri;
/** private boolean ledEnabled;
* Ring notification kill switch. Allow disabling ringtones without losing private int ledColor;
* ringtone selection.
*/
private boolean mRing;
private String mRingtoneUri; private boolean vibrateEnabled;
/** private int vibratePattern;
* LED kill switch. private int vibrateTimes;
*/
private boolean mLed;
private int mLedColor;
/**
* Vibration kill switch.
*/
private boolean mVibrate;
private int mVibratePattern;
private int mVibrateTimes;
/** /**
* Set the ringtone kill switch. Allow to disable ringtone without losing * Set the ringtone kill switch. Allow to disable ringtone without losing
* ringtone selection. * ringtone selection.
* *
* @param ring * @param ringEnabled
* <code>true</code> to allow ringtones, <code>false</code> * <code>true</code> to allow ringtones, <code>false</code>
* otherwise. * otherwise.
*/ */
public synchronized void setRing(boolean ring) { public synchronized void setRingEnabled(boolean ringEnabled) {
mRing = ring; this.ringEnabled = ringEnabled;
} }
/** /**
* @return <code>true</code> if ringtone is allowed to play, * @return <code>true</code> if ringtone is allowed to play,
* <code>false</code> otherwise. * <code>false</code> otherwise.
*/ */
public synchronized boolean shouldRing() { public synchronized boolean isRingEnabled() {
return mRing; return ringEnabled;
} }
public synchronized String getRingtone() { public synchronized String getRingtone() {
return mRingtoneUri; return ringtoneUri;
} }
public synchronized void setRingtone(String ringtoneUri) { public synchronized void setRingtone(String ringtoneUri) {
mRingtoneUri = ringtoneUri; this.ringtoneUri = ringtoneUri;
} }
public synchronized boolean isLed() { public synchronized boolean isLedEnabled() {
return mLed; return ledEnabled;
} }
public synchronized void setLed(final boolean led) { public synchronized void setLed(final boolean led) {
mLed = led; ledEnabled = led;
} }
public synchronized int getLedColor() { public synchronized int getLedColor() {
return mLedColor; return ledColor;
} }
public synchronized void setLedColor(int color) { public synchronized void setLedColor(int color) {
mLedColor = color; ledColor = color;
} }
public synchronized boolean shouldVibrate() { public synchronized boolean isVibrateEnabled() {
return mVibrate; return vibrateEnabled;
} }
public synchronized void setVibrate(boolean vibrate) { public synchronized void setVibrate(boolean vibrate) {
mVibrate = vibrate; vibrateEnabled = vibrate;
} }
public synchronized int getVibratePattern() { public synchronized int getVibratePattern() {
return mVibratePattern; return vibratePattern;
} }
public synchronized int getVibrateTimes() { public synchronized int getVibrateTimes() {
return mVibrateTimes; return vibrateTimes;
} }
public synchronized void setVibratePattern(int pattern) { public synchronized void setVibratePattern(int pattern) {
mVibratePattern = pattern; vibratePattern = pattern;
} }
public synchronized void setVibrateTimes(int times) { public synchronized void setVibrateTimes(int times) {
mVibrateTimes = times; vibrateTimes = times;
} }
@ -108,7 +94,7 @@ public class NotificationSetting {
*/ */
public long[] getVibration() { public long[] getVibration() {
return getVibration(mVibratePattern, mVibrateTimes); return getVibration(vibratePattern, vibrateTimes);
} }
public static long[] getVibration(int pattern, int times) { public static long[] getVibration(int pattern, int times) {
@ -149,6 +135,4 @@ public class NotificationSetting {
return repeatedPattern; return repeatedPattern;
} }
} }

View file

@ -602,11 +602,11 @@ public class AccountSettings extends K9PreferenceActivity {
// XXX: The following two lines act as a workaround for the RingtonePreference // XXX: The following two lines act as a workaround for the RingtonePreference
// which does not let us set/get the value programmatically // which does not let us set/get the value programmatically
SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences(); SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
String currentRingtone = (!mAccount.getNotificationSetting().shouldRing() ? null : mAccount.getNotificationSetting().getRingtone()); String currentRingtone = (!mAccount.getNotificationSetting().isRingEnabled() ? null : mAccount.getNotificationSetting().getRingtone());
prefs.edit().putString(PREFERENCE_RINGTONE, currentRingtone).commit(); prefs.edit().putString(PREFERENCE_RINGTONE, currentRingtone).commit();
mAccountVibrate = (CheckBoxPreference) findPreference(PREFERENCE_VIBRATE); mAccountVibrate = (CheckBoxPreference) findPreference(PREFERENCE_VIBRATE);
mAccountVibrate.setChecked(mAccount.getNotificationSetting().shouldVibrate()); mAccountVibrate.setChecked(mAccount.getNotificationSetting().isVibrateEnabled());
mAccountVibratePattern = (ListPreference) findPreference(PREFERENCE_VIBRATE_PATTERN); mAccountVibratePattern = (ListPreference) findPreference(PREFERENCE_VIBRATE_PATTERN);
mAccountVibratePattern.setValue(String.valueOf(mAccount.getNotificationSetting().getVibratePattern())); mAccountVibratePattern.setValue(String.valueOf(mAccount.getNotificationSetting().getVibratePattern()));
@ -637,7 +637,7 @@ public class AccountSettings extends K9PreferenceActivity {
}); });
mAccountLed = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFICATION_LED); mAccountLed = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFICATION_LED);
mAccountLed.setChecked(mAccount.getNotificationSetting().isLed()); mAccountLed.setChecked(mAccount.getNotificationSetting().isLedEnabled());
mNotificationOpensUnread = (CheckBoxPreference)findPreference(PREFERENCE_NOTIFICATION_OPENS_UNREAD); mNotificationOpensUnread = (CheckBoxPreference)findPreference(PREFERENCE_NOTIFICATION_OPENS_UNREAD);
mNotificationOpensUnread.setChecked(mAccount.goToUnreadMessageSearch()); mNotificationOpensUnread.setChecked(mAccount.goToUnreadMessageSearch());
@ -825,10 +825,10 @@ public class AccountSettings extends K9PreferenceActivity {
SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences(); SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
String newRingtone = prefs.getString(PREFERENCE_RINGTONE, null); String newRingtone = prefs.getString(PREFERENCE_RINGTONE, null);
if (newRingtone != null) { if (newRingtone != null) {
mAccount.getNotificationSetting().setRing(true); mAccount.getNotificationSetting().setRingEnabled(true);
mAccount.getNotificationSetting().setRingtone(newRingtone); mAccount.getNotificationSetting().setRingtone(newRingtone);
} else { } else {
if (mAccount.getNotificationSetting().shouldRing()) { if (mAccount.getNotificationSetting().isRingEnabled()) {
mAccount.getNotificationSetting().setRingtone(null); mAccount.getNotificationSetting().setRingtone(null);
} }
} }

View file

@ -76,9 +76,9 @@ class DeviceNotifications extends BaseNotifications {
NotificationSetting notificationSetting = account.getNotificationSetting(); NotificationSetting notificationSetting = account.getNotificationSetting();
controller.configureNotification( controller.configureNotification(
builder, builder,
(notificationSetting.shouldRing()) ? notificationSetting.getRingtone() : null, (notificationSetting.isRingEnabled()) ? notificationSetting.getRingtone() : null,
(notificationSetting.shouldVibrate()) ? notificationSetting.getVibration() : null, (notificationSetting.isVibrateEnabled()) ? notificationSetting.getVibration() : null,
(notificationSetting.isLed()) ? notificationSetting.getLedColor() : null, (notificationSetting.isLedEnabled()) ? notificationSetting.getLedColor() : null,
NOTIFICATION_LED_BLINK_SLOW, NOTIFICATION_LED_BLINK_SLOW,
ringAndVibrate); ringAndVibrate);

View file

@ -82,7 +82,7 @@ public class RemoteControlService extends CoreService {
account.setNotifyNewMail(Boolean.parseBoolean(notificationEnabled)); account.setNotifyNewMail(Boolean.parseBoolean(notificationEnabled));
} }
if (ringEnabled != null) { if (ringEnabled != null) {
account.getNotificationSetting().setRing(Boolean.parseBoolean(ringEnabled)); account.getNotificationSetting().setRingEnabled(Boolean.parseBoolean(ringEnabled));
} }
if (vibrateEnabled != null) { if (vibrateEnabled != null) {
account.getNotificationSetting().setVibrate(Boolean.parseBoolean(vibrateEnabled)); account.getNotificationSetting().setVibrate(Boolean.parseBoolean(vibrateEnabled));