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.setVibratePattern(0);
notificationSetting.setVibrateTimes(5);
notificationSetting.setRing(true);
notificationSetting.setRingEnabled(true);
notificationSetting.setRingtone("content://settings/system/notification_sound");
notificationSetting.setLedColor(chipColor);
@ -444,7 +444,7 @@ public class Account implements BaseAccount, StoreConfig {
notificationSetting.setVibrate(storage.getBoolean(accountUuid + ".vibrate", false));
notificationSetting.setVibratePattern(storage.getInt(accountUuid + ".vibratePattern", 0));
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",
"content://settings/system/notification_sound"));
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 + ".alwaysShowCcBcc", alwaysShowCcBcc);
editor.putBoolean(accountUuid + ".vibrate", notificationSetting.shouldVibrate());
editor.putBoolean(accountUuid + ".vibrate", notificationSetting.isVibrateEnabled());
editor.putInt(accountUuid + ".vibratePattern", notificationSetting.getVibratePattern());
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.putBoolean(accountUuid + ".led", notificationSetting.isLed());
editor.putBoolean(accountUuid + ".led", notificationSetting.isLedEnabled());
editor.putInt(accountUuid + ".ledColor", notificationSetting.getLedColor());
for (NetworkType type : NetworkType.values()) {

View file

@ -4,97 +4,83 @@ package com.fsck.k9;
* Describes how a notification should behave.
*/
public class NotificationSetting {
private boolean ringEnabled;
private String ringtoneUri;
/**
* Ring notification kill switch. Allow disabling ringtones without losing
* ringtone selection.
*/
private boolean mRing;
private boolean ledEnabled;
private int ledColor;
private String mRingtoneUri;
private boolean vibrateEnabled;
/**
* LED kill switch.
*/
private boolean mLed;
private int mLedColor;
/**
* Vibration kill switch.
*/
private boolean mVibrate;
private int mVibratePattern;
private int mVibrateTimes;
private int vibratePattern;
private int vibrateTimes;
/**
* Set the ringtone kill switch. Allow to disable ringtone without losing
* ringtone selection.
*
* @param ring
* @param ringEnabled
* <code>true</code> to allow ringtones, <code>false</code>
* otherwise.
*/
public synchronized void setRing(boolean ring) {
mRing = ring;
public synchronized void setRingEnabled(boolean ringEnabled) {
this.ringEnabled = ringEnabled;
}
/**
* @return <code>true</code> if ringtone is allowed to play,
* <code>false</code> otherwise.
*/
public synchronized boolean shouldRing() {
return mRing;
public synchronized boolean isRingEnabled() {
return ringEnabled;
}
public synchronized String getRingtone() {
return mRingtoneUri;
return ringtoneUri;
}
public synchronized void setRingtone(String ringtoneUri) {
mRingtoneUri = ringtoneUri;
this.ringtoneUri = ringtoneUri;
}
public synchronized boolean isLed() {
return mLed;
public synchronized boolean isLedEnabled() {
return ledEnabled;
}
public synchronized void setLed(final boolean led) {
mLed = led;
ledEnabled = led;
}
public synchronized int getLedColor() {
return mLedColor;
return ledColor;
}
public synchronized void setLedColor(int color) {
mLedColor = color;
ledColor = color;
}
public synchronized boolean shouldVibrate() {
return mVibrate;
public synchronized boolean isVibrateEnabled() {
return vibrateEnabled;
}
public synchronized void setVibrate(boolean vibrate) {
mVibrate = vibrate;
vibrateEnabled = vibrate;
}
public synchronized int getVibratePattern() {
return mVibratePattern;
return vibratePattern;
}
public synchronized int getVibrateTimes() {
return mVibrateTimes;
return vibrateTimes;
}
public synchronized void setVibratePattern(int pattern) {
mVibratePattern = pattern;
vibratePattern = pattern;
}
public synchronized void setVibrateTimes(int times) {
mVibrateTimes = times;
vibrateTimes = times;
}
@ -108,7 +94,7 @@ public class NotificationSetting {
*/
public long[] getVibration() {
return getVibration(mVibratePattern, mVibrateTimes);
return getVibration(vibratePattern, vibrateTimes);
}
public static long[] getVibration(int pattern, int times) {
@ -149,6 +135,4 @@ public class NotificationSetting {
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
// which does not let us set/get the value programmatically
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();
mAccountVibrate = (CheckBoxPreference) findPreference(PREFERENCE_VIBRATE);
mAccountVibrate.setChecked(mAccount.getNotificationSetting().shouldVibrate());
mAccountVibrate.setChecked(mAccount.getNotificationSetting().isVibrateEnabled());
mAccountVibratePattern = (ListPreference) findPreference(PREFERENCE_VIBRATE_PATTERN);
mAccountVibratePattern.setValue(String.valueOf(mAccount.getNotificationSetting().getVibratePattern()));
@ -637,7 +637,7 @@ public class AccountSettings extends K9PreferenceActivity {
});
mAccountLed = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFICATION_LED);
mAccountLed.setChecked(mAccount.getNotificationSetting().isLed());
mAccountLed.setChecked(mAccount.getNotificationSetting().isLedEnabled());
mNotificationOpensUnread = (CheckBoxPreference)findPreference(PREFERENCE_NOTIFICATION_OPENS_UNREAD);
mNotificationOpensUnread.setChecked(mAccount.goToUnreadMessageSearch());
@ -825,10 +825,10 @@ public class AccountSettings extends K9PreferenceActivity {
SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
String newRingtone = prefs.getString(PREFERENCE_RINGTONE, null);
if (newRingtone != null) {
mAccount.getNotificationSetting().setRing(true);
mAccount.getNotificationSetting().setRingEnabled(true);
mAccount.getNotificationSetting().setRingtone(newRingtone);
} else {
if (mAccount.getNotificationSetting().shouldRing()) {
if (mAccount.getNotificationSetting().isRingEnabled()) {
mAccount.getNotificationSetting().setRingtone(null);
}
}

View file

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

View file

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