mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 12:56:49 +01:00
emoji: do a lazy initialisation
The goal is not to slowdown the startup but also to do this initialisation only when it is needed. Suggested-by: cpfeiffer
This commit is contained in:
parent
efd7195725
commit
22904667b8
@ -53,7 +53,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import io.wax911.emojify.EmojiManager;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBOpenHelper;
|
||||
@ -198,8 +197,6 @@ public class GBApplication extends Application {
|
||||
}
|
||||
startService(new Intent(this, NotificationCollectorMonitorService.class));
|
||||
}
|
||||
|
||||
EmojiManager.initEmojiData(getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -364,7 +364,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
return text;
|
||||
|
||||
if (!mCoordinator.supportsUnicodeEmojis())
|
||||
return EmojiConverter.convertUnicodeEmojiToAscii(text);
|
||||
return EmojiConverter.convertUnicodeEmojiToAscii(text, getApplicationContext());
|
||||
|
||||
return text;
|
||||
}
|
||||
|
@ -17,6 +17,9 @@
|
||||
|
||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import io.wax911.emojify.EmojiManager;
|
||||
import io.wax911.emojify.EmojiUtils;
|
||||
|
||||
public class EmojiConverter {
|
||||
@ -56,6 +59,8 @@ public class EmojiConverter {
|
||||
{"\u2764", "<3"}, // heart
|
||||
};
|
||||
|
||||
private static boolean isInitialised = false;
|
||||
|
||||
private static String convertSimpleEmojiToAscii(String text) {
|
||||
for (String[] emojiMap : simpleEmojiMapping) {
|
||||
text = text.replace(emojiMap[0], emojiMap[1]);
|
||||
@ -63,10 +68,21 @@ public class EmojiConverter {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static String convertUnicodeEmojiToAscii(String text) {
|
||||
|
||||
text = convertSimpleEmojiToAscii(text);
|
||||
private static String convertAdvancedEmojiToAscii(String text, Context context) {
|
||||
// Do a lazy initialisation not to slowdown the startup and when it is needed
|
||||
if (!isInitialised) {
|
||||
EmojiManager.initEmojiData(context);
|
||||
isInitialised = true;
|
||||
}
|
||||
|
||||
return EmojiUtils.shortCodify(text);
|
||||
}
|
||||
|
||||
public static String convertUnicodeEmojiToAscii(String text, Context context) {
|
||||
text = convertSimpleEmojiToAscii(text);
|
||||
|
||||
text = convertAdvancedEmojiToAscii(text, context);
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user