Fix network on main during letter position lookups (#136)

Maybe fixes #135

Yet another network-on-main exception fix.
This commit is contained in:
damontecres 2025-11-01 19:25:19 -04:00 committed by GitHub
parent b288f0f100
commit 715dc1abda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 31 deletions

View file

@ -158,6 +158,7 @@ class CollectionFolderViewModel
}
suspend fun positionOfLetter(letter: Char): Int? =
withContext(Dispatchers.IO) {
item.value?.let { item ->
val includeItemTypes =
when (item.data.collectionType) {
@ -180,6 +181,7 @@ class CollectionFolderViewModel
result.totalRecordCount
}
}
}
/**
* Shows a collection folder as a grid

View file

@ -64,7 +64,8 @@ class GenreViewModel
}
}
suspend fun positionOfLetter(letter: Char): Int {
suspend fun positionOfLetter(letter: Char): Int =
withContext(Dispatchers.IO) {
val request =
GetGenresRequest(
parentId = itemId,
@ -73,7 +74,7 @@ class GenreViewModel
enableTotalRecordCount = true,
)
val result by GetGenresRequestHandler.execute(api, request)
return result.totalRecordCount
return@withContext result.totalRecordCount
}
}

View file

@ -59,7 +59,9 @@ import com.github.damontecres.wholphin.ui.playback.isForwardButton
import com.github.damontecres.wholphin.ui.playback.isPlayKeyUp
import com.github.damontecres.wholphin.ui.tryRequestFocus
import com.github.damontecres.wholphin.util.ExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber
private const val DEBUG = false
@ -350,7 +352,10 @@ fun CardGrid(
modifier = Modifier.align(Alignment.CenterVertically),
letterClicked = { letter ->
scope.launch(ExceptionHandler()) {
val jumpPosition = letterPosition.invoke(letter)
val jumpPosition =
withContext(Dispatchers.IO) {
letterPosition.invoke(letter)
}
Timber.d("Alphabet jump to $jumpPosition")
if (jumpPosition >= 0) {
gridState.scrollToItem(jumpPosition)