From b68855442398a30d5d32cf2d97d2cd8b30ef6db9 Mon Sep 17 00:00:00 2001 From: Evgenii Kozlov Date: Tue, 13 Oct 2020 15:42:55 +0300 Subject: [PATCH] Emoji cross-platform sync issues (#981) --- CHANGELOG.md | 1 + dependencies.gradle | 4 --- library-emojifier/build.gradle | 5 +--- .../anytypeio/anytype/emojifier/Emojifier.kt | 26 +++++++++++++++--- .../anytype/emojifier/EmojiSearchTest.kt | 27 +++++++++++++++++++ library-page-icon-picker-widget/build.gradle | 5 ---- presentation-editor/build.gradle | 5 ---- presentation/build.gradle | 5 ---- 8 files changed, 51 insertions(+), 27 deletions(-) create mode 100644 library-emojifier/src/test/java/com/agileburo/anytype/emojifier/EmojiSearchTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f5b0e5daf..2005fae33b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Fixes & tech 🚒 +* Emoji cross-platform sync issues (#969) * Fix soft input visibility/focusing issues on Android 7 (#966) * Change min sdk to Android 24 (#976) * Cannot set carriage into an empty text block in large documents (#906) diff --git a/dependencies.gradle b/dependencies.gradle index f62cbcc286..b5017b17be 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -181,10 +181,6 @@ ext { roomTesting: "androidx.room:room-testing:$room_version" ] - libraryPageIconPicker = [ - emojiJava: "com.vdurmont:emoji-java:5.1.1" - ] - analytics = [ amplitude: "com.amplitude:android-sdk:$amplitude_version" ] diff --git a/library-emojifier/build.gradle b/library-emojifier/build.gradle index 4a5d4a8413..8d2b0e31b9 100644 --- a/library-emojifier/build.gradle +++ b/library-emojifier/build.gradle @@ -43,15 +43,12 @@ dependencies { def appDependencies = rootProject.ext.mainApplication def unitTestDependencies = rootProject.ext.unitTesting - def lib = rootProject.ext.libraryPageIconPicker implementation project(':domain') implementation project(':core-utils') - implementation(lib.emojiJava) { - exclude group: 'org.json', module: 'json' - } implementation appDependencies.gson implementation appDependencies.coroutines testImplementation unitTestDependencies.junit + testImplementation unitTestDependencies.kotlinTest } \ No newline at end of file diff --git a/library-emojifier/src/main/java/com/anytypeio/anytype/emojifier/Emojifier.kt b/library-emojifier/src/main/java/com/anytypeio/anytype/emojifier/Emojifier.kt index 29ec341188..f5be074a66 100644 --- a/library-emojifier/src/main/java/com/anytypeio/anytype/emojifier/Emojifier.kt +++ b/library-emojifier/src/main/java/com/anytypeio/anytype/emojifier/Emojifier.kt @@ -4,6 +4,9 @@ import com.anytypeio.anytype.emojifier.data.Emoji object Emojifier { + private const val EMOJI_SEPARATOR_INT = 65039 + private const val SEPARATOR = EMOJI_SEPARATOR_INT.toChar() + /** * cache for [search] results. */ @@ -15,7 +18,22 @@ object Emojifier { */ @Throws(IllegalStateException::class) fun uri(unicode: String): String { - val (page, index) = search(unicode) + var result = search(unicode) + + if (result == null) { + if (unicode.last() == SEPARATOR) { + val sb = StringBuilder() + unicode.forEachIndexed { index, char -> + if (index < unicode.length.dec()) sb.append(char) + } + result = search(sb.toString()) + } + } + + checkNotNull(result) { "Could not find emoji for: $unicode" } + + val (page, index) = result + return uri(page, index) } @@ -32,8 +50,7 @@ object Emojifier { * @param unicode emoji unicode * @return a pair constisting of emoji's page and emoji's index for this [unicode] */ - @Throws(IllegalStateException::class) - private fun search(unicode: String): Pair { + private fun search(unicode: String): Pair? { val cached = cache[unicode] if (cached != null) return cached @@ -49,10 +66,11 @@ object Emojifier { return@forEachIndexed } } - return result ?: throw IllegalStateException("Result not found for: $unicode") + return result } object Config { const val EMOJI_FILE = "emoji.json" } + } \ No newline at end of file diff --git a/library-emojifier/src/test/java/com/agileburo/anytype/emojifier/EmojiSearchTest.kt b/library-emojifier/src/test/java/com/agileburo/anytype/emojifier/EmojiSearchTest.kt new file mode 100644 index 0000000000..e2fe8c6234 --- /dev/null +++ b/library-emojifier/src/test/java/com/agileburo/anytype/emojifier/EmojiSearchTest.kt @@ -0,0 +1,27 @@ +package com.agileburo.anytype.emojifier + +import com.anytypeio.anytype.emojifier.Emojifier +import org.junit.Test + +class EmojiSearchTest { + + @Test + fun `should find uri for all emojis`() { + + val emojis = listOf( + "⛰️", "\uD83C\uDFD8️", + "⛰️", "⚔️", "\uD83C\uDFDB️", + "▶️", "\uD83D\uDDE3️", "⛩️", + "\uD83D\uDC87\u200D♂️", "⚙️", + "☺️", "\uD83D\uDDC4️", "\uD83D\uDDD2️", + "\uD83D\uDD78️", "\uD83D\uDE47\u200D♀️", + "\uD83C\uDF21️", "\uD83D\uDDB2️", + "✴️", "⌨️", "\uD83E\uDDD1\uD83C\uDFFD\u200D✈️", + "\uD83D\uDC69\uD83C\uDFFC\u200D⚕️", "☂️" + ) + + emojis.forEach { unicode -> + Emojifier.uri(unicode) + } + } +} \ No newline at end of file diff --git a/library-page-icon-picker-widget/build.gradle b/library-page-icon-picker-widget/build.gradle index 60dbb3ae24..1280669f8d 100644 --- a/library-page-icon-picker-widget/build.gradle +++ b/library-page-icon-picker-widget/build.gradle @@ -42,11 +42,6 @@ android { dependencies { def applicationDependencies = rootProject.ext.mainApplication def unitTestDependencies = rootProject.ext.unitTesting - def lib = rootProject.ext.libraryPageIconPicker - - implementation(lib.emojiJava) { - exclude group: 'org.json', module: 'json' - } implementation project(':core-utils') implementation project(':core-ui') diff --git a/presentation-editor/build.gradle b/presentation-editor/build.gradle index 08327faf7c..46853e738a 100644 --- a/presentation-editor/build.gradle +++ b/presentation-editor/build.gradle @@ -30,11 +30,6 @@ dependencies { def applicationDependencies = rootProject.ext.mainApplication def unitTestDependencies = rootProject.ext.unitTesting - def lib = rootProject.ext.libraryPageIconPicker - - implementation(lib.emojiJava) { - exclude group: 'org.json', module: 'json' - } implementation applicationDependencies.kotlin implementation applicationDependencies.coroutines diff --git a/presentation/build.gradle b/presentation/build.gradle index 031a29173d..586a1e7fba 100644 --- a/presentation/build.gradle +++ b/presentation/build.gradle @@ -33,11 +33,6 @@ dependencies { def applicationDependencies = rootProject.ext.mainApplication def unitTestDependencies = rootProject.ext.unitTesting def analyticsDependencies = rootProject.ext.analytics - def lib = rootProject.ext.libraryPageIconPicker - - implementation(lib.emojiJava) { - exclude group: 'org.json', module: 'json' - } implementation applicationDependencies.kotlin implementation applicationDependencies.coroutines