Zepp OS: Allow disabling app notifications per device

This commit is contained in:
José Rebelo 2023-12-08 11:29:20 +00:00
parent 77329813b9
commit f29995b571
5 changed files with 24 additions and 0 deletions

View File

@ -232,6 +232,7 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_CASIO_ALERT_SMS = "casio_alert_sms";
public static final String PREF_AUTOREMOVE_MESSAGE = "autoremove_message";
public static final String PREF_SEND_APP_NOTIFICATIONS = "send_app_notifications";
public static final String PREF_AUTOREMOVE_NOTIFICATIONS = "autoremove_notifications";
public static final String PREF_SCREEN_ON_ON_NOTIFICATIONS = "screen_on_on_notifications";
public static final String PREF_WORKOUT_KEEP_SCREEN_ON = "workout_keep_screen_on";

View File

@ -398,6 +398,7 @@ public abstract class Huami2021Coordinator extends HuamiCoordinator {
settings.add(R.xml.devicesettings_sound_and_vibration);
settings.add(R.xml.devicesettings_vibrationpatterns);
settings.add(R.xml.devicesettings_donotdisturb_withauto_and_always);
settings.add(R.xml.devicesettings_send_app_notifications);
settings.add(R.xml.devicesettings_screen_on_on_notifications);
settings.add(R.xml.devicesettings_autoremove_notifications);
settings.add(R.xml.devicesettings_canned_reply_16);

View File

@ -31,6 +31,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Locale;
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventNotificationControl;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
@ -215,6 +216,11 @@ public class ZeppOsNotificationService extends AbstractZeppOsService {
}
public void sendNotification(final NotificationSpec notificationSpec) {
if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) {
LOG.debug("App notifications disabled - ignoring");
return;
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final String senderOrTitle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title);
@ -289,6 +295,11 @@ public class ZeppOsNotificationService extends AbstractZeppOsService {
}
public void deleteNotification(final int id) {
if (!getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_SEND_APP_NOTIFICATIONS, true)) {
LOG.debug("App notifications disabled - ignoring delete");
return;
}
LOG.info("Deleting notification {} from band", id);
final ByteBuffer buf = ByteBuffer.allocate(12);

View File

@ -348,6 +348,8 @@
<string name="pref_summary_autoremove_notifications">Notifications are automatically removed from the device when dismissed from the phone</string>
<string name="pref_title_screen_on_on_notifications">Screen On on Notifications</string>
<string name="pref_summary_screen_on_on_notifications">Turn on the band\'s screen when a notification arrives</string>
<string name="pref_title_send_app_notifications">Send notifications</string>
<string name="pref_summary_send_app_notifications">Send app notifications to the device</string>
<string name="pref_title_pebble_privacy_mode">Privacy mode</string>
<string name="pref_pebble_privacy_mode_off">Normal notifications</string>
<string name="pref_pebble_privacy_mode_content">Shift the notification text off-screen</string>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreferenceCompat
android:defaultValue="true"
android:icon="@drawable/ic_notifications"
android:key="send_app_notifications"
android:summary="@string/pref_summary_send_app_notifications"
android:title="@string/pref_title_send_app_notifications" />
</androidx.preference.PreferenceScreen>