fix: 书籍详情页添加标签高亮显示

This commit is contained in:
HapeLee
2026-06-27 02:27:43 +08:00
parent dd2190c091
commit c885306550
3 changed files with 32 additions and 6 deletions
@@ -13,10 +13,17 @@ import kotlinx.collections.immutable.persistentListOf
const val READER_RESULT_DELETED = 100
@Stable
data class HighlightedTag(
val matchedLabels: List<String>,
val title: String?,
)
data class BookInfoUiState(
val book: BookInfoBookUi? = null,
val hasChapters: Boolean = false,
val webFiles: List<BookInfoWebFile> = emptyList(),
val highlightedTags: List<HighlightedTag> = emptyList(),
val kindLabels: List<String> = emptyList(),
val groupNames: String? = null,
val hasCustomGroup: Boolean = false,
@@ -86,6 +86,7 @@ import io.legado.app.ui.widget.components.AppTextField
import io.legado.app.ui.widget.components.alert.AppAlertDialog
import io.legado.app.ui.widget.components.button.series.SmallTonalButton
import io.legado.app.ui.widget.components.card.GlassCard
import io.legado.app.ui.widget.components.card.HighlightTagRow
import io.legado.app.ui.widget.components.card.TextCard
import io.legado.app.ui.widget.components.changeSource.ChangeSourceSheet
import io.legado.app.ui.widget.components.icon.AppIcon
@@ -205,6 +206,7 @@ private fun BookInfoScreenContent(
item {
BookInfoHeader(
book = book,
highlightedTags = state.highlightedTags,
kindLabels = state.kindLabels,
groupNames = state.groupNames,
onCoverClick = { onIntent(BookInfoIntent.CoverClick) },
@@ -644,6 +646,7 @@ private fun BookInfoOverflowMenu(
@Composable
private fun BookInfoHeader(
book: BookInfoBookUi,
highlightedTags: List<HighlightedTag>,
kindLabels: List<String>,
groupNames: String?,
onCoverClick: () -> Unit,
@@ -756,6 +759,9 @@ private fun BookInfoHeader(
)
}
}
if (highlightedTags.isNotEmpty()) {
HighlightTagRow(tags = highlightedTags)
}
if (kindLabels.isNotEmpty() || !groupNames.isNullOrBlank()) {
val kindListState = rememberLazyListState()
LazyRow(
@@ -771,7 +777,7 @@ private fun BookInfoHeader(
text = stringResource(R.string.group_s, it),
textStyle = LegadoTheme.typography.labelLargeEmphasized,
backgroundColor = LegadoTheme.colorScheme.surfaceContainer,
contentColor = LegadoTheme.colorScheme.onSurface,
contentColor = LegadoTheme.colorScheme.onSurfaceVariant,
)
}
}
@@ -783,7 +789,7 @@ private fun BookInfoHeader(
text = label,
textStyle = LegadoTheme.typography.labelLargeEmphasized,
backgroundColor = LegadoTheme.colorScheme.surfaceContainer,
contentColor = LegadoTheme.colorScheme.onSurface,
contentColor = LegadoTheme.colorScheme.onSurfaceVariant,
)
}
}
@@ -38,6 +38,7 @@ import io.legado.app.help.book.isSameNameAuthor
import io.legado.app.help.book.isWebFile
import io.legado.app.help.book.removeType
import io.legado.app.help.book.upKind
import io.legado.app.help.book.parseHighlightedTags
import io.legado.app.help.book.updateTo
import io.legado.app.help.config.LocalConfig
import io.legado.app.help.coroutine.Coroutine
@@ -139,6 +140,7 @@ class BookInfoViewModel(
private var currentChapterList: List<BookChapter> = emptyList()
private var currentWebFiles: List<BookInfoWebFile> = emptyList()
private var currentRelatedBooks: List<RelatedBooksUi> = emptyList()
private var currentHighlightedTags: List<HighlightedTag> = emptyList()
private var currentKindLabels: List<String> = emptyList()
private var currentGroupNames: String? = null
private var currentHasCustomGroup = false
@@ -871,15 +873,25 @@ class BookInfoViewModel(
val normalizedGroupNames = groupNames.ifBlank { null }
appDb.bookDao.update(book)
val finalKinds = book.kind?.splitNotBlank(",", "\n").orEmpty().toList()
Triple(finalKinds, normalizedGroupNames, hasCustomGroup)
val enabledRules = appDb.highlightTagRuleDao.getEnabled()
val (highlighted, regular) = parseHighlightedTags(finalKinds, enabledRules)
HighlightMeta(highlighted, regular, normalizedGroupNames, hasCustomGroup)
}.onSuccess {
currentKindLabels = it.first
currentGroupNames = it.second
currentHasCustomGroup = it.third
currentHighlightedTags = it.highlighted
currentKindLabels = it.regular
currentGroupNames = it.groupNames
currentHasCustomGroup = it.hasCustomGroup
syncUiState()
}
}
private data class HighlightMeta(
val highlighted: List<HighlightedTag>,
val regular: List<String>,
val groupNames: String?,
val hasCustomGroup: Boolean,
)
private fun loadChapter(
book: Book,
runPreUpdateJs: Boolean = true,
@@ -1335,6 +1347,7 @@ class BookInfoViewModel(
hasChapters = currentChapterList.isNotEmpty(),
webFiles = currentWebFiles,
relatedBooks = currentRelatedBooks.toImmutableList(),
highlightedTags = currentHighlightedTags,
kindLabels = currentKindLabels,
groupNames = currentGroupNames,
hasCustomGroup = currentHasCustomGroup,