mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
PineTime: Improve notification handling
* If setting enabled, add source application (or SMS) * Fallback to using notification subject if body is unavailable * Trim/cut sender or title at 25+ chars if necessary * Better support for notifications without body or subject
This commit is contained in:
parent
88d553771d
commit
2ef44e766e
@ -364,4 +364,6 @@ public class DeviceSettingsPreferenceConst {
|
||||
|
||||
public static final String PREF_TEMPERATURE_SCALE_CF = "temperature_scale_cf";
|
||||
public static final String PREF_FEMOMETER_MEASUREMENT_MODE = "femometer_measurement_mode";
|
||||
|
||||
public static final String PREF_PREFIX_NOTIFICATION_WITH_APP = "pref_prefix_notification_with_app";
|
||||
}
|
||||
|
@ -549,6 +549,8 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
|
||||
addPreferenceHandlerFor(PREF_TEMPERATURE_SCALE_CF);
|
||||
|
||||
addPreferenceHandlerFor(PREF_PREFIX_NOTIFICATION_WITH_APP);
|
||||
|
||||
addPreferenceHandlerFor("lock");
|
||||
|
||||
String sleepTimeState = prefs.getString(PREF_SLEEP_TIME, PREF_DO_NOT_DISTURB_OFF);
|
||||
|
@ -166,7 +166,8 @@ public class PineTimeJFCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
|
||||
return new int[]{
|
||||
R.xml.devicesettings_transliteration,
|
||||
R.xml.devicesettings_world_clocks
|
||||
R.xml.devicesettings_world_clocks,
|
||||
R.xml.devicesettings_prefix_notification_with_app
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NavigationInfoSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WorldClock;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
|
||||
@ -118,6 +119,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
|
||||
private final BatteryInfoProfile<PineTimeJFSupport> batteryInfoProfile;
|
||||
|
||||
private final int MaxNotificationLength = 100;
|
||||
private final int CutNotificationTitleMinAt = 25;
|
||||
private int firmwareVersionMajor = 0;
|
||||
private int firmwareVersionMinor = 0;
|
||||
private int firmwareVersionPatch = 0;
|
||||
@ -306,15 +308,35 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
|
||||
TransactionBuilder builder = new TransactionBuilder("notification");
|
||||
|
||||
String message;
|
||||
if (notificationSpec.body == null) {
|
||||
notificationSpec.body = "";
|
||||
String source = null;
|
||||
String bodyOrSubject = nodomain.freeyourgadget.gadgetbridge.util.StringUtils.getFirstOf(notificationSpec.body, notificationSpec.subject);
|
||||
String senderOrTitle = nodomain.freeyourgadget.gadgetbridge.util.StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title);
|
||||
if (!nodomain.freeyourgadget.gadgetbridge.util.StringUtils.isNullOrEmpty(notificationSpec.sourceName)) {
|
||||
source = notificationSpec.sourceName;
|
||||
} else if (notificationSpec.type == NotificationType.GENERIC_SMS) {
|
||||
source = getContext().getString(R.string.pref_title_notifications_sms);
|
||||
}
|
||||
|
||||
if (isFirmwareAtLeastVersion0_15()) {
|
||||
String senderOrTitle = nodomain.freeyourgadget.gadgetbridge.util.StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title);
|
||||
message = senderOrTitle + "\0" + notificationSpec.body;
|
||||
if (bodyOrSubject.length() > 0){
|
||||
if (isFirmwareAtLeastVersion0_15()) {
|
||||
if (!GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREF_PREFIX_NOTIFICATION_WITH_APP, true)) {
|
||||
source = null;
|
||||
}
|
||||
int cutLength = Math.max(CutNotificationTitleMinAt, MaxNotificationLength - 3 - bodyOrSubject.length() - (source != null ? source.length() + 2 : 0));
|
||||
if (cutLength < senderOrTitle.length() - 1) {
|
||||
for (; cutLength > 0 && senderOrTitle.charAt(cutLength - 1) == ' '; cutLength--);
|
||||
senderOrTitle = senderOrTitle.substring(0, cutLength) + ">";
|
||||
}
|
||||
message = nodomain.freeyourgadget.gadgetbridge.util.StringUtils.join(": ", source, senderOrTitle) + "\0" + bodyOrSubject;
|
||||
} else {
|
||||
message = bodyOrSubject;
|
||||
}
|
||||
} else {
|
||||
message = notificationSpec.body;
|
||||
if (isFirmwareAtLeastVersion0_15()) {
|
||||
message = (source != null ? source : "") + "\0" + senderOrTitle;
|
||||
} else {
|
||||
message = senderOrTitle;
|
||||
}
|
||||
}
|
||||
|
||||
NewAlert alert = new NewAlert(AlertCategory.CustomHuami, 1, message);
|
||||
|
@ -2397,4 +2397,7 @@
|
||||
<string name="call_rejection_method_ignore">Ignore (silence)</string>
|
||||
<string name="pref_call_rejection_method_title">Call rejection method</string>
|
||||
<string name="pref_call_rejection_method_summary">Which action is taken when an incoming call is rejected from the watch</string>
|
||||
|
||||
<string name="pref_title_prefix_notification_with_app">App name in notification</string>
|
||||
<string name="pref_summary_prefix_notification_with_app">Prefix notification title with name of source application</string>
|
||||
</resources>
|
||||
|
@ -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="pref_prefix_notification_with_app"
|
||||
android:title="@string/pref_title_prefix_notification_with_app"
|
||||
android:summary="@string/pref_summary_prefix_notification_with_app" />
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user