mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-26 09:11:37 +02:00
Garmin: Add setting to disable notifications
This commit is contained in:
parent
33eb748b64
commit
cf02a02a48
@ -356,7 +356,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
addPreferenceHandlerFor(PREF_SEND_APP_NOTIFICATIONS);
|
||||
addPreferenceHandlerFor(PREF_SWIPE_UNLOCK);
|
||||
addPreferenceHandlerFor(PREF_MI2_DATEFORMAT);
|
||||
addPreferenceHandlerFor(PREF_DATEFORMAT);
|
||||
|
@ -39,9 +39,10 @@ public abstract class GarminCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
final List<Integer> connection = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.CONNECTION);
|
||||
connection.add(R.xml.devicesettings_high_mtu);
|
||||
|
||||
if (getCannedRepliesSlotCount(device) > 0) {
|
||||
final List<Integer> notifications = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.CALLS_AND_NOTIFICATIONS);
|
||||
final List<Integer> notifications = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.CALLS_AND_NOTIFICATIONS);
|
||||
notifications.add(R.xml.devicesettings_send_app_notifications);
|
||||
|
||||
if (getCannedRepliesSlotCount(device) > 0) {
|
||||
notifications.add(R.xml.devicesettings_garmin_default_reply_suffix);
|
||||
notifications.add(R.xml.devicesettings_canned_reply_16);
|
||||
notifications.add(R.xml.devicesettings_canned_dismisscall_16);
|
||||
|
@ -60,12 +60,14 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SetD
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SetFileFlagsMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SupportedFileTypesMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.SystemEventMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status.NotificationSubscriptionStatusMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ALLOW_HIGH_MTU;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GARMIN_DEFAULT_REPLY_SUFFIX;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS;
|
||||
|
||||
|
||||
public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommunicator.Callback {
|
||||
@ -230,7 +232,22 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
|
||||
} else if (deviceEvent instanceof NotificationSubscriptionDeviceEvent) {
|
||||
final boolean enable = ((NotificationSubscriptionDeviceEvent) deviceEvent).enable;
|
||||
notificationsHandler.setEnabled(enable);
|
||||
LOG.info("NOTIFICATIONS ARE NOW {}", enable ? "ON" : "OFF");
|
||||
|
||||
final NotificationSubscriptionStatusMessage.NotificationStatus finalStatus;
|
||||
if (getDevicePrefs().getBoolean(PREF_SEND_APP_NOTIFICATIONS, true)) {
|
||||
finalStatus = NotificationSubscriptionStatusMessage.NotificationStatus.ENABLED;
|
||||
} else {
|
||||
finalStatus = NotificationSubscriptionStatusMessage.NotificationStatus.DISABLED;
|
||||
}
|
||||
|
||||
LOG.info("NOTIFICATIONS ARE NOW enabled={}, status={}", enable, finalStatus);
|
||||
|
||||
sendOutgoingMessage(new NotificationSubscriptionStatusMessage(
|
||||
GFDIMessage.Status.ACK,
|
||||
finalStatus,
|
||||
enable,
|
||||
0
|
||||
));
|
||||
} else if (deviceEvent instanceof SupportedFileTypesDeviceEvent) {
|
||||
this.supportedFileTypeList.clear();
|
||||
this.supportedFileTypeList.addAll(((SupportedFileTypesDeviceEvent) deviceEvent).getSupportedFileTypes());
|
||||
@ -261,7 +278,7 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotification(NotificationSpec notificationSpec) {
|
||||
public void onNotification(final NotificationSpec notificationSpec) {
|
||||
sendOutgoingMessage(notificationsHandler.onNotification(notificationSpec));
|
||||
}
|
||||
|
||||
@ -406,8 +423,15 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
|
||||
|
||||
@Override
|
||||
public void onSendConfiguration(String config) {
|
||||
if (PREF_GARMIN_DEFAULT_REPLY_SUFFIX.equals(config)) {
|
||||
sendOutgoingMessage(toggleDefaultReplySuffix(getDevicePrefs().getBoolean(PREF_GARMIN_DEFAULT_REPLY_SUFFIX, true)));
|
||||
switch (config) {
|
||||
case PREF_GARMIN_DEFAULT_REPLY_SUFFIX:
|
||||
sendOutgoingMessage(toggleDefaultReplySuffix(getDevicePrefs().getBoolean(PREF_GARMIN_DEFAULT_REPLY_SUFFIX, true)));
|
||||
break;
|
||||
case PREF_SEND_APP_NOTIFICATIONS:
|
||||
NotificationSubscriptionDeviceEvent notificationSubscriptionDeviceEvent = new NotificationSubscriptionDeviceEvent();
|
||||
notificationSubscriptionDeviceEvent.enable = true; // actual status is fetched from preferences
|
||||
evaluateGBDeviceEvent(notificationSubscriptionDeviceEvent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,8 @@ public class NotificationSubscriptionMessage extends GFDIMessage {
|
||||
this.enable = enable;
|
||||
this.unk = unk;
|
||||
|
||||
this.statusMessage = new NotificationSubscriptionStatusMessage(Status.ACK, NotificationSubscriptionStatusMessage.NotificationStatus.OK, enable, unk);
|
||||
// We do not set the status message here so we can reply with the proper notifications status
|
||||
// from the device event
|
||||
}
|
||||
|
||||
public static NotificationSubscriptionMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
||||
|
@ -33,7 +33,8 @@ public class NotificationSubscriptionStatusMessage extends GFDIStatusMessage {
|
||||
}
|
||||
|
||||
public enum NotificationStatus {
|
||||
OK,
|
||||
ENABLED,
|
||||
DISABLED
|
||||
;
|
||||
|
||||
public static NotificationStatus fromId(int id) {
|
||||
|
Loading…
Reference in New Issue
Block a user