diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt index af8d9779d..02f12ecd3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt @@ -87,8 +87,7 @@ class LibraryScreenModel( private val trackManager: TrackManager = Injekt.get(), ) : StateScreenModel(State()) { - // This is active category INDEX NUMBER - var activeCategory: Int by libraryPreferences.lastUsedCategory().asState(coroutineScope) + var activeCategoryIndex: Int by libraryPreferences.lastUsedCategory().asState(coroutineScope) val isDownloadOnly: Boolean by preferences.downloadedOnly().asState(coroutineScope) val isIncognitoMode: Boolean by preferences.incognitoMode().asState(coroutineScope) @@ -588,7 +587,7 @@ class LibraryScreenModel( suspend fun getRandomLibraryItemForCurrentCategory(): LibraryItem? { return withIOContext { state.value - .getLibraryItemsByCategoryId(activeCategory.toLong()) + .getLibraryItemsByCategoryId(state.value.categories[activeCategoryIndex].id) ?.randomOrNull() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt index 123895cee..78e38915a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryTab.kt @@ -97,7 +97,7 @@ object LibraryTab : Tab { started } val onClickFilter: () -> Unit = { - scope.launch { sendSettingsSheetIntent(state.categories[screenModel.activeCategory]) } + scope.launch { sendSettingsSheetIntent(state.categories[screenModel.activeCategoryIndex]) } } Scaffold( @@ -105,7 +105,7 @@ object LibraryTab : Tab { val title = state.getToolbarTitle( defaultTitle = stringResource(R.string.label_library), defaultCategoryTitle = stringResource(R.string.label_default), - page = screenModel.activeCategory, + page = screenModel.activeCategoryIndex, ) val tabVisible = state.showCategoryTabs && state.categories.size > 1 LibraryToolbar( @@ -115,8 +115,8 @@ object LibraryTab : Tab { incognitoMode = !tabVisible && screenModel.isIncognitoMode, downloadedOnlyMode = !tabVisible && screenModel.isDownloadOnly, onClickUnselectAll = screenModel::clearSelection, - onClickSelectAll = { screenModel.selectAll(screenModel.activeCategory) }, - onClickInvertSelection = { screenModel.invertSelection(screenModel.activeCategory) }, + onClickSelectAll = { screenModel.selectAll(screenModel.activeCategoryIndex) }, + onClickInvertSelection = { screenModel.invertSelection(screenModel.activeCategoryIndex) }, onClickFilter = onClickFilter, onClickRefresh = { onClickRefresh(null) }, onClickOpenRandomManga = { @@ -169,9 +169,9 @@ object LibraryTab : Tab { searchQuery = state.searchQuery, selection = state.selection, contentPadding = contentPadding, - currentPage = { screenModel.activeCategory }, + currentPage = { screenModel.activeCategoryIndex }, showPageTabs = state.showCategoryTabs || !state.searchQuery.isNullOrEmpty(), - onChangeCurrentPage = { screenModel.activeCategory = it }, + onChangeCurrentPage = { screenModel.activeCategoryIndex = it }, onMangaClicked = { navigator.push(MangaScreen(it)) }, onContinueReadingClicked = { it: LibraryManga -> scope.launchIO {