1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-1378 App | Tech | Hot fixes for 0.22.2 (#50)

- Make emojifier safe
- Support Collection layout in CollectionViewModel
- Make MDNS component delegate try/catch safe.
This commit is contained in:
Evgenii Kozlov 2023-06-12 12:24:31 +02:00 committed by uburoiubu
parent 8cc6f4dcb3
commit 7018d7dec9
No known key found for this signature in database
GPG key ID: C8FB80E0A595FBB6
6 changed files with 53 additions and 13 deletions

View file

@ -9,6 +9,7 @@ dependencies {
implementation project(':core-utils')
implementation libs.gson
implementation libs.coroutinesAndroid
implementation libs.timber
testImplementation libs.junit
testImplementation libs.kotlinTest

View file

@ -1,6 +1,7 @@
package com.anytypeio.anytype.emojifier
import com.anytypeio.anytype.emojifier.data.Emoji
import timber.log.Timber
object Emojifier {
@ -37,6 +38,28 @@ object Emojifier {
return uri(page, index)
}
fun safeUri(unicode: String): String {
try {
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)
} catch (e: Exception) {
return Config.EMPTY_URI.also {
Timber.e(e, "Error while searching for uri")
}
}
}
/**
* @param page emoji's page (emoji category)
* @param index emoji's index on the [page]
@ -71,6 +94,7 @@ object Emojifier {
object Config {
const val EMOJI_FILE = "emoji.json"
const val EMPTY_URI = ""
}
}