mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
Emoji cross-platform sync issues (#981)
This commit is contained in:
parent
86abc25ed5
commit
b688554423
8 changed files with 51 additions and 27 deletions
|
@ -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
|
||||
}
|
|
@ -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<Int, Int> {
|
||||
private fun search(unicode: String): Pair<Int, Int>? {
|
||||
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"
|
||||
}
|
||||
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue