1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Bangle.js: add wake on notification response OPEN

This commit is contained in:
Ganblejs 2024-04-09 21:48:56 +02:00 committed by José Rebelo
parent 594c409067
commit 96bbd578c8
2 changed files with 16 additions and 1 deletions

View File

@ -187,6 +187,7 @@ public class BangleJSCoordinator extends AbstractBLEDeviceCoordinator {
settings.add(R.xml.devicesettings_header_notifications); settings.add(R.xml.devicesettings_header_notifications);
settings.add(R.xml.devicesettings_send_app_notifications); settings.add(R.xml.devicesettings_send_app_notifications);
settings.add(R.xml.devicesettings_notification_wake_on_open);
settings.add(R.xml.devicesettings_text_bitmaps); settings.add(R.xml.devicesettings_text_bitmaps);
settings.add(R.xml.devicesettings_transliteration); settings.add(R.xml.devicesettings_transliteration);

View File

@ -27,6 +27,7 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_GPS_USE_NETWORK_ONLY; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_GPS_USE_NETWORK_ONLY;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_INTENTS; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_INTENTS;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_INTERNET_ACCESS; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_INTERNET_ACCESS;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_NOTIFICATION_WAKE_ON_OPEN;
import static nodomain.freeyourgadget.gadgetbridge.database.DBHelper.getUser; import static nodomain.freeyourgadget.gadgetbridge.database.DBHelper.getUser;
import static nodomain.freeyourgadget.gadgetbridge.devices.banglejs.BangleJSConstants.PREF_BANGLEJS_ACTIVITY_FULL_SYNC_START; import static nodomain.freeyourgadget.gadgetbridge.devices.banglejs.BangleJSConstants.PREF_BANGLEJS_ACTIVITY_FULL_SYNC_START;
import static nodomain.freeyourgadget.gadgetbridge.devices.banglejs.BangleJSConstants.PREF_BANGLEJS_ACTIVITY_FULL_SYNC_STATUS; import static nodomain.freeyourgadget.gadgetbridge.devices.banglejs.BangleJSConstants.PREF_BANGLEJS_ACTIVITY_FULL_SYNC_STATUS;
@ -98,6 +99,7 @@ import io.wax911.emojify.EmojiUtils;
import nodomain.freeyourgadget.gadgetbridge.BuildConfig; import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.WakeActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.capabilities.loyaltycards.BarcodeFormat; import nodomain.freeyourgadget.gadgetbridge.capabilities.loyaltycards.BarcodeFormat;
import nodomain.freeyourgadget.gadgetbridge.capabilities.loyaltycards.LoyaltyCard; import nodomain.freeyourgadget.gadgetbridge.capabilities.loyaltycards.LoyaltyCard;
@ -637,9 +639,21 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
* Handle "notify" packet, used to send notification control from device to GB * Handle "notify" packet, used to send notification control from device to GB
*/ */
private void handleNotificationControl(JSONObject json) throws JSONException { private void handleNotificationControl(JSONObject json) throws JSONException {
String response = json.getString("n").toUpperCase();
LOG.debug("Notification response: " + response);
// Wake the Android device if the setting is toggled on by user.
// Doesn't work if run after the notification handling below for some reason (which
// I'd rather do since the screen would only be opened once the content was ready).
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
if (devicePrefs.getBoolean(PREF_NOTIFICATION_WAKE_ON_OPEN, false) && response.equals("OPEN")) {
WakeActivity.start(getContext());
}
GBDeviceEventNotificationControl deviceEvtNotificationControl = new GBDeviceEventNotificationControl(); GBDeviceEventNotificationControl deviceEvtNotificationControl = new GBDeviceEventNotificationControl();
// .title appears unused // .title appears unused
deviceEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.valueOf(json.getString("n").toUpperCase()); deviceEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.valueOf(response);
if (json.has("id")) if (json.has("id"))
deviceEvtNotificationControl.handle = json.getInt("id"); deviceEvtNotificationControl.handle = json.getInt("id");
if (json.has("tel")) if (json.has("tel"))