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 e2883b7b9..398d68d4a 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 @@ -922,6 +922,42 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements return message; } + /** + * #2987 / #4419 - Some devices do not show the sender / title for certain notification types + */ + public String getNotificationBodyCheckAcceptsSender(NotificationSpec notificationSpec) { + String senderOrTitle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title); + byte customIconId = HuamiIcon.mapToIconId(notificationSpec.type); + boolean acceptsSender = HuamiIcon.acceptsSender(customIconId); + String message; + + /* The title will be displayed beside the icon depending on the icon ID sent to the + device. If the icon ID does not admit a title, it will display the app's name, and + we will repeat the subject as part of the notification body, but only if the app name + is different from the subject. That way it's aesthetically pleasing. + */ + if (!acceptsSender && !senderOrTitle.equals(notificationSpec.sourceName)) { + message = "-\0"; //if the sender is not accepted, whatever goes in this field is ignored + message += senderOrTitle + "\n"; + } else { + message = senderOrTitle + "\0"; + } + + if (notificationSpec.subject != null) { + message += StringUtils.truncate(notificationSpec.subject, 128) + "\n\n"; + } + + if (notificationSpec.body != null) { + message += StringUtils.truncate(notificationSpec.body, 512); + } + + if (notificationSpec.body == null && notificationSpec.subject == null) { + message += " "; + } + + return message; + } + @Override public void onNotification(NotificationSpec notificationSpec) { final boolean hasExtraHeader = notificationHasExtraHeader(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip3pro/AmazfitBip3ProSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip3pro/AmazfitBip3ProSupport.java index 08e8ffdba..08f4765d1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip3pro/AmazfitBip3ProSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbip3pro/AmazfitBip3ProSupport.java @@ -25,6 +25,7 @@ import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip3pro.AmazfitBip3ProFWHelper; import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.update.UpdateFirmwareOperation; @@ -76,4 +77,10 @@ public class AmazfitBip3ProSupport extends AmazfitBipSupport { setDisplayItemsNew(builder, false, false, R.array.pref_gtsgtr2_display_items_default); return this; } + + @Override + public String getNotificationBody(NotificationSpec notificationSpec) { + // See #4419 + return getNotificationBodyCheckAcceptsSender(notificationSpec); + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2MiniSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2MiniSupport.java index b12b38854..41ce7b51e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2MiniSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts2/AmazfitGTS2MiniSupport.java @@ -28,9 +28,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts2.AmazfitGTS2MiniFWHelper; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiIcon; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; -import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; public class AmazfitGTS2MiniSupport extends AmazfitGTS2Support { @@ -47,36 +45,8 @@ public class AmazfitGTS2MiniSupport extends AmazfitGTS2Support { } @Override - public String getNotificationBody(NotificationSpec notificationSpec){ - String senderOrTitle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title); - byte customIconId = HuamiIcon.mapToIconId(notificationSpec.type); - boolean acceptsSender = HuamiIcon.acceptsSender(customIconId); - String message; - - /* The title will be displayed beside the icon depending on the icon ID sent to the - device. If the icon ID does not admit a title, it will display the app's name, and - we will repeat the subject as part of the notification body, but only if the app name - is different from the subject. That way it's aesthetically pleasing. - */ - if(!acceptsSender && !senderOrTitle.equals(notificationSpec.sourceName)) { - message = "-\0"; //if the sender is not accepted, whatever goes in this field is ignored - message += senderOrTitle + "\n"; - } else { - message = senderOrTitle + "\0"; - } - - if(notificationSpec.subject != null) { - message += StringUtils.truncate(notificationSpec.subject, 128) + "\n\n"; - } - - if(notificationSpec.body != null) { - message += StringUtils.truncate(notificationSpec.body, 512); - } - - if(notificationSpec.body == null && notificationSpec.subject == null) { - message += " "; - } - - return message; + public String getNotificationBody(NotificationSpec notificationSpec) { + // #2987 + return getNotificationBodyCheckAcceptsSender(notificationSpec); } }