1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-29 03:55:49 +01:00

Fix emoji transliteration

This commit is contained in:
José Rebelo 2023-07-08 17:13:53 +01:00
parent cc8a1dbdaa
commit 5c78488e93
3 changed files with 25 additions and 21 deletions

View File

@ -71,7 +71,9 @@ public class GBDeviceService implements DeviceService {
EXTRA_MUSIC_ALBUM, EXTRA_MUSIC_ALBUM,
EXTRA_MUSIC_TRACK, EXTRA_MUSIC_TRACK,
EXTRA_CALENDAREVENT_TITLE, EXTRA_CALENDAREVENT_TITLE,
EXTRA_CALENDAREVENT_DESCRIPTION EXTRA_CALENDAREVENT_DESCRIPTION,
EXTRA_CALENDAREVENT_LOCATION,
EXTRA_CALENDAREVENT_CALNAME,
}; };
private static final Logger LOG = LoggerFactory.getLogger(GBDeviceService.class); private static final Logger LOG = LoggerFactory.getLogger(GBDeviceService.class);

View File

@ -730,11 +730,15 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
final Transliterator transliterator = LanguageUtils.getTransliterator(device); final Transliterator transliterator = LanguageUtils.getTransliterator(device);
if (transliterator != null) { for (String extra : GBDeviceService.transliterationExtras) {
for (String extra : GBDeviceService.transliterationExtras) { if (intent.hasExtra(extra)) {
if (intent.hasExtra(extra)) { // Ensure the text is sanitized (eg. emoji converted to ascii) before applying the transliterators
intent.putExtra(extra, transliterator.transliterate(intent.getStringExtra(extra))); // otherwise the emoji are removed before converting them
String sanitizedText = sanitizeNotifText(intent.getStringExtra(extra), device);
if (transliterator != null) {
sanitizedText = transliterator.transliterate(sanitizedText);
} }
intent.putExtra(extra, sanitizedText);
} }
} }
@ -746,10 +750,10 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
int desiredId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); int desiredId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
NotificationSpec notificationSpec = new NotificationSpec(desiredId); NotificationSpec notificationSpec = new NotificationSpec(desiredId);
notificationSpec.phoneNumber = intent.getStringExtra(EXTRA_NOTIFICATION_PHONENUMBER); notificationSpec.phoneNumber = intent.getStringExtra(EXTRA_NOTIFICATION_PHONENUMBER);
notificationSpec.sender = sanitizeNotifText(intent.getStringExtra(EXTRA_NOTIFICATION_SENDER), device); notificationSpec.sender = intent.getStringExtra(EXTRA_NOTIFICATION_SENDER);
notificationSpec.subject = sanitizeNotifText(intent.getStringExtra(EXTRA_NOTIFICATION_SUBJECT), device); notificationSpec.subject = intent.getStringExtra(EXTRA_NOTIFICATION_SUBJECT);
notificationSpec.title = sanitizeNotifText(intent.getStringExtra(EXTRA_NOTIFICATION_TITLE), device); notificationSpec.title = intent.getStringExtra(EXTRA_NOTIFICATION_TITLE);
notificationSpec.body = sanitizeNotifText(intent.getStringExtra(EXTRA_NOTIFICATION_BODY), device); notificationSpec.body = intent.getStringExtra(EXTRA_NOTIFICATION_BODY);
notificationSpec.sourceName = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCENAME); notificationSpec.sourceName = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCENAME);
notificationSpec.type = (NotificationType) intent.getSerializableExtra(EXTRA_NOTIFICATION_TYPE); notificationSpec.type = (NotificationType) intent.getSerializableExtra(EXTRA_NOTIFICATION_TYPE);
notificationSpec.attachedActions = (ArrayList<NotificationSpec.Action>) intent.getSerializableExtra(EXTRA_NOTIFICATION_ACTIONS); notificationSpec.attachedActions = (ArrayList<NotificationSpec.Action>) intent.getSerializableExtra(EXTRA_NOTIFICATION_ACTIONS);
@ -793,10 +797,10 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
calendarEventSpec.timestamp = intent.getIntExtra(EXTRA_CALENDAREVENT_TIMESTAMP, -1); calendarEventSpec.timestamp = intent.getIntExtra(EXTRA_CALENDAREVENT_TIMESTAMP, -1);
calendarEventSpec.durationInSeconds = intent.getIntExtra(EXTRA_CALENDAREVENT_DURATION, -1); calendarEventSpec.durationInSeconds = intent.getIntExtra(EXTRA_CALENDAREVENT_DURATION, -1);
calendarEventSpec.allDay = intent.getBooleanExtra(EXTRA_CALENDAREVENT_ALLDAY, false); calendarEventSpec.allDay = intent.getBooleanExtra(EXTRA_CALENDAREVENT_ALLDAY, false);
calendarEventSpec.title = sanitizeNotifText(intent.getStringExtra(EXTRA_CALENDAREVENT_TITLE), device); calendarEventSpec.title = intent.getStringExtra(EXTRA_CALENDAREVENT_TITLE);
calendarEventSpec.description = sanitizeNotifText(intent.getStringExtra(EXTRA_CALENDAREVENT_DESCRIPTION), device); calendarEventSpec.description = intent.getStringExtra(EXTRA_CALENDAREVENT_DESCRIPTION);
calendarEventSpec.location = sanitizeNotifText(intent.getStringExtra(EXTRA_CALENDAREVENT_LOCATION), device); calendarEventSpec.location = intent.getStringExtra(EXTRA_CALENDAREVENT_LOCATION);
calendarEventSpec.calName = sanitizeNotifText(intent.getStringExtra(EXTRA_CALENDAREVENT_CALNAME), device); calendarEventSpec.calName = intent.getStringExtra(EXTRA_CALENDAREVENT_CALNAME);
calendarEventSpec.color = intent.getIntExtra(EXTRA_CALENDAREVENT_COLOR, 0); calendarEventSpec.color = intent.getIntExtra(EXTRA_CALENDAREVENT_COLOR, 0);
deviceSupport.onAddCalendarEvent(calendarEventSpec); deviceSupport.onAddCalendarEvent(calendarEventSpec);
break; break;
@ -850,7 +854,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
CallSpec callSpec = new CallSpec(); CallSpec callSpec = new CallSpec();
callSpec.command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED); callSpec.command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED);
callSpec.number = intent.getStringExtra(EXTRA_CALL_PHONENUMBER); callSpec.number = intent.getStringExtra(EXTRA_CALL_PHONENUMBER);
callSpec.name = sanitizeNotifText(intent.getStringExtra(EXTRA_CALL_DISPLAYNAME), device); callSpec.name = intent.getStringExtra(EXTRA_CALL_DISPLAYNAME);
callSpec.dndSuppressed = intent.getIntExtra(EXTRA_CALL_DNDSUPPRESSED, 0); callSpec.dndSuppressed = intent.getIntExtra(EXTRA_CALL_DNDSUPPRESSED, 0);
deviceSupport.onSetCallState(callSpec); deviceSupport.onSetCallState(callSpec);
break; break;
@ -868,9 +872,9 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
break; break;
case ACTION_SETMUSICINFO: case ACTION_SETMUSICINFO:
MusicSpec musicSpec = new MusicSpec(); MusicSpec musicSpec = new MusicSpec();
musicSpec.artist = sanitizeNotifText(intent.getStringExtra(EXTRA_MUSIC_ARTIST), device); musicSpec.artist = intent.getStringExtra(EXTRA_MUSIC_ARTIST);
musicSpec.album = sanitizeNotifText(intent.getStringExtra(EXTRA_MUSIC_ALBUM), device); musicSpec.album = intent.getStringExtra(EXTRA_MUSIC_ALBUM);
musicSpec.track = sanitizeNotifText(intent.getStringExtra(EXTRA_MUSIC_TRACK), device); musicSpec.track = intent.getStringExtra(EXTRA_MUSIC_TRACK);
musicSpec.duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0); musicSpec.duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0);
musicSpec.trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0); musicSpec.trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0);
musicSpec.trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 0); musicSpec.trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 0);

View File

@ -25,10 +25,8 @@ import androidx.annotation.Nullable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.text.Normalizer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -38,11 +36,13 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.ArabicTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.ArabicTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.BengaliTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.BengaliTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.CroatianTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.CzechTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.CzechTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.EstonianTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.EstonianTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.ExtendedAsciiTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.ExtendedAsciiTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.FlattenToAsciiTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.FlattenToAsciiTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.FrenchTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.FrenchTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.GeorgianTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.GermanTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.GermanTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.GreekTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.GreekTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.HebrewTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.HebrewTransliterator;
@ -55,8 +55,6 @@ import nodomain.freeyourgadget.gadgetbridge.util.language.impl.RussianTransliter
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.ScandinavianTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.ScandinavianTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.TurkishTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.TurkishTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.UkranianTransliterator; import nodomain.freeyourgadget.gadgetbridge.util.language.impl.UkranianTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.GeorgianTransliterator;
import nodomain.freeyourgadget.gadgetbridge.util.language.impl.CroatianTransliterator;
public class LanguageUtils { public class LanguageUtils {
private static final Logger LOG = LoggerFactory.getLogger(LanguageUtils.class); private static final Logger LOG = LoggerFactory.getLogger(LanguageUtils.class);