mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 16:30:49 +00:00
Remove a compose recomposition between the started state and the isOnline state that is already cached.
This commit is contained in:
parent
ef90b82396
commit
e0d2a71b47
@ -13,6 +13,14 @@ object OnlineChecker {
|
||||
val checkOnlineCache = LruCache<String, OnlineCheckResult>(100)
|
||||
val fiveMinutes = 1000 * 60 * 5
|
||||
|
||||
fun isOnlineCached(url: String?): Boolean {
|
||||
if (url.isNullOrBlank()) return false
|
||||
if ((checkOnlineCache.get(url)?.timeInMs ?: 0) > System.currentTimeMillis() - fiveMinutes) {
|
||||
return checkOnlineCache.get(url).online
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun isOnline(url: String?): Boolean {
|
||||
checkNotInMainThread()
|
||||
|
||||
|
@ -27,6 +27,7 @@ import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleEventObserver
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.service.NostrHomeDataSource
|
||||
import com.vitorpamplona.amethyst.service.OnlineChecker
|
||||
import com.vitorpamplona.amethyst.ui.navigation.Route
|
||||
import com.vitorpamplona.amethyst.ui.note.UpdateZapAmountDialog
|
||||
import com.vitorpamplona.amethyst.ui.screen.FeedViewModel
|
||||
@ -166,7 +167,11 @@ private fun HomePages(
|
||||
|
||||
@Composable
|
||||
fun CheckIfUrlIsOnline(url: String, accountViewModel: AccountViewModel, whenOnline: @Composable () -> Unit) {
|
||||
var online by remember { mutableStateOf(false) }
|
||||
var online by remember {
|
||||
mutableStateOf(
|
||||
OnlineChecker.isOnlineCached(url)
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(key1 = url) {
|
||||
accountViewModel.checkIsOnline(url) { isOnline ->
|
||||
@ -176,7 +181,10 @@ fun CheckIfUrlIsOnline(url: String, accountViewModel: AccountViewModel, whenOnli
|
||||
}
|
||||
}
|
||||
|
||||
Crossfade(targetState = online) {
|
||||
Crossfade(
|
||||
targetState = online,
|
||||
label = "CheckIfUrlIsOnline"
|
||||
) {
|
||||
if (it) {
|
||||
whenOnline()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user