diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java index 69e9e3f97..3dbd44764 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLETypeConversions.java @@ -264,20 +264,29 @@ public class BLETypeConversions { case GENERIC_SMS: return AlertCategory.SMS; case GENERIC_EMAIL: + case GMAIL: + case OUTLOOK: + case YAHOO_MAIL: return AlertCategory.Email; case GENERIC_NAVIGATION: return AlertCategory.Simple; + case CONVERSATIONS: + case FACEBOOK_MESSENGER: + case GOOGLE_MESSENGER: + case GOOGLE_HANGOUTS: + case HIPCHAT: + case KAKAO_TALK: + case LINE: case RIOT: case SIGNAL: + case SKYPE: + case SNAPCHAT: case TELEGRAM: - case WHATSAPP: - case CONVERSATIONS: - case FACEBOOK: - case FACEBOOK_MESSENGER: case TWITTER: + case WHATSAPP: + case VIBER: + case WECHAT: return AlertCategory.InstantMessage; - case UNKNOWN: - return AlertCategory.Simple; } return AlertCategory.Simple; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertCategory.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertCategory.java index 4a896f411..4556e4b3a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertCategory.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertCategory.java @@ -38,7 +38,7 @@ public enum AlertCategory { // 251-255 defined by service specification Any(255), Custom(-1), - CustomMiBand2(-6); + CustomHuami(-6); private final int id; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertNotificationProfile.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertNotificationProfile.java index 11d3d9f47..1032fb242 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertNotificationProfile.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertNotificationProfile.java @@ -103,7 +103,7 @@ public class AlertNotificationProfile exten ByteArrayOutputStream stream = new ByteArrayOutputStream(100); stream.write(BLETypeConversions.fromUint8(alert.getCategory().getId())); stream.write(BLETypeConversions.fromUint8(alert.getNumAlerts())); - if (alert.getCategory() == AlertCategory.CustomMiBand2) { + if (alert.getCategory() == AlertCategory.CustomHuami) { stream.write(BLETypeConversions.fromUint8(alert.getCustomIcon())); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java index 5db13c110..11b0c84a0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java @@ -88,7 +88,7 @@ public class AmazfitBipSupport extends MiBand2Support { byte customIconId = HuamiIcon.mapToIconId(notificationSpec.type); - AlertCategory alertCategory = AlertCategory.CustomMiBand2; + AlertCategory alertCategory = AlertCategory.CustomHuami; // The SMS icon for AlertCategory.SMS is unique and not available as iconId if (notificationSpec.type == NotificationType.GENERIC_SMS) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/common/SimpleNotification.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/common/SimpleNotification.java index 2f36276a4..78f4abaa4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/common/SimpleNotification.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/common/SimpleNotification.java @@ -16,21 +16,28 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.service.devices.common; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory; public class SimpleNotification { private final String message; private final AlertCategory alertCategory; + private final NotificationType notificationType; - public SimpleNotification(String message, AlertCategory alertCategory) { + public SimpleNotification(String message, AlertCategory alertCategory, NotificationType notificationType) { this.message = message; this.alertCategory = alertCategory; + this.notificationType = notificationType; } public AlertCategory getAlertCategory() { return alertCategory; } + public NotificationType getNotificationType() { + return notificationType; + } + public String getMessage() { return message; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index a67543b36..6bda8bc8e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -587,7 +587,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } }; String message = NotificationUtils.getPreferredTextFor(notificationSpec, 40, 40, getContext()); - SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.HighPriorityAlert); + SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.HighPriorityAlert, null); performPreferredNotification("alarm clock ringing", simpleNotification, MiBandConst.ORIGIN_ALARM_CLOCK, abortAction); } @@ -653,7 +653,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } }; String message = NotificationUtils.getPreferredTextFor(callSpec); - SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.IncomingCall); + SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.IncomingCall, null); performPreferredNotification("incoming call", simpleNotification, MiBandConst.ORIGIN_INCOMING_CALL, abortAction); } else if ((callSpec.command == CallSpec.CALL_START) || (callSpec.command == CallSpec.CALL_END)) { telephoneRinging = false; @@ -745,7 +745,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { return !isLocatingDevice; } }; - SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.HighPriorityAlert); + SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.HighPriorityAlert, null); performDefaultNotification("locating device", simpleNotification, (short) 255, abortAction); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2TextNotificationStrategy.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2TextNotificationStrategy.java index 3be9596e6..17e774776 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2TextNotificationStrategy.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2TextNotificationStrategy.java @@ -20,7 +20,6 @@ import android.bluetooth.BluetoothGattCharacteristic; import android.support.annotation.NonNull; import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile; -import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiIcon; import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic; @@ -30,6 +29,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotificat import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert; import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.OverflowStrategy; import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification; +import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiIcon; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; public class Mi2TextNotificationStrategy extends Mi2NotificationStrategy { @@ -63,15 +63,13 @@ public class Mi2TextNotificationStrategy extends Mi2NotificationStrategy { protected byte[] getNotifyMessage(SimpleNotification simpleNotification) { int numAlerts = 1; - if (simpleNotification != null) { - switch (simpleNotification.getAlertCategory()) { - case Email: - return new byte[] { BLETypeConversions.fromUint8(AlertCategory.Email.getId()), BLETypeConversions.fromUint8(numAlerts)}; - case InstantMessage: - return new byte[] { BLETypeConversions.fromUint8(AlertCategory.CustomMiBand2.getId()), BLETypeConversions.fromUint8(numAlerts), HuamiIcon.WECHAT}; - case News: - return new byte[] { BLETypeConversions.fromUint8(AlertCategory.CustomMiBand2.getId()), BLETypeConversions.fromUint8(numAlerts), HuamiIcon.PENGUIN_1}; + if (simpleNotification != null && simpleNotification.getNotificationType() != null && simpleNotification.getAlertCategory() != AlertCategory.SMS) { + byte customIconId = HuamiIcon.mapToIconId(simpleNotification.getNotificationType()); + if (customIconId == HuamiIcon.EMAIL) { + // unfortunately. the email icon breaks the notification, fall back to a standard AlertCategory + return new byte[]{BLETypeConversions.fromUint8(AlertCategory.Email.getId()), BLETypeConversions.fromUint8(numAlerts)}; } + return new byte[]{BLETypeConversions.fromUint8(AlertCategory.CustomHuami.getId()), BLETypeConversions.fromUint8(numAlerts), customIconId}; } return new byte[] { BLETypeConversions.fromUint8(AlertCategory.SMS.getId()), BLETypeConversions.fromUint8(numAlerts)}; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java index 84bbd91d5..eb539d2a6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java @@ -597,7 +597,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { } String message = NotificationUtils.getPreferredTextFor(notificationSpec, 40, 40, getContext()).trim(); String origin = notificationSpec.type.getGenericType(); - SimpleNotification simpleNotification = new SimpleNotification(message, BLETypeConversions.toAlertCategory(notificationSpec.type)); + SimpleNotification simpleNotification = new SimpleNotification(message, BLETypeConversions.toAlertCategory(notificationSpec.type), notificationSpec.type); performPreferredNotification(origin + " received", origin, simpleNotification, alertLevel, null); } @@ -610,7 +610,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { } }; String message = NotificationUtils.getPreferredTextFor(notificationSpec, 40, 40, getContext()); - SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.HighPriorityAlert); + SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.HighPriorityAlert, notificationSpec.type); performPreferredNotification("alarm clock ringing", MiBandConst.ORIGIN_ALARM_CLOCK, simpleNotification, MiBand2Service.ALERT_LEVEL_VIBRATE_ONLY, abortAction); } @@ -643,7 +643,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { } }; String message = NotificationUtils.getPreferredTextFor(callSpec); - SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.IncomingCall); + SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.IncomingCall, null); performPreferredNotification("incoming call", MiBandConst.ORIGIN_INCOMING_CALL, simpleNotification, MiBand2Service.ALERT_LEVEL_PHONE_CALL, abortAction); } else if ((callSpec.command == CallSpec.CALL_START) || (callSpec.command == CallSpec.CALL_END)) { telephoneRinging = false; @@ -742,7 +742,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { return !isLocatingDevice; } }; - SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.HighPriorityAlert); + SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.HighPriorityAlert, null); performDefaultNotification("locating device", simpleNotification, (short) 255, abortAction); } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/NotificationUtils.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/NotificationUtils.java index 7939f4eb9..a99e6fa0a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/NotificationUtils.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/NotificationUtils.java @@ -34,14 +34,22 @@ public class NotificationUtils { return formatText(notificationSpec.sender, notificationSpec.subject, notificationSpec.body, lengthBody, lengthSubject, context); case GENERIC_NAVIGATION: return StringUtils.getFirstOf(notificationSpec.title, notificationSpec.body); + case CONVERSATIONS: + case FACEBOOK_MESSENGER: + case GOOGLE_MESSENGER: + case GOOGLE_HANGOUTS: + case HIPCHAT: + case KAKAO_TALK: + case LINE: case RIOT: case SIGNAL: + case SKYPE: + case SNAPCHAT: case TELEGRAM: case TWITTER: case WHATSAPP: - case CONVERSATIONS: - case FACEBOOK: - case FACEBOOK_MESSENGER: + case VIBER: + case WECHAT: return StringUtils.ensureNotNull(notificationSpec.body); } return "";