fix: 书籍详情页添加标签高亮显示
This commit is contained in:
3 files changed
+32
-6
No files matched your search
@@ -13,10 +13,17 @@ import kotlinx.collections.immutable.persistentListOf
|
|||||||
|
|
||||||
const val READER_RESULT_DELETED = 100
|
const val READER_RESULT_DELETED = 100
|
||||||
|
|
||||||
|
@Stable
|
||||||
|
data class HighlightedTag(
|
||||||
|
val matchedLabels: List<String>,
|
||||||
|
val title: String?,
|
||||||
|
)
|
||||||
|
|
||||||
data class BookInfoUiState(
|
data class BookInfoUiState(
|
||||||
val book: BookInfoBookUi? = null,
|
val book: BookInfoBookUi? = null,
|
||||||
val hasChapters: Boolean = false,
|
val hasChapters: Boolean = false,
|
||||||
val webFiles: List<BookInfoWebFile> = emptyList(),
|
val webFiles: List<BookInfoWebFile> = emptyList(),
|
||||||
|
val highlightedTags: List<HighlightedTag> = emptyList(),
|
||||||
val kindLabels: List<String> = emptyList(),
|
val kindLabels: List<String> = emptyList(),
|
||||||
val groupNames: String? = null,
|
val groupNames: String? = null,
|
||||||
val hasCustomGroup: Boolean = false,
|
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.alert.AppAlertDialog
|
||||||
import io.legado.app.ui.widget.components.button.series.SmallTonalButton
|
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.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.card.TextCard
|
||||||
import io.legado.app.ui.widget.components.changeSource.ChangeSourceSheet
|
import io.legado.app.ui.widget.components.changeSource.ChangeSourceSheet
|
||||||
import io.legado.app.ui.widget.components.icon.AppIcon
|
import io.legado.app.ui.widget.components.icon.AppIcon
|
||||||
@@ -205,6 +206,7 @@ private fun BookInfoScreenContent(
|
|||||||
item {
|
item {
|
||||||
BookInfoHeader(
|
BookInfoHeader(
|
||||||
book = book,
|
book = book,
|
||||||
|
highlightedTags = state.highlightedTags,
|
||||||
kindLabels = state.kindLabels,
|
kindLabels = state.kindLabels,
|
||||||
groupNames = state.groupNames,
|
groupNames = state.groupNames,
|
||||||
onCoverClick = { onIntent(BookInfoIntent.CoverClick) },
|
onCoverClick = { onIntent(BookInfoIntent.CoverClick) },
|
||||||
@@ -644,6 +646,7 @@ private fun BookInfoOverflowMenu(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun BookInfoHeader(
|
private fun BookInfoHeader(
|
||||||
book: BookInfoBookUi,
|
book: BookInfoBookUi,
|
||||||
|
highlightedTags: List<HighlightedTag>,
|
||||||
kindLabels: List<String>,
|
kindLabels: List<String>,
|
||||||
groupNames: String?,
|
groupNames: String?,
|
||||||
onCoverClick: () -> Unit,
|
onCoverClick: () -> Unit,
|
||||||
@@ -756,6 +759,9 @@ private fun BookInfoHeader(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (highlightedTags.isNotEmpty()) {
|
||||||
|
HighlightTagRow(tags = highlightedTags)
|
||||||
|
}
|
||||||
if (kindLabels.isNotEmpty() || !groupNames.isNullOrBlank()) {
|
if (kindLabels.isNotEmpty() || !groupNames.isNullOrBlank()) {
|
||||||
val kindListState = rememberLazyListState()
|
val kindListState = rememberLazyListState()
|
||||||
LazyRow(
|
LazyRow(
|
||||||
@@ -771,7 +777,7 @@ private fun BookInfoHeader(
|
|||||||
text = stringResource(R.string.group_s, it),
|
text = stringResource(R.string.group_s, it),
|
||||||
textStyle = LegadoTheme.typography.labelLargeEmphasized,
|
textStyle = LegadoTheme.typography.labelLargeEmphasized,
|
||||||
backgroundColor = LegadoTheme.colorScheme.surfaceContainer,
|
backgroundColor = LegadoTheme.colorScheme.surfaceContainer,
|
||||||
contentColor = LegadoTheme.colorScheme.onSurface,
|
contentColor = LegadoTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -783,7 +789,7 @@ private fun BookInfoHeader(
|
|||||||
text = label,
|
text = label,
|
||||||
textStyle = LegadoTheme.typography.labelLargeEmphasized,
|
textStyle = LegadoTheme.typography.labelLargeEmphasized,
|
||||||
backgroundColor = LegadoTheme.colorScheme.surfaceContainer,
|
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.isWebFile
|
||||||
import io.legado.app.help.book.removeType
|
import io.legado.app.help.book.removeType
|
||||||
import io.legado.app.help.book.upKind
|
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.book.updateTo
|
||||||
import io.legado.app.help.config.LocalConfig
|
import io.legado.app.help.config.LocalConfig
|
||||||
import io.legado.app.help.coroutine.Coroutine
|
import io.legado.app.help.coroutine.Coroutine
|
||||||
@@ -139,6 +140,7 @@ class BookInfoViewModel(
|
|||||||
private var currentChapterList: List<BookChapter> = emptyList()
|
private var currentChapterList: List<BookChapter> = emptyList()
|
||||||
private var currentWebFiles: List<BookInfoWebFile> = emptyList()
|
private var currentWebFiles: List<BookInfoWebFile> = emptyList()
|
||||||
private var currentRelatedBooks: List<RelatedBooksUi> = emptyList()
|
private var currentRelatedBooks: List<RelatedBooksUi> = emptyList()
|
||||||
|
private var currentHighlightedTags: List<HighlightedTag> = emptyList()
|
||||||
private var currentKindLabels: List<String> = emptyList()
|
private var currentKindLabels: List<String> = emptyList()
|
||||||
private var currentGroupNames: String? = null
|
private var currentGroupNames: String? = null
|
||||||
private var currentHasCustomGroup = false
|
private var currentHasCustomGroup = false
|
||||||
@@ -871,15 +873,25 @@ class BookInfoViewModel(
|
|||||||
val normalizedGroupNames = groupNames.ifBlank { null }
|
val normalizedGroupNames = groupNames.ifBlank { null }
|
||||||
appDb.bookDao.update(book)
|
appDb.bookDao.update(book)
|
||||||
val finalKinds = book.kind?.splitNotBlank(",", "\n").orEmpty().toList()
|
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 {
|
}.onSuccess {
|
||||||
currentKindLabels = it.first
|
currentHighlightedTags = it.highlighted
|
||||||
currentGroupNames = it.second
|
currentKindLabels = it.regular
|
||||||
currentHasCustomGroup = it.third
|
currentGroupNames = it.groupNames
|
||||||
|
currentHasCustomGroup = it.hasCustomGroup
|
||||||
syncUiState()
|
syncUiState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private data class HighlightMeta(
|
||||||
|
val highlighted: List<HighlightedTag>,
|
||||||
|
val regular: List<String>,
|
||||||
|
val groupNames: String?,
|
||||||
|
val hasCustomGroup: Boolean,
|
||||||
|
)
|
||||||
|
|
||||||
private fun loadChapter(
|
private fun loadChapter(
|
||||||
book: Book,
|
book: Book,
|
||||||
runPreUpdateJs: Boolean = true,
|
runPreUpdateJs: Boolean = true,
|
||||||
@@ -1335,6 +1347,7 @@ class BookInfoViewModel(
|
|||||||
hasChapters = currentChapterList.isNotEmpty(),
|
hasChapters = currentChapterList.isNotEmpty(),
|
||||||
webFiles = currentWebFiles,
|
webFiles = currentWebFiles,
|
||||||
relatedBooks = currentRelatedBooks.toImmutableList(),
|
relatedBooks = currentRelatedBooks.toImmutableList(),
|
||||||
|
highlightedTags = currentHighlightedTags,
|
||||||
kindLabels = currentKindLabels,
|
kindLabels = currentKindLabels,
|
||||||
groupNames = currentGroupNames,
|
groupNames = currentGroupNames,
|
||||||
hasCustomGroup = currentHasCustomGroup,
|
hasCustomGroup = currentHasCustomGroup,
|
||||||
|
|||||||
Reference in new issue
Block a user