mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-12 18:57:36 +01:00
Fixed regression undoing PR #2474, notification content preserved for Amazfit GTS 2 Mini
This commit is contained in:
parent
abf19f2b6c
commit
4386f321a3
@ -19,6 +19,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.Context;
|
||||
@ -822,11 +823,13 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotification(NotificationSpec notificationSpec) {
|
||||
final boolean hasExtraHeader = notificationHasExtraHeader();
|
||||
final int maxLength = notificationMaxLength();
|
||||
|
||||
/**
|
||||
* Contains the logic to build the text content that will be sent to the device.
|
||||
* Some huami devices will omit some of the content.
|
||||
* @param notificationSpec
|
||||
* @return
|
||||
*/
|
||||
public String getNotificationBody(NotificationSpec notificationSpec) {
|
||||
String senderOrTitle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title);
|
||||
|
||||
String message = StringUtils.truncate(senderOrTitle, 32) + "\0";
|
||||
@ -840,6 +843,16 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
message += " "; // if we have no body we have to send at least something on some devices, else they reboot (Bip S)
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotification(NotificationSpec notificationSpec) {
|
||||
final boolean hasExtraHeader = notificationHasExtraHeader();
|
||||
final int maxLength = notificationMaxLength();
|
||||
|
||||
String message = getNotificationBody(notificationSpec);
|
||||
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("new notification");
|
||||
|
||||
|
@ -27,8 +27,11 @@ import java.io.IOException;
|
||||
|
||||
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 {
|
||||
|
||||
@ -43,4 +46,38 @@ public class AmazfitGTS2MiniSupport extends AmazfitGTS2Support {
|
||||
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
|
||||
return new AmazfitGTS2MiniFWHelper(uri, context);
|
||||
}
|
||||
|
||||
@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;
|
||||
} else {
|
||||
message = senderOrTitle;
|
||||
}
|
||||
|
||||
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…
x
Reference in New Issue
Block a user