diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 1f17df04d..56ec02f93 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -122,7 +122,7 @@ public class GBApplication extends Application { private static SharedPreferences sharedPrefs; private static final String PREFS_VERSION = "shared_preferences_version"; //if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version - private static final int CURRENT_PREFS_VERSION = 27; + private static final int CURRENT_PREFS_VERSION = 28; private static LimitedQueue mIDSenderLookup = new LimitedQueue(16); private static Prefs prefs; @@ -1404,6 +1404,47 @@ public class GBApplication extends Application { } } + if (oldVersion < 28) { + try (DBHandler db = acquireDB()) { + final DaoSession daoSession = db.getDaoSession(); + final List activeDevices = DBHelper.getActiveDevices(daoSession); + + for (final Device dbDevice : activeDevices) { + final SharedPreferences deviceSharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(dbDevice.getIdentifier()); + final SharedPreferences.Editor deviceSharedPrefsEdit = deviceSharedPrefs.edit(); + boolean shouldApply = false; + + if (!"UNKNOWN".equals(deviceSharedPrefs.getString("events_forwarding_fellsleep_action_selection", "UNKNOWN"))) { + shouldApply = true; + deviceSharedPrefsEdit.putStringSet( + "events_forwarding_fellsleep_action_selections", + Collections.singleton(deviceSharedPrefs.getString("events_forwarding_fellsleep_action_selection", "UNKNOWN")) + ); + } + if (!"UNKNOWN".equals(deviceSharedPrefs.getString("events_forwarding_wokeup_action_selection", "UNKNOWN"))) { + shouldApply = true; + deviceSharedPrefsEdit.putStringSet( + "events_forwarding_wokeup_action_selections", + Collections.singleton(deviceSharedPrefs.getString("events_forwarding_wokeup_action_selection", "UNKNOWN")) + ); + } + if (!"UNKNOWN".equals(deviceSharedPrefs.getString("events_forwarding_startnonwear_action_selection", "UNKNOWN"))) { + shouldApply = true; + deviceSharedPrefsEdit.putStringSet( + "events_forwarding_startnonwear_action_selections", + Collections.singleton(deviceSharedPrefs.getString("events_forwarding_startnonwear_action_selection", "UNKNOWN")) + ); + } + + if (shouldApply) { + deviceSharedPrefsEdit.apply(); + } + } + } catch (Exception e) { + Log.w(TAG, "error acquiring DB lock"); + } + } + editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION)); editor.apply(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractPreferenceFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractPreferenceFragment.java index 07b4de95e..5c4c15e6d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractPreferenceFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractPreferenceFragment.java @@ -38,9 +38,12 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Set; +import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.util.XTimePreference; import nodomain.freeyourgadget.gadgetbridge.util.XTimePreferenceFragment; import nodomain.freeyourgadget.gadgetbridge.util.dialogs.MaterialEditTextPreferenceDialogFragment; @@ -199,7 +202,29 @@ public abstract class AbstractPreferenceFragment extends PreferenceFragmentCompa } if (getPreferenceKeysWithSummary().contains(key)) { - final String summary = prefs.getString(key, preference.getSummary() != null ? preference.getSummary().toString() : ""); + final String summary; + + // For multi select preferences, let's set the summary to the values, comma-delimited + if (preference instanceof MultiSelectListPreference) { + final Set prefSetValue = prefs.getStringSet(key, Collections.emptySet()); + if (prefSetValue.isEmpty()) { + summary = requireContext().getString(R.string.not_set); + } else { + final MultiSelectListPreference multiSelectListPreference = (MultiSelectListPreference) preference; + final CharSequence[] entries = multiSelectListPreference.getEntries(); + final CharSequence[] entryValues = multiSelectListPreference.getEntryValues(); + final List translatedEntries = new ArrayList<>(); + for (int i = 0; i < entryValues.length; i++) { + if (prefSetValue.contains(entryValues[i].toString())) { + translatedEntries.add(entries[i].toString()); + } + } + summary = String.join(", ", translatedEntries); + } + } else { + summary = prefs.getString(key, preference.getSummary() != null ? preference.getSummary().toString() : ""); + } + preference.setSummary(summary); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java index d3fa9df2a..89426647f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java @@ -382,12 +382,11 @@ public class DeviceSettingsPreferenceConst { public static final String PREF_FEMOMETER_MEASUREMENT_MODE = "femometer_measurement_mode"; public static final String PREF_PREFIX_NOTIFICATION_WITH_APP = "pref_prefix_notification_with_app"; - public static final String PREF_DEVICE_ACTION_SELECTION_OFF = "UNKNOWN"; public static final String PREF_DEVICE_ACTION_SELECTION_BROADCAST = "BROADCAST"; - public static final String PREF_DEVICE_ACTION_FELL_SLEEP_SELECTION = "events_forwarding_fellsleep_action_selection"; + public static final String PREF_DEVICE_ACTION_FELL_SLEEP_SELECTIONS = "events_forwarding_fellsleep_action_selections"; public static final String PREF_DEVICE_ACTION_FELL_SLEEP_BROADCAST = "prefs_events_forwarding_fellsleep_broadcast"; - public static final String PREF_DEVICE_ACTION_WOKE_UP_SELECTION = "events_forwarding_wokeup_action_selection"; + public static final String PREF_DEVICE_ACTION_WOKE_UP_SELECTIONS = "events_forwarding_wokeup_action_selections"; public static final String PREF_DEVICE_ACTION_WOKE_UP_BROADCAST = "prefs_events_forwarding_wokeup_broadcast"; - public static final String PREF_DEVICE_ACTION_START_NON_WEAR_SELECTION = "events_forwarding_startnonwear_action_selection"; + public static final String PREF_DEVICE_ACTION_START_NON_WEAR_SELECTIONS = "events_forwarding_startnonwear_action_selections"; public static final String PREF_DEVICE_ACTION_START_NON_WEAR_BROADCAST = "prefs_events_forwarding_startnonwear_broadcast"; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java index 738e4bd77..eaf04b249 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java @@ -26,11 +26,11 @@ import androidx.preference.ListPreference; import androidx.preference.Preference; import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.Objects; import java.util.Set; @@ -50,23 +50,20 @@ import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst; -import nodomain.freeyourgadget.gadgetbridge.devices.sony.wena3.SonyWena3SettingKeys; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; -import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.*; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_CONTROL_CENTER_SORTABLE; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_FELL_SLEEP_BROADCAST; -import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_FELL_SLEEP_SELECTION; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_FELL_SLEEP_SELECTIONS; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_SELECTION_BROADCAST; -import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_SELECTION_OFF; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_START_NON_WEAR_BROADCAST; -import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_START_NON_WEAR_SELECTION; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_START_NON_WEAR_SELECTIONS; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_WOKE_UP_BROADCAST; -import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_WOKE_UP_SELECTION; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_WOKE_UP_SELECTIONS; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_EXPOSE_HR_THIRDPARTY; @@ -845,15 +842,16 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i new PasswordCapabilityImpl().registerPreferences(getContext(), coordinator.getPasswordCapability(), this); new HeartRateCapability().registerPreferences(getContext(), coordinator.getHeartRateMeasurementIntervals(), this); - String deviceActionsFellSleepSelection = prefs.getString(PREF_DEVICE_ACTION_FELL_SLEEP_SELECTION, PREF_DEVICE_ACTION_SELECTION_OFF); - final Preference deviceActionsFellSleep = findPreference(PREF_DEVICE_ACTION_FELL_SLEEP_SELECTION); + Set deviceActionsFellSleepSelection = prefs.getStringSet(PREF_DEVICE_ACTION_FELL_SLEEP_SELECTIONS, Collections.emptySet()); + final Preference deviceActionsFellSleep = findPreference(PREF_DEVICE_ACTION_FELL_SLEEP_SELECTIONS); final Preference deviceActionsFellSleepBroadcast = findPreference(PREF_DEVICE_ACTION_FELL_SLEEP_BROADCAST); - boolean deviceActionsFellSleepSelectionBroadcast = deviceActionsFellSleepSelection.equals(PREF_DEVICE_ACTION_SELECTION_BROADCAST); + boolean deviceActionsFellSleepSelectionBroadcast = deviceActionsFellSleepSelection.contains(PREF_DEVICE_ACTION_SELECTION_BROADCAST); if (deviceActionsFellSleep != null) { deviceActionsFellSleep.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { - final boolean broadcast = PREF_DEVICE_ACTION_SELECTION_BROADCAST.equals(newVal.toString()); + final Set newValSet = (Set) newVal; + final boolean broadcast = newValSet.contains(PREF_DEVICE_ACTION_SELECTION_BROADCAST); Objects.requireNonNull(deviceActionsFellSleepBroadcast).setEnabled(broadcast); return true; } @@ -863,15 +861,16 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i deviceActionsFellSleepBroadcast.setEnabled(deviceActionsFellSleepSelectionBroadcast); } - String deviceActionsWokeUpSelection = prefs.getString(PREF_DEVICE_ACTION_WOKE_UP_SELECTION, PREF_DEVICE_ACTION_SELECTION_OFF); - final Preference deviceActionsWokeUp = findPreference(PREF_DEVICE_ACTION_WOKE_UP_SELECTION); + Set deviceActionsWokeUpSelection = prefs.getStringSet(PREF_DEVICE_ACTION_WOKE_UP_SELECTIONS, Collections.emptySet()); + final Preference deviceActionsWokeUp = findPreference(PREF_DEVICE_ACTION_WOKE_UP_SELECTIONS); final Preference deviceActionsWokeUpBroadcast = findPreference(PREF_DEVICE_ACTION_WOKE_UP_BROADCAST); - boolean deviceActionsWokeUpSelectionBroadcast = deviceActionsWokeUpSelection.equals(PREF_DEVICE_ACTION_SELECTION_BROADCAST); + boolean deviceActionsWokeUpSelectionBroadcast = deviceActionsWokeUpSelection.contains(PREF_DEVICE_ACTION_SELECTION_BROADCAST); if (deviceActionsWokeUp != null) { deviceActionsWokeUp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { - final boolean broadcast = PREF_DEVICE_ACTION_SELECTION_BROADCAST.equals(newVal.toString()); + final Set newValSet = (Set) newVal; + final boolean broadcast = newValSet.contains(PREF_DEVICE_ACTION_SELECTION_BROADCAST); Objects.requireNonNull(deviceActionsWokeUpBroadcast).setEnabled(broadcast); return true; } @@ -881,15 +880,16 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i deviceActionsWokeUpBroadcast.setEnabled(deviceActionsWokeUpSelectionBroadcast); } - String deviceActionsStartNonWearSelection = prefs.getString(PREF_DEVICE_ACTION_START_NON_WEAR_SELECTION, PREF_DEVICE_ACTION_SELECTION_OFF); - final Preference deviceActionsStartNonWear = findPreference(PREF_DEVICE_ACTION_START_NON_WEAR_SELECTION); + Set deviceActionsStartNonWearSelection = prefs.getStringSet(PREF_DEVICE_ACTION_START_NON_WEAR_SELECTIONS, Collections.emptySet()); + final Preference deviceActionsStartNonWear = findPreference(PREF_DEVICE_ACTION_START_NON_WEAR_SELECTIONS); final Preference deviceActionsStartNonWearBroadcast = findPreference(PREF_DEVICE_ACTION_START_NON_WEAR_BROADCAST); - boolean deviceActionsStartNonWearSelectionBroadcast = deviceActionsStartNonWearSelection.equals(PREF_DEVICE_ACTION_SELECTION_BROADCAST); + boolean deviceActionsStartNonWearSelectionBroadcast = deviceActionsStartNonWearSelection.contains(PREF_DEVICE_ACTION_SELECTION_BROADCAST); if (deviceActionsStartNonWear != null) { deviceActionsStartNonWear.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { - final boolean broadcast = PREF_DEVICE_ACTION_SELECTION_BROADCAST.equals(newVal.toString()); + final Set newValSet = (Set) newVal; + final boolean broadcast = newValSet.contains(PREF_DEVICE_ACTION_SELECTION_BROADCAST); Objects.requireNonNull(deviceActionsStartNonWearBroadcast).setEnabled(broadcast); return true; } @@ -1030,6 +1030,9 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i final Set keysWithSummary = new HashSet<>(); keysWithSummary.add(PREF_INACTIVITY_THRESHOLD); + keysWithSummary.add(PREF_DEVICE_ACTION_FELL_SLEEP_SELECTIONS); + keysWithSummary.add(PREF_DEVICE_ACTION_START_NON_WEAR_SELECTIONS); + keysWithSummary.add(PREF_DEVICE_ACTION_WOKE_UP_SELECTIONS); if (deviceSpecificSettingsCustomizer != null) { keysWithSummary.addAll(deviceSpecificSettingsCustomizer.getPreferenceKeysWithSummary()); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java index 832c09f74..84e371f72 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractDeviceSupport.java @@ -46,9 +46,11 @@ import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.Locale; import java.util.Objects; +import java.util.Set; import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.GBApplication; @@ -533,16 +535,16 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { * Helper method to run specific actions configured in the device preferences, upon wear state * or awake/asleep events. * - * @param action + * @param actions * @param message */ - private void handleDeviceAction(String action, String message) { - String actionDisabled = getContext().getString(R.string.pref_button_action_disabled_value); - - if (actionDisabled.equals(action)) { + private void handleDeviceAction(Set actions, String message) { + if (actions.isEmpty()) { return; } + LOG.debug("Handing device actions: {}", String.join(",", actions)); + final String actionBroadcast = getContext().getString(R.string.pref_device_action_broadcast_value); final String actionFitnessControlStart = getContext().getString(R.string.pref_device_action_fitness_app_control_start_value); final String actionFitnessControlStop = getContext().getString(R.string.pref_device_action_fitness_app_control_stop_value); @@ -555,71 +557,66 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { final String actionDndAlarms = getContext().getString(R.string.pref_device_action_dnd_alarms_value); final String actionDndOn = getContext().getString(R.string.pref_device_action_dnd_on_value); - if (actionBroadcast.equals(action)) { + if (actions.contains(actionBroadcast)) { if (message != null) { Intent in = new Intent(); in.setAction(message); - LOG.info("Sending broadcast " + message); + LOG.info("Sending broadcast {}", message); getContext().getApplicationContext().sendBroadcast(in); - return; } } - if (actionFitnessControlStart.equals(action)) { + if (actions.contains(actionFitnessControlStart)) { OpenTracksController.startRecording(getContext()); - return; - } - - if (actionFitnessControlStop.equals(action)) { + } else if (actions.contains(actionFitnessControlStop)) { OpenTracksController.stopRecording(getContext()); - return; - } - - if (actionFitnessControlToggle.equals(action)) { + } else if (actions.contains(actionFitnessControlToggle)) { OpenTracksController.toggleRecording(getContext()); - return; } - if (actionMediaPlay.equals(action) || - actionMediaPause.equals(action) || - actionMediaPlayPause.equals(action) - ) { + final String mediaAction; + if (actions.contains(actionMediaPlayPause)) { + mediaAction = actionMediaPlayPause; + } else if (actions.contains(actionMediaPause)) { + mediaAction = actionMediaPause; + } else if (actions.contains(actionMediaPlay)) { + mediaAction = actionMediaPlay; + } else { + mediaAction = null; + } + + if (mediaAction != null) { GBDeviceEventMusicControl deviceEventMusicControl = new GBDeviceEventMusicControl(); - deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.valueOf(action); + deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.valueOf(mediaAction); evaluateGBDeviceEvent(deviceEventMusicControl); - return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final int interruptionFilter; - if (actionDndOff.equals(action)) { + if (actions.contains(actionDndOff)) { interruptionFilter = NotificationManager.INTERRUPTION_FILTER_ALL; - } else if (actionDndpriority.equals(action)) { + } else if (actions.contains(actionDndpriority)) { interruptionFilter = NotificationManager.INTERRUPTION_FILTER_PRIORITY; - } else if (actionDndAlarms.equals(action)) { + } else if (actions.contains(actionDndAlarms)) { interruptionFilter = NotificationManager.INTERRUPTION_FILTER_ALARMS; - } else if (actionDndOn.equals(action)) { + } else if (actions.contains(actionDndOn)) { interruptionFilter = NotificationManager.INTERRUPTION_FILTER_NONE; } else { interruptionFilter = NotificationManager.INTERRUPTION_FILTER_UNKNOWN; } if (interruptionFilter != NotificationManager.INTERRUPTION_FILTER_UNKNOWN) { - LOG.debug("Setting do not disturb to {} for {}", interruptionFilter, action); + LOG.debug("Setting do not disturb to {}", interruptionFilter); if (!notificationManager.isNotificationPolicyAccessGranted()) { LOG.warn("Do not disturb permissions not granted"); - return; } notificationManager.setInterruptionFilter(interruptionFilter); - return; } } - - LOG.warn("Unhandled device state change action (action: {}, message: {})", action, message); } private void handleGBDeviceEvent(GBDeviceEventSleepStateDetection event) { @@ -629,18 +626,17 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { return; } - String actionDisabled = getContext().getString(R.string.pref_button_action_disabled_value); String actionPreferenceKey, messagePreferenceKey; int defaultBroadcastMessageResource; switch (event.sleepState) { case AWAKE: - actionPreferenceKey = DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_WOKE_UP_SELECTION; + actionPreferenceKey = DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_WOKE_UP_SELECTIONS; messagePreferenceKey = DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_WOKE_UP_BROADCAST; defaultBroadcastMessageResource = R.string.prefs_events_forwarding_wokeup_broadcast_default_value; break; case ASLEEP: - actionPreferenceKey = DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_FELL_SLEEP_SELECTION; + actionPreferenceKey = DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_FELL_SLEEP_SELECTIONS; messagePreferenceKey = DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_FELL_SLEEP_BROADCAST; defaultBroadcastMessageResource = R.string.prefs_events_forwarding_fellsleep_broadcast_default_value; break; @@ -649,14 +645,14 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { return; } - String action = getDevicePrefs().getString(actionPreferenceKey, actionDisabled); + Set actions = getDevicePrefs().getStringSet(actionPreferenceKey, Collections.emptySet()); - if (actionDisabled.equals(action)) { + if (actions.isEmpty()) { return; } String broadcastMessage = getDevicePrefs().getString(messagePreferenceKey, context.getString(defaultBroadcastMessageResource)); - handleDeviceAction(action, broadcastMessage); + handleDeviceAction(actions, broadcastMessage); } private void handleGBDeviceEvent(GBDeviceEventWearState event) { @@ -671,14 +667,13 @@ public abstract class AbstractDeviceSupport implements DeviceSupport { LOG.debug("WEAR_STATE state is not NOT_WEARING, aborting further evaluation"); } - String valueDisabled = getContext().getString(R.string.pref_button_action_disabled_value); - String actionOnUnwear = getDevicePrefs().getString( - DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_START_NON_WEAR_SELECTION, - valueDisabled + Set actionOnUnwear = getDevicePrefs().getStringSet( + DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_START_NON_WEAR_SELECTIONS, + Collections.emptySet() ); // check if an action is set - if (actionOnUnwear.equals(valueDisabled)) { + if (actionOnUnwear.isEmpty()) { return; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index 5df6eb42f..557afb49a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -225,7 +225,6 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_USER_FITNESS_GOAL_NOTIFICATION; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_WEARLOCATION; -import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_ACTION_SELECTION_OFF; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Service.WORKOUT_GPS_FLAG_POSITION; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Service.WORKOUT_GPS_FLAG_STATUS; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_BUTTON_ACTION_SELECTION_BROADCAST; @@ -1825,7 +1824,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements } private void handleMediaButton(String mediaAction) { - if (mediaAction.equals(PREF_DEVICE_ACTION_SELECTION_OFF) || mediaAction.equals(PREF_BUTTON_ACTION_SELECTION_OFF)) { + if (mediaAction.equals(PREF_BUTTON_ACTION_SELECTION_OFF)) { return; } GBDeviceEventMusicControl deviceEventMusicControl = new GBDeviceEventMusicControl(); diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 176b46307..4d05fdf2c 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -1,5 +1,9 @@ + + + + @string/pref_theme_system @string/pref_theme_light @@ -2554,7 +2558,6 @@ - @string/pref_button_action_disabled @string/pref_media_play @string/pref_media_pause @string/pref_media_playpause @@ -2569,7 +2572,6 @@ - @string/pref_button_action_disabled_value @string/pref_media_play_value @string/pref_media_pause_value @string/pref_media_playpause_value diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 089c7029c..2be00ba70 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2439,4 +2439,5 @@ Xiaomi Watch S1 Active Mi Watch Color Sport Pixoo + Not set diff --git a/app/src/main/res/xml/devicesettings_device_actions.xml b/app/src/main/res/xml/devicesettings_device_actions.xml index 39ca0a2d4..db353cfc6 100644 --- a/app/src/main/res/xml/devicesettings_device_actions.xml +++ b/app/src/main/res/xml/devicesettings_device_actions.xml @@ -12,12 +12,11 @@ android:title="@string/prefs_events_forwarding_fellsleep" android:icon="@drawable/ic_nights_stay"> - - - - -