mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Fix network on main during letter position lookups (#136)
Maybe fixes #135 Yet another network-on-main exception fix.
This commit is contained in:
parent
b288f0f100
commit
715dc1abda
3 changed files with 39 additions and 31 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue