[优化] 优化书籍详情界面

This commit is contained in:
HapeLee
2026-04-18 12:28:45 +08:00
parent a7af2ef752
commit 979632e35c
7 changed files with 20 additions and 22 deletions
@@ -11,6 +11,7 @@ data class BookInfoUiState(
val webFiles: List<BookInfoWebFile> = emptyList(),
val kindLabels: List<String> = emptyList(),
val groupNames: String? = null,
val hasCustomGroup: Boolean = false,
val inBookshelf: Boolean = false,
val bookSource: BookSource? = null,
val isTocLoading: Boolean = true,
@@ -43,6 +43,7 @@ import androidx.compose.material.icons.filled.Share
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.outlined.Book
import androidx.compose.material.icons.outlined.Bookmark
import androidx.compose.material.icons.outlined.BookmarkBorder
import androidx.compose.material.icons.outlined.CollectionsBookmark
import androidx.compose.material.icons.outlined.FolderZip
import androidx.compose.material.icons.outlined.Image
@@ -264,7 +265,7 @@ private fun BookInfoScreenContent(
.padding(bottom = 24.dp)
) {
BookInfoActions(
book = book,
hasCustomGroup = state.hasCustomGroup,
inBookshelf = state.inBookshelf,
onShelfClick = { onIntent(BookInfoIntent.ShelfClick) },
onTocClick = { onIntent(BookInfoIntent.TocClick) },
@@ -735,7 +736,7 @@ private fun BookInfoHeader(
@Composable
private fun BookInfoActions(
book: Book,
hasCustomGroup: Boolean,
inBookshelf: Boolean,
onShelfClick: () -> Unit,
onTocClick: () -> Unit,
@@ -791,7 +792,7 @@ private fun BookInfoActions(
)
BookInfoActionCard(
modifier = Modifier.weight(1f),
icon = if (book.group > 0) Icons.Default.Bookmark else Icons.Outlined.Bookmark,
icon = if (hasCustomGroup) Icons.Default.Bookmark else Icons.Outlined.BookmarkBorder,
label = stringResource(R.string.change_group),
onClick = onGroupClick
)
@@ -138,7 +138,7 @@ fun GroupSelectSheet(
) {
Column(modifier = Modifier.fillMaxWidth()) {
LazyColumn(
modifier = Modifier.heightIn(max = 600.dp),
modifier = Modifier.heightIn(max = 560.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
items(groups, key = { it.groupId }) { group ->
@@ -70,6 +70,7 @@ class BookInfoViewModel(
private var currentWebFiles: List<BookInfoWebFile> = emptyList()
private var currentKindLabels: List<String> = emptyList()
private var currentGroupNames: String? = null
private var currentHasCustomGroup = false
private var chapterChanged = false
var inBookshelf = false
@@ -602,6 +603,7 @@ class BookInfoViewModel(
currentBook = it
currentChapterList = toc
currentGroupNames = null
currentHasCustomGroup = false
currentKindLabels = emptyList()
syncUiState(isTocLoading = false)
refreshMeta(it)
@@ -616,6 +618,7 @@ class BookInfoViewModel(
currentWebFiles = emptyList()
currentKindLabels = emptyList()
currentGroupNames = null
currentHasCustomGroup = false
syncUiState(isTocLoading = true)
refreshMeta(book)
upCoverByRule(book)
@@ -668,11 +671,16 @@ class BookInfoViewModel(
kinds.add(ConvertUtils.formatFileSize(size))
}
}
val userGroupIds = appDb.bookGroupDao.idsSum
val groupAnd = userGroupIds and book.group
val hasCustomGroup = book.group > 0L && groupAnd != 0L
val groupNames = appDb.bookGroupDao.getGroupNames(book.group).joinToString(",")
kinds.toList() to groupNames.ifBlank { null }
val normalizedGroupNames = groupNames.ifBlank { null }
Triple(kinds.toList(), normalizedGroupNames, hasCustomGroup)
}.onSuccess {
currentKindLabels = it.first
currentGroupNames = it.second
currentHasCustomGroup = it.third
syncUiState()
}
}
@@ -803,6 +811,7 @@ class BookInfoViewModel(
currentBook?.let { book ->
book.group = groupId
currentGroupNames = null
currentHasCustomGroup = false
refreshMeta(book)
if (inBookshelf) {
saveBook(book)
@@ -1100,6 +1109,7 @@ class BookInfoViewModel(
webFiles = currentWebFiles,
kindLabels = currentKindLabels,
groupNames = currentGroupNames,
hasCustomGroup = currentHasCustomGroup,
inBookshelf = inBookshelf,
bookSource = bookSource,
isTocLoading = isTocLoading,