mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-25 08:05:55 +01:00
Allow multiple device actions to be triggered for the same event
This commit is contained in:
parent
25196a932e
commit
4d12ac93e7
@ -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<Device> 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();
|
||||
}
|
||||
|
@ -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<String> 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<String> 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);
|
||||
}
|
||||
|
||||
|
@ -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";
|
||||
}
|
||||
|
@ -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<String> 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<String> newValSet = (Set<String>) 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<String> 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<String> newValSet = (Set<String>) 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<String> 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<String> newValSet = (Set<String>) 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<String> 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());
|
||||
|
@ -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<String> 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<String> 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<String> 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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -1,5 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="empty_array">
|
||||
<!-- empty array -->
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_theme_options">
|
||||
<item>@string/pref_theme_system</item>
|
||||
<item>@string/pref_theme_light</item>
|
||||
@ -2554,7 +2558,6 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="device_action_options">
|
||||
<item>@string/pref_button_action_disabled</item>
|
||||
<item>@string/pref_media_play</item>
|
||||
<item>@string/pref_media_pause</item>
|
||||
<item>@string/pref_media_playpause</item>
|
||||
@ -2569,7 +2572,6 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="device_action_values">
|
||||
<item>@string/pref_button_action_disabled_value</item>
|
||||
<item>@string/pref_media_play_value</item>
|
||||
<item>@string/pref_media_pause_value</item>
|
||||
<item>@string/pref_media_playpause_value</item>
|
||||
|
@ -2439,4 +2439,5 @@
|
||||
<string name="devicetype_xiaomi_watch_s1_active">Xiaomi Watch S1 Active</string>
|
||||
<string name="devicetype_mi_watch_color_sport">Mi Watch Color Sport</string>
|
||||
<string name="devicetype_pixoo">Pixoo</string>
|
||||
<string name="not_set">Not set</string>
|
||||
</resources>
|
||||
|
@ -12,12 +12,11 @@
|
||||
android:title="@string/prefs_events_forwarding_fellsleep"
|
||||
android:icon="@drawable/ic_nights_stay">
|
||||
|
||||
<ListPreference
|
||||
<MultiSelectListPreference
|
||||
android:entries="@array/device_action_options"
|
||||
android:entryValues="@array/device_action_values"
|
||||
android:key="events_forwarding_fellsleep_action_selection"
|
||||
android:summary="%s"
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
android:key="events_forwarding_fellsleep_action_selections"
|
||||
android:defaultValue="@array/empty_array"
|
||||
android:title="@string/prefs_events_forwarding_action_title" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="@string/prefs_events_forwarding_fellsleep_broadcast_default_value"
|
||||
@ -30,12 +29,11 @@
|
||||
android:title="@string/prefs_events_forwarding_wokeup"
|
||||
android:icon="@drawable/ic_wb_sunny">
|
||||
|
||||
<ListPreference
|
||||
<MultiSelectListPreference
|
||||
android:entries="@array/device_action_options"
|
||||
android:entryValues="@array/device_action_values"
|
||||
android:key="events_forwarding_wokeup_action_selection"
|
||||
android:summary="%s"
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
android:key="events_forwarding_wokeup_action_selections"
|
||||
android:defaultValue="@array/empty_array"
|
||||
android:title="@string/prefs_events_forwarding_action_title" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="@string/prefs_events_forwarding_wokeup_broadcast_default_value"
|
||||
@ -48,12 +46,12 @@
|
||||
android:title="@string/prefs_events_forwarding_startnonwear"
|
||||
android:icon="@drawable/ic_no_watch">
|
||||
|
||||
<ListPreference
|
||||
<MultiSelectListPreference
|
||||
android:entries="@array/device_action_options"
|
||||
android:entryValues="@array/device_action_values"
|
||||
android:key="events_forwarding_startnonwear_action_selection"
|
||||
android:key="events_forwarding_startnonwear_action_selections"
|
||||
android:summary="%s"
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
android:defaultValue="@array/empty_array"
|
||||
android:title="@string/prefs_events_forwarding_action_title" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="@string/prefs_events_forwarding_startnonwear_broadcast_default_value"
|
||||
|
@ -12,11 +12,11 @@
|
||||
android:icon="@drawable/ic_nights_stay"
|
||||
android:title="@string/prefs_events_forwarding_fellsleep">
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
<MultiSelectListPreference
|
||||
android:defaultValue="@array/empty_array"
|
||||
android:entries="@array/device_action_options"
|
||||
android:entryValues="@array/device_action_values"
|
||||
android:key="events_forwarding_fellsleep_action_selection"
|
||||
android:key="events_forwarding_fellsleep_action_selections"
|
||||
android:summary="%s"
|
||||
android:title="@string/prefs_events_forwarding_action_title" />
|
||||
<EditTextPreference
|
||||
@ -30,11 +30,11 @@
|
||||
android:icon="@drawable/ic_wb_sunny"
|
||||
android:title="@string/prefs_events_forwarding_wokeup">
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
<MultiSelectListPreference
|
||||
android:defaultValue="@array/empty_array"
|
||||
android:entries="@array/device_action_options"
|
||||
android:entryValues="@array/device_action_values"
|
||||
android:key="events_forwarding_wokeup_action_selection"
|
||||
android:key="events_forwarding_wokeup_action_selections"
|
||||
android:summary="%s"
|
||||
android:title="@string/prefs_events_forwarding_action_title" />
|
||||
<EditTextPreference
|
||||
|
Loading…
Reference in New Issue
Block a user