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:
parent
8cc6f4dcb3
commit
7018d7dec9
6 changed files with 53 additions and 13 deletions
|
@ -67,7 +67,7 @@ fun TreeWidgetObjectIcon(
|
|||
}
|
||||
is ObjectIcon.Basic.Emoji -> {
|
||||
UriImage(
|
||||
uri = Emojifier.uri(icon.unicode),
|
||||
uri = Emojifier.safeUri(icon.unicode),
|
||||
modifier = Modifier.padding(start = paddingStart, end = paddingEnd)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ dependencies {
|
|||
implementation project(':core-utils')
|
||||
implementation libs.gson
|
||||
implementation libs.coroutinesAndroid
|
||||
implementation libs.timber
|
||||
|
||||
testImplementation libs.junit
|
||||
testImplementation libs.kotlinTest
|
||||
|
|
|
@ -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 = ""
|
||||
}
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.launch
|
||||
import service.AndroidDiscoveryProxy
|
||||
import service.DiscoveryObserver
|
||||
import timber.log.Timber
|
||||
|
||||
class MDNSDelegate(
|
||||
private val scope: CoroutineScope,
|
||||
|
@ -18,18 +19,26 @@ class MDNSDelegate(
|
|||
private var observer: DiscoveryObserver? = null
|
||||
|
||||
fun start() {
|
||||
isStarted = true
|
||||
scope.launch(dispatcher) {
|
||||
observer?.let { observer ->
|
||||
resolver.start(observer)
|
||||
try {
|
||||
isStarted = true
|
||||
scope.launch(dispatcher) {
|
||||
observer?.let { observer ->
|
||||
resolver.start(observer)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Error while starting MDNS delegate")
|
||||
}
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
isStarted = false
|
||||
scope.launch(dispatcher) {
|
||||
resolver.stop()
|
||||
try {
|
||||
isStarted = false
|
||||
scope.launch(dispatcher) {
|
||||
resolver.stop()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Error while stopping MDNS delegate")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,11 +21,19 @@ class NsdDiscoveryListener(
|
|||
private val resolveSemaphore = Semaphore(1)
|
||||
|
||||
fun registerObserver(observer: DiscoveryObserver) {
|
||||
this.observer = observer
|
||||
try {
|
||||
this.observer = observer
|
||||
} catch (e: Exception) {
|
||||
Timber.e("Error while registering observer")
|
||||
}
|
||||
}
|
||||
|
||||
fun unregisterObserver() {
|
||||
this.observer = null
|
||||
try {
|
||||
this.observer = null
|
||||
} catch (e: Exception) {
|
||||
Timber.e("Error while unregistering observer")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDiscoveryStarted(regType: String) {
|
||||
|
@ -34,9 +42,7 @@ class NsdDiscoveryListener(
|
|||
|
||||
override fun onServiceFound(service: NsdServiceInfo) {
|
||||
scope.launch(dispatcher) {
|
||||
|
||||
val observer = observer ?: return@launch
|
||||
|
||||
resolveSemaphore.acquire()
|
||||
nsdManager.resolveService(service, ResolveListener(observer, resolveSemaphore))
|
||||
}
|
||||
|
|
|
@ -347,7 +347,7 @@ class CollectionViewModel(
|
|||
ObjectType.Layout.BOOKMARK -> {
|
||||
commands.emit(Command.LaunchDocument(id = target))
|
||||
}
|
||||
ObjectType.Layout.SET -> {
|
||||
ObjectType.Layout.SET, ObjectType.Layout.COLLECTION -> {
|
||||
commands.emit(Command.LaunchObjectSet(target = target))
|
||||
}
|
||||
else -> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue