mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +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? =
|
suspend fun positionOfLetter(letter: Char): Int? =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
item.value?.let { item ->
|
item.value?.let { item ->
|
||||||
val includeItemTypes =
|
val includeItemTypes =
|
||||||
when (item.data.collectionType) {
|
when (item.data.collectionType) {
|
||||||
|
|
@ -180,6 +181,7 @@ class CollectionFolderViewModel
|
||||||
result.totalRecordCount
|
result.totalRecordCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a collection folder as a grid
|
* 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 =
|
val request =
|
||||||
GetGenresRequest(
|
GetGenresRequest(
|
||||||
parentId = itemId,
|
parentId = itemId,
|
||||||
|
|
@ -73,7 +74,7 @@ class GenreViewModel
|
||||||
enableTotalRecordCount = true,
|
enableTotalRecordCount = true,
|
||||||
)
|
)
|
||||||
val result by GetGenresRequestHandler.execute(api, request)
|
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.playback.isPlayKeyUp
|
||||||
import com.github.damontecres.wholphin.ui.tryRequestFocus
|
import com.github.damontecres.wholphin.ui.tryRequestFocus
|
||||||
import com.github.damontecres.wholphin.util.ExceptionHandler
|
import com.github.damontecres.wholphin.util.ExceptionHandler
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
private const val DEBUG = false
|
private const val DEBUG = false
|
||||||
|
|
@ -350,7 +352,10 @@ fun CardGrid(
|
||||||
modifier = Modifier.align(Alignment.CenterVertically),
|
modifier = Modifier.align(Alignment.CenterVertically),
|
||||||
letterClicked = { letter ->
|
letterClicked = { letter ->
|
||||||
scope.launch(ExceptionHandler()) {
|
scope.launch(ExceptionHandler()) {
|
||||||
val jumpPosition = letterPosition.invoke(letter)
|
val jumpPosition =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
letterPosition.invoke(letter)
|
||||||
|
}
|
||||||
Timber.d("Alphabet jump to $jumpPosition")
|
Timber.d("Alphabet jump to $jumpPosition")
|
||||||
if (jumpPosition >= 0) {
|
if (jumpPosition >= 0) {
|
||||||
gridState.scrollToItem(jumpPosition)
|
gridState.scrollToItem(jumpPosition)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue