Show empty screen when a category is empty (#8690)

* Show empty screen when a category is empty

* Review changes

* Review changes #2

Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
zbue
2022-12-08 22:15:10 +08:00
committed by GitHub
parent ed5e013874
commit 01c6e46a71
8 changed files with 60 additions and 11 deletions

View File

@@ -21,6 +21,7 @@ fun extensionsTab(
): TabContent {
val navigator = LocalNavigator.currentOrThrow
val state by extensionsScreenModel.state.collectAsState()
val searchQuery by extensionsScreenModel.query.collectAsState()
return TabContent(
titleRes = R.string.label_extensions,
@@ -37,6 +38,7 @@ fun extensionsTab(
ExtensionScreen(
state = state,
contentPadding = contentPadding,
searchQuery = searchQuery,
onLongClickItem = { extension ->
when (extension) {
is Extension.Available -> extensionsScreenModel.installExtension(extension)

View File

@@ -742,17 +742,19 @@ class LibraryScreenModel(
val showMangaContinueButton: Boolean = false,
val dialog: Dialog? = null,
) {
val selectionMode = selection.isNotEmpty()
val categories = library.keys.toList()
val libraryCount by lazy {
private val libraryCount by lazy {
library.values
.flatten()
.fastDistinctBy { it.libraryManga.manga.id }
.size
}
val isLibraryEmpty by lazy { libraryCount == 0 }
val selectionMode = selection.isNotEmpty()
val categories = library.keys.toList()
fun getLibraryItemsByCategoryId(categoryId: Long): List<LibraryItem>? {
return library.firstNotNullOfOrNull { (k, v) -> v.takeIf { k.id == categoryId } }
}

View File

@@ -149,7 +149,7 @@ object LibraryTab : Tab {
) { contentPadding ->
when {
state.isLoading -> LoadingScreen(modifier = Modifier.padding(contentPadding))
state.searchQuery.isNullOrEmpty() && !state.hasActiveFilters && state.libraryCount == 0 -> {
state.searchQuery.isNullOrEmpty() && !state.hasActiveFilters && state.isLibraryEmpty -> {
val handler = LocalUriHandler.current
EmptyScreen(
textResource = R.string.information_empty_library,
@@ -170,6 +170,7 @@ object LibraryTab : Tab {
selection = state.selection,
contentPadding = contentPadding,
currentPage = { screenModel.activeCategoryIndex },
hasActiveFilters = state.hasActiveFilters,
showPageTabs = state.showCategoryTabs || !state.searchQuery.isNullOrEmpty(),
onChangeCurrentPage = { screenModel.activeCategoryIndex = it },
onMangaClicked = { navigator.push(MangaScreen(it)) },