Remove ORIGIN_ notification constants, clean up

- MI preferences now use NotificationType.getFixedName() for preference
  keys
master
cpfeiffer 2016-10-10 22:39:20 +02:00
parent b2d36dfb54
commit 62828e5158
6 changed files with 43 additions and 75 deletions

View File

@ -21,15 +21,7 @@ public final class MiBandConst {
public static final String PREF_TRY_SMS = "mi_try_sms";
public static final String ORIGIN_SMS = "sms";
public static final String ORIGIN_CHAT = "chat";
public static final String ORIGIN_TELEGRAM = "telegram";
public static final String ORIGIN_TWITTER = "twitter";
public static final String ORIGIN_FACEBOOK = "facebook";
public static final String ORIGIN_INCOMING_CALL = "incoming_call";
public static final String ORIGIN_K9MAIL = "k9mail";
public static final String ORIGIN_PEBBLEMSG = "pebblemsg";
public static final String ORIGIN_GENERIC = "generic";
public static final String MI_GENERAL_NAME_PREFIX = "MI";
public static final String MI_BAND2_NAME = "MI Band 2";
public static final String MI_1 = "1";

View File

@ -14,21 +14,12 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_CHAT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_FACEBOOK;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_GENERIC;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_INCOMING_CALL;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_K9MAIL;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_PEBBLEMSG;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_SMS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TELEGRAM;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TWITTER;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_TRY_SMS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefKey;
@ -66,7 +57,7 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
private void addTryListeners() {
for (final NotificationType type : NotificationType.values()) {
String prefKey = "mi_try_" + type.name();
String prefKey = "mi_try_" + type.getFixedValue();
final Preference tryPref = findPreference(prefKey);
if (tryPref != null) {
tryPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@ -90,21 +81,20 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
@Override
protected String[] getPreferenceKeysWithSummary() {
return new String[]{
String[] strings1 = {
PREF_USER_ALIAS,
PREF_MIBAND_ADDRESS,
PREF_MIBAND_FITNESS_GOAL,
PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR,
PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS,
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_SMS),
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_CHAT),
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_TELEGRAM),
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_TWITTER),
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_FACEBOOK),
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_INCOMING_CALL),
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_K9MAIL),
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_PEBBLEMSG),
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_GENERIC),
PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS,
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_INCOMING_CALL)
};
String[] strings2 = new String[NotificationType.values().length];
int i = 0;
for (NotificationType type : NotificationType.values()) {
strings2[i++] = type.getFixedValue();
}
return org.apache.commons.lang3.ArrayUtils.addAll(strings1, strings2);
}
}

View File

@ -9,5 +9,15 @@ public enum NotificationType {
FACEBOOK,
SMS,
TWITTER,
TELEGRAM,
TELEGRAM;
/**
* Returns the enum constant as a fixed String value, e.g. to be used
* as preference key. In case the keys are ever changed, this method
* may be used to bring backward compatibility.
* @return
*/
public String getFixedValue() {
return name().toLowerCase();
}
}

View File

@ -54,7 +54,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.AbortTransactio
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.ConditionalWriteAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WriteAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertLevel;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.Mi2NotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.operations.InitOperation;
@ -74,14 +73,6 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FL
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_DURATION;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_ORIGINAL_COLOUR;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_CHAT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_FACEBOOK;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_GENERIC;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_K9MAIL;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_PEBBLEMSG;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_SMS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TELEGRAM;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TWITTER;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_DURATION;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_PAUSE;
@ -561,46 +552,38 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
@Override
public void onNotification(NotificationSpec notificationSpec) {
String task;
String origin;
int alertLevel;
switch (notificationSpec.type) {
case SMS:
task = "sms received";
origin = ORIGIN_SMS;
alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE;
break;
case EMAIL:
task = "email received";
origin = ORIGIN_K9MAIL;
alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE;
break;
case FACEBOOK:
task = "facebook message received";
origin = ORIGIN_FACEBOOK;
alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE;
break;
case TWITTER:
task = "twitter message received";
origin = ORIGIN_TWITTER;
alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE;
break;
case TELEGRAM:
task = "telegram message received";
origin = ORIGIN_TELEGRAM;
alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE;
break;
case CHAT:
task = "chat message received";
origin = ORIGIN_CHAT;
alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE;
break;
case UNDEFINED:
default:
task = "generic notification received";
origin = ORIGIN_GENERIC;
alertLevel = MiBand2Service.ALERT_LEVEL_VIBRATE_ONLY;
}
performPreferredNotification(task, origin, alertLevel, null);
performPreferredNotification(task, notificationSpec.type.getFixedValue(), alertLevel, null);
}
@Override

View File

@ -36,7 +36,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.entities.User;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.State;
@ -77,13 +76,6 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FL
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_DURATION;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.FLASH_ORIGINAL_COLOUR;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_FACEBOOK;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_GENERIC;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_K9MAIL;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_PEBBLEMSG;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_SMS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TELEGRAM;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_TWITTER;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_DURATION;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_PAUSE;
@ -542,28 +534,29 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
@Override
public void onNotification(NotificationSpec notificationSpec) {
// FIXME: these ORIGIN contants do not really make sense anymore
String origin = notificationSpec.type.getFixedValue();
switch (notificationSpec.type) {
case SMS:
performPreferredNotification("sms received", ORIGIN_SMS, null);
performPreferredNotification("sms received", origin, null);
break;
case EMAIL:
performPreferredNotification("email received", ORIGIN_K9MAIL, null);
performPreferredNotification("email received", origin, null);
break;
case CHAT:
performPreferredNotification("chat message received", ORIGIN_PEBBLEMSG, null);
performPreferredNotification("chat message received", origin, null);
break;
case TELEGRAM:
performPreferredNotification("chat message received", ORIGIN_TELEGRAM, null);
performPreferredNotification("chat message received", origin, null);
break;
case TWITTER:
performPreferredNotification("chat message received", ORIGIN_TWITTER, null);
performPreferredNotification("chat message received", origin, null);
break;
case FACEBOOK:
performPreferredNotification("chat message received", ORIGIN_FACEBOOK, null);
performPreferredNotification("chat message received", origin, null);
break;
case UNDEFINED:
default:
performPreferredNotification("generic notification received", ORIGIN_GENERIC, null);
performPreferredNotification("generic notification received", origin, null);
}
}

View File

@ -70,7 +70,7 @@
android:title="@string/pref_title_notifications_repetitions" />
<Preference
android:key="mi_try_SMS"
android:key="mi_try_sms"
android:title="@string/vibration_try"/>
</PreferenceScreen>
@ -104,18 +104,18 @@
android:defaultValue="@string/p_medium"
android:entries="@array/vibration_profile"
android:entryValues="@array/vibration_profile_values"
android:key="mi_vibration_profile_k9mail"
android:key="mi_vibration_profile_email"
android:title="@string/miband_prefs_vibration"
android:summary="%s" />
<EditTextPreference
android:defaultValue="2"
android:inputType="number"
android:key="mi_vibration_count_k9mail"
android:key="mi_vibration_count_email"
android:maxLength="1"
android:title="@string/pref_title_notifications_repetitions" />
<Preference
android:key="mi_try_EMAIL"
android:key="mi_try_email"
android:title="@string/vibration_try"/>
</PreferenceScreen>
@ -139,7 +139,7 @@
android:maxLength="1"
android:title="@string/pref_title_notifications_repetitions" />
<Preference
android:key="mi_try_TELEGRAM"
android:key="mi_try_telegram"
android:title="@string/vibration_try"/>
</PreferenceScreen>
@ -163,7 +163,7 @@
android:maxLength="1"
android:title="@string/pref_title_notifications_repetitions" />
<Preference
android:key="mi_try_CHAT"
android:key="mi_try_chat"
android:title="@string/vibration_try"/>
</PreferenceScreen>
@ -187,7 +187,7 @@
android:maxLength="1"
android:title="@string/pref_title_notifications_repetitions" />
<Preference
android:key="mi_try_TWITTER"
android:key="mi_try_twitter"
android:title="@string/vibration_try"/>
</PreferenceScreen>
@ -211,7 +211,7 @@
android:maxLength="1"
android:title="@string/pref_title_notifications_repetitions" />
<Preference
android:key="mi_try_FACEBOOK"
android:key="mi_try_facebook"
android:title="@string/vibration_try"/>
</PreferenceScreen>
@ -224,18 +224,18 @@
android:defaultValue="@string/p_waterdrop"
android:entries="@array/vibration_profile"
android:entryValues="@array/vibration_profile_values"
android:key="mi_vibration_profile_generic"
android:key="mi_vibration_profile_undefined"
android:title="@string/miband_prefs_vibration"
android:summary="%s" />
<EditTextPreference
android:defaultValue="3"
android:inputType="number"
android:key="mi_vibration_count_generic"
android:key="mi_vibration_count_undefined"
android:maxLength="1"
android:title="@string/pref_title_notifications_repetitions" />
<Preference
android:key="mi_try_UNDEFINED"
android:key="mi_try_undefined"
android:title="@string/vibration_try"/>
</PreferenceScreen>