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,26 +158,28 @@ class CollectionFolderViewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun positionOfLetter(letter: Char): Int? =
|
suspend fun positionOfLetter(letter: Char): Int? =
|
||||||
item.value?.let { item ->
|
withContext(Dispatchers.IO) {
|
||||||
val includeItemTypes =
|
item.value?.let { item ->
|
||||||
when (item.data.collectionType) {
|
val includeItemTypes =
|
||||||
CollectionType.MOVIES -> listOf(BaseItemKind.MOVIE)
|
when (item.data.collectionType) {
|
||||||
CollectionType.TVSHOWS -> listOf(BaseItemKind.SERIES)
|
CollectionType.MOVIES -> listOf(BaseItemKind.MOVIE)
|
||||||
CollectionType.HOMEVIDEOS -> listOf(BaseItemKind.VIDEO)
|
CollectionType.TVSHOWS -> listOf(BaseItemKind.SERIES)
|
||||||
|
CollectionType.HOMEVIDEOS -> listOf(BaseItemKind.VIDEO)
|
||||||
|
|
||||||
else -> listOf()
|
else -> listOf()
|
||||||
}
|
}
|
||||||
val request =
|
val request =
|
||||||
GetItemsRequest(
|
GetItemsRequest(
|
||||||
parentId = item.id,
|
parentId = item.id,
|
||||||
includeItemTypes = includeItemTypes,
|
includeItemTypes = includeItemTypes,
|
||||||
nameLessThan = letter.toString(),
|
nameLessThan = letter.toString(),
|
||||||
limit = 0,
|
limit = 0,
|
||||||
enableTotalRecordCount = true,
|
enableTotalRecordCount = true,
|
||||||
recursive = true,
|
recursive = true,
|
||||||
)
|
)
|
||||||
val result by GetItemsRequestHandler.execute(api, request)
|
val result by GetItemsRequestHandler.execute(api, request)
|
||||||
result.totalRecordCount
|
result.totalRecordCount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,17 +64,18 @@ class GenreViewModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun positionOfLetter(letter: Char): Int {
|
suspend fun positionOfLetter(letter: Char): Int =
|
||||||
val request =
|
withContext(Dispatchers.IO) {
|
||||||
GetGenresRequest(
|
val request =
|
||||||
parentId = itemId,
|
GetGenresRequest(
|
||||||
nameLessThan = letter.toString(),
|
parentId = itemId,
|
||||||
limit = 0,
|
nameLessThan = letter.toString(),
|
||||||
enableTotalRecordCount = true,
|
limit = 0,
|
||||||
)
|
enableTotalRecordCount = true,
|
||||||
val result by GetGenresRequestHandler.execute(api, request)
|
)
|
||||||
return result.totalRecordCount
|
val result by GetGenresRequestHandler.execute(api, request)
|
||||||
}
|
return@withContext result.totalRecordCount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
||||||
|
|
@ -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