Use proper category when getting random item

Fixes #8700

(cherry picked from commit ed5e013874ad5bff00a5544e7f8b62c8ca7b1764)
This commit is contained in:
arkon 2022-12-08 09:01:37 -05:00 committed by Jobobby04
parent 16879e02e8
commit e53a5cf429
2 changed files with 8 additions and 9 deletions

View File

@ -140,8 +140,7 @@ class LibraryScreenModel(
// SY <-- // SY <--
) : StateScreenModel<LibraryScreenModel.State>(State()) { ) : StateScreenModel<LibraryScreenModel.State>(State()) {
// This is active category INDEX NUMBER var activeCategoryIndex: Int by libraryPreferences.lastUsedCategory().asState(coroutineScope)
var activeCategory: Int by libraryPreferences.lastUsedCategory().asState(coroutineScope)
val isDownloadOnly: Boolean by preferences.downloadedOnly().asState(coroutineScope) val isDownloadOnly: Boolean by preferences.downloadedOnly().asState(coroutineScope)
val isIncognitoMode: Boolean by preferences.incognitoMode().asState(coroutineScope) val isIncognitoMode: Boolean by preferences.incognitoMode().asState(coroutineScope)
@ -860,7 +859,7 @@ class LibraryScreenModel(
suspend fun getRandomLibraryItemForCurrentCategory(): LibraryItem? { suspend fun getRandomLibraryItemForCurrentCategory(): LibraryItem? {
return withIOContext { return withIOContext {
state.value state.value
.getLibraryItemsByCategoryId(activeCategory.toLong()) .getLibraryItemsByCategoryId(state.value.categories[activeCategoryIndex].id)
?.randomOrNull() ?.randomOrNull()
} }
} }

View File

@ -120,7 +120,7 @@ object LibraryTab : Tab {
started started
} }
val onClickFilter: () -> Unit = { val onClickFilter: () -> Unit = {
scope.launch { sendSettingsSheetIntent(state.categories[screenModel.activeCategory]) } scope.launch { sendSettingsSheetIntent(state.categories[screenModel.activeCategoryIndex]) }
} }
Scaffold( Scaffold(
@ -128,7 +128,7 @@ object LibraryTab : Tab {
val title = state.getToolbarTitle( val title = state.getToolbarTitle(
defaultTitle = stringResource(R.string.label_library), defaultTitle = stringResource(R.string.label_library),
defaultCategoryTitle = stringResource(R.string.label_default), defaultCategoryTitle = stringResource(R.string.label_default),
page = screenModel.activeCategory, page = screenModel.activeCategoryIndex,
) )
val tabVisible = state.showCategoryTabs && state.categories.size > 1 val tabVisible = state.showCategoryTabs && state.categories.size > 1
LibraryToolbar( LibraryToolbar(
@ -138,8 +138,8 @@ object LibraryTab : Tab {
incognitoMode = !tabVisible && screenModel.isIncognitoMode, incognitoMode = !tabVisible && screenModel.isIncognitoMode,
downloadedOnlyMode = !tabVisible && screenModel.isDownloadOnly, downloadedOnlyMode = !tabVisible && screenModel.isDownloadOnly,
onClickUnselectAll = screenModel::clearSelection, onClickUnselectAll = screenModel::clearSelection,
onClickSelectAll = { screenModel.selectAll(screenModel.activeCategory) }, onClickSelectAll = { screenModel.selectAll(screenModel.activeCategoryIndex) },
onClickInvertSelection = { screenModel.invertSelection(screenModel.activeCategory) }, onClickInvertSelection = { screenModel.invertSelection(screenModel.activeCategoryIndex) },
onClickFilter = onClickFilter, onClickFilter = onClickFilter,
onClickRefresh = { onClickRefresh(null) }, onClickRefresh = { onClickRefresh(null) },
onClickOpenRandomManga = { onClickOpenRandomManga = {
@ -214,9 +214,9 @@ object LibraryTab : Tab {
searchQuery = state.searchQuery, searchQuery = state.searchQuery,
selection = state.selection, selection = state.selection,
contentPadding = contentPadding, contentPadding = contentPadding,
currentPage = { screenModel.activeCategory }, currentPage = { screenModel.activeCategoryIndex },
showPageTabs = state.showCategoryTabs || !state.searchQuery.isNullOrEmpty(), showPageTabs = state.showCategoryTabs || !state.searchQuery.isNullOrEmpty(),
onChangeCurrentPage = { screenModel.activeCategory = it }, onChangeCurrentPage = { screenModel.activeCategoryIndex = it },
onMangaClicked = { navigator.push(MangaScreen(it)) }, onMangaClicked = { navigator.push(MangaScreen(it)) },
onContinueReadingClicked = { it: LibraryManga -> onContinueReadingClicked = { it: LibraryManga ->
scope.launchIO { scope.launchIO {