mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 01:55:50 +01:00
Amazfit Bip 3 Pro: Fix title and sender on some notifications (#4419)
This commit is contained in:
parent
b220a2553c
commit
a8d617259d
@ -922,6 +922,42 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
|||||||
return message;
|
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
|
@Override
|
||||||
public void onNotification(NotificationSpec notificationSpec) {
|
public void onNotification(NotificationSpec notificationSpec) {
|
||||||
final boolean hasExtraHeader = notificationHasExtraHeader();
|
final boolean hasExtraHeader = notificationHasExtraHeader();
|
||||||
|
@ -25,6 +25,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip3pro.AmazfitBip3ProFWHelper;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip3pro.AmazfitBip3ProFWHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.update.UpdateFirmwareOperation;
|
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);
|
setDisplayItemsNew(builder, false, false, R.array.pref_gtsgtr2_display_items_default);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNotificationBody(NotificationSpec notificationSpec) {
|
||||||
|
// See #4419
|
||||||
|
return getNotificationBodyCheckAcceptsSender(notificationSpec);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts2.AmazfitGTS2MiniFWHelper;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts2.AmazfitGTS2MiniFWHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
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.service.devices.huami.HuamiSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
|
||||||
|
|
||||||
public class AmazfitGTS2MiniSupport extends AmazfitGTS2Support {
|
public class AmazfitGTS2MiniSupport extends AmazfitGTS2Support {
|
||||||
|
|
||||||
@ -47,36 +45,8 @@ public class AmazfitGTS2MiniSupport extends AmazfitGTS2Support {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNotificationBody(NotificationSpec notificationSpec){
|
public String getNotificationBody(NotificationSpec notificationSpec) {
|
||||||
String senderOrTitle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title);
|
// #2987
|
||||||
byte customIconId = HuamiIcon.mapToIconId(notificationSpec.type);
|
return getNotificationBodyCheckAcceptsSender(notificationSpec);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user