From 429d41b16861dca38e41c1c58dc7f507b9321ce6 Mon Sep 17 00:00:00 2001 From: HapeLee <1321903405@qq.com> Date: Sun, 30 Nov 2025 15:43:07 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20=E5=BD=93=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E5=8F=91=E7=8E=B0=E9=A1=B5=E6=9C=89=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E4=BD=86=E5=85=A8=E9=83=BD=E8=A2=AB=E8=BF=87=E6=BB=A4=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=8A=A0=E8=BD=BD=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E9=A1=B5=20#399?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/explore/ExploreShowScreen.kt | 85 ++++++++++--------- .../ui/book/explore/ExploreShowViewModel.kt | 24 +++--- 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowScreen.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowScreen.kt index 4332078ef..23a3984d6 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowScreen.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowScreen.kt @@ -64,6 +64,7 @@ import io.legado.app.data.entities.rule.ExploreKind import io.legado.app.model.BookShelfState import io.legado.app.ui.widget.components.AnimatedTextLine import io.legado.app.ui.widget.components.Cover +import io.legado.app.ui.widget.components.EmptyMessageView import org.koin.androidx.compose.koinViewModel @OptIn(ExperimentalMaterial3Api::class) @@ -145,35 +146,35 @@ fun ExploreShowScreen( .fillMaxSize() .padding(paddingValues) ) { - LazyColumn( - state = listState, - contentPadding = PaddingValues(bottom = 16.dp) - ) { - items( - items = books, - key = { it.bookUrl } - ) { book -> - val shelfState = viewModel.getCurrentBookShelfState(book) - ExploreBookItem( - book = book, - shelfState = shelfState, - onClick = { onBookClick(book) }, - modifier = Modifier.animateItem() - ) - } - - item { - LoadMoreFooter( - isLoading = isLoading, - errorMsg = errorMsg, - onRetry = { viewModel.loadMore() } - ) - } - } - if (!isLoading && books.isEmpty() && errorMsg == null) { Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { - Text("暂无书籍", color = Color.Gray) + EmptyMessageView(message = "暂无书籍") + } + } else { + LazyColumn( + state = listState, + contentPadding = PaddingValues(bottom = 16.dp) + ) { + items( + items = books, + key = { it.bookUrl } + ) { book -> + val shelfState = viewModel.getCurrentBookShelfState(book) + ExploreBookItem( + book = book, + shelfState = shelfState, + onClick = { onBookClick(book) }, + modifier = Modifier.animateItem() + ) + } + + item { + LoadMoreFooter( + isLoading = isLoading, + errorMsg = errorMsg, + onRetry = viewModel::loadMore + ) + } } } @@ -181,7 +182,7 @@ fun ExploreShowScreen( derivedStateOf { val totalItems = listState.layoutInfo.totalItemsCount val lastVisibleIndex = listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0 - totalItems > 0 && lastVisibleIndex >= totalItems - 2 + totalItems > 0 && lastVisibleIndex >= totalItems - 9 } } @@ -366,6 +367,7 @@ fun ExploreBookItem( style = MaterialTheme.typography.bodySmall, color = Color.Gray, maxLines = 2, + minLines = 2, overflow = TextOverflow.Ellipsis ) } @@ -442,18 +444,23 @@ fun LoadMoreFooter( .padding(32.dp), contentAlignment = Alignment.Center ) { - if (isLoading) { - LoadingIndicator() - } else if (errorMsg != null) { - Column(horizontalAlignment = Alignment.CenterHorizontally) { - Text(text = "加载失败: $errorMsg", color = Color.Red, style = MaterialTheme.typography.bodySmall) - TextButton(onClick = onRetry) { - Text("重试") + when { + isLoading -> LoadingIndicator() + + errorMsg != null -> { + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Text("加载失败: $errorMsg", color = Color.Red) + TextButton(onClick = onRetry) { Text("重试") } } } - } else { - // 没有在加载且没有错误,可能到底了,或者等待滑动触发 - Spacer(modifier = Modifier.height(1.dp)) + + else -> { + Text( + text = "已经到底了~", + color = Color.Gray, + style = MaterialTheme.typography.bodySmall + ) + } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt index 80710e935..e93f820db 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt @@ -63,19 +63,7 @@ class ExploreShowViewModel( _bookshelf ) { books, filter, bookshelf -> books.filter { item -> - val state = getBookShelfState(item, bookshelf) - when (filter) { - BookFilterState.SHOW_ALL -> true - - BookFilterState.HIDE_IN_SHELF -> - state != BookShelfState.IN_SHELF - - BookFilterState.HIDE_SAME_NAME_AUTHOR -> - state != BookShelfState.SAME_NAME_AUTHOR - - BookFilterState.SHOW_NOT_IN_SHELF_ONLY -> - state == BookShelfState.NOT_IN_SHELF - } + isBookValid(item, filter, bookshelf) } }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList()) @@ -169,6 +157,16 @@ class ExploreShowViewModel( return getBookShelfState(item, _bookshelf.value) } + private fun isBookValid(book: SearchBook, filter: BookFilterState, shelf: Set): Boolean { + val state = getBookShelfState(book, shelf) + return when (filter) { + BookFilterState.SHOW_ALL -> true + BookFilterState.HIDE_IN_SHELF -> state != BookShelfState.IN_SHELF + BookFilterState.HIDE_SAME_NAME_AUTHOR -> state != BookShelfState.SAME_NAME_AUTHOR + BookFilterState.SHOW_NOT_IN_SHELF_ONLY -> state == BookShelfState.NOT_IN_SHELF + } + } + private fun getBookShelfState(item: SearchBook, shelf: Set): BookShelfState { val exactMatch = shelf.any { it.name == item.name && it.author == item.author && it.url == item.bookUrl } if (exactMatch) return BookShelfState.IN_SHELF