1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 03:16:51 +01:00

Simplification of transliteration integration

This commit is contained in:
ivanovlev 2017-01-24 21:04:06 +03:00
parent 31ccaf361b
commit 06295abcb6
3 changed files with 40 additions and 28 deletions

View File

@ -180,9 +180,10 @@ public class DebugActivity extends GBActivity {
@Override
public void onClick(View v) {
MusicSpec musicSpec = new MusicSpec();
musicSpec.artist = editContent.getText().toString() + "(artist)";
musicSpec.album = editContent.getText().toString() + "(album)";
musicSpec.track = editContent.getText().toString() + "(track)";
String testString = editContent.getText().toString();
musicSpec.artist = testString + "(artist)";
musicSpec.album = testString + "(album)";
musicSpec.track = testString + "(track)";
musicSpec.duration = 10;
musicSpec.trackCount = 5;
musicSpec.trackNr = 2;

View File

@ -19,10 +19,25 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils;
public class GBDeviceService implements DeviceService {
protected final Context mContext;
private final Class<? extends Service> mServiceClass;
private final String[] transliterationExtras = new String[]{
EXTRA_NOTIFICATION_PHONENUMBER,
EXTRA_NOTIFICATION_SENDER,
EXTRA_NOTIFICATION_SUBJECT,
EXTRA_NOTIFICATION_TITLE,
EXTRA_NOTIFICATION_BODY,
EXTRA_NOTIFICATION_SOURCENAME,
EXTRA_CALL_PHONENUMBER,
EXTRA_MUSIC_ARTIST,
EXTRA_MUSIC_ALBUM,
EXTRA_MUSIC_TRACK,
EXTRA_CALENDAREVENT_TITLE,
EXTRA_CALENDAREVENT_DESCRIPTION
};
public GBDeviceService(Context context) {
mContext = context;
@ -34,6 +49,14 @@ public class GBDeviceService implements DeviceService {
}
protected void invokeService(Intent intent) {
if(LanguageUtils.transliterate()){
for (String extra: transliterationExtras) {
if (intent.hasExtra(extra)){
intent.putExtra(extra, LanguageUtils.transliterate(intent.getStringExtra(extra)));
}
}
}
mContext.startService(intent);
}

View File

@ -51,7 +51,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ADD_CALENDAREVENT;
@ -323,12 +322,12 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
break;
case ACTION_NOTIFICATION: {
NotificationSpec notificationSpec = new NotificationSpec();
notificationSpec.phoneNumber = getStringExtra(intent, EXTRA_NOTIFICATION_PHONENUMBER);
notificationSpec.sender = getStringExtra(intent, EXTRA_NOTIFICATION_SENDER);
notificationSpec.subject = getStringExtra(intent, EXTRA_NOTIFICATION_SUBJECT);
notificationSpec.title = getStringExtra(intent, EXTRA_NOTIFICATION_TITLE);
notificationSpec.body = getStringExtra(intent, EXTRA_NOTIFICATION_BODY);
notificationSpec.sourceName = getStringExtra(intent, EXTRA_NOTIFICATION_SOURCENAME);
notificationSpec.phoneNumber = intent.getStringExtra(EXTRA_NOTIFICATION_PHONENUMBER);
notificationSpec.sender = intent.getStringExtra(EXTRA_NOTIFICATION_SENDER);
notificationSpec.subject = intent.getStringExtra(EXTRA_NOTIFICATION_SUBJECT);
notificationSpec.title = intent.getStringExtra(EXTRA_NOTIFICATION_TITLE);
notificationSpec.body = intent.getStringExtra(EXTRA_NOTIFICATION_BODY);
notificationSpec.sourceName = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCENAME);
notificationSpec.type = (NotificationType) intent.getSerializableExtra(EXTRA_NOTIFICATION_TYPE);
notificationSpec.id = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1);
notificationSpec.flags = intent.getIntExtra(EXTRA_NOTIFICATION_FLAGS, 0);
@ -370,8 +369,8 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
calendarEventSpec.type = intent.getByteExtra(EXTRA_CALENDAREVENT_TYPE, (byte) -1);
calendarEventSpec.timestamp = intent.getIntExtra(EXTRA_CALENDAREVENT_TIMESTAMP, -1);
calendarEventSpec.durationInSeconds = intent.getIntExtra(EXTRA_CALENDAREVENT_DURATION, -1);
calendarEventSpec.title = getStringExtra(intent, EXTRA_CALENDAREVENT_TITLE);
calendarEventSpec.description = getStringExtra(intent, EXTRA_CALENDAREVENT_DESCRIPTION);
calendarEventSpec.title = intent.getStringExtra(EXTRA_CALENDAREVENT_TITLE);
calendarEventSpec.description = intent.getStringExtra(EXTRA_CALENDAREVENT_DESCRIPTION);
mDeviceSupport.onAddCalendarEvent(calendarEventSpec);
break;
}
@ -416,7 +415,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
case ACTION_CALLSTATE:
int command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED);
String phoneNumber = getStringExtra(intent, EXTRA_CALL_PHONENUMBER);
String phoneNumber = intent.getStringExtra(EXTRA_CALL_PHONENUMBER);
String callerName = null;
if (phoneNumber != null) {
callerName = getContactDisplayNameByNumber(phoneNumber);
@ -442,9 +441,9 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
break;
case ACTION_SETMUSICINFO:
MusicSpec musicSpec = new MusicSpec();
musicSpec.artist = getStringExtra(intent, EXTRA_MUSIC_ARTIST);
musicSpec.album = getStringExtra(intent, EXTRA_MUSIC_ALBUM);
musicSpec.track = getStringExtra(intent, EXTRA_MUSIC_TRACK);
musicSpec.artist = intent.getStringExtra(EXTRA_MUSIC_ARTIST);
musicSpec.album = intent.getStringExtra(EXTRA_MUSIC_ALBUM);
musicSpec.track = intent.getStringExtra(EXTRA_MUSIC_TRACK);
musicSpec.duration = intent.getIntExtra(EXTRA_MUSIC_DURATION, 0);
musicSpec.trackCount = intent.getIntExtra(EXTRA_MUSIC_TRACKCOUNT, 0);
musicSpec.trackNr = intent.getIntExtra(EXTRA_MUSIC_TRACKNR, 0);
@ -707,18 +706,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
// ignore, just return name below
}
return LanguageUtils.transliterate()
? LanguageUtils.transliterate(name)
: name;
}
//Standard method with transliteration
private String getStringExtra(Intent intent, String event){
String extra = intent.getStringExtra(event);
return LanguageUtils.transliterate()
? LanguageUtils.transliterate(extra)
: extra;
return name;
}
@Override