From 0c856438fa86296ecc70f8422740d64f18a9b716 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Tue, 28 Jun 2022 19:12:15 +0700 Subject: [PATCH] MangaInfoHeader: Add description placeholder (#7398) To always show summary view for expanding tags --- .../manga/components/MangaInfoHeader.kt | 38 ++++++++++--------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt index e8b122ec43..01aa0559fd 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt @@ -82,6 +82,8 @@ import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.util.system.copyToClipboard import kotlin.math.roundToInt +private val whitespaceLineRegex = Regex("[\\r\\n]{2,}", setOf(RegexOption.MULTILINE)) + @Composable fun MangaInfoHeader( modifier: Modifier = Modifier, @@ -205,25 +207,25 @@ fun MangaInfoHeader( val (expanded, onExpanded) = rememberSaveable { mutableStateOf(fromSource || windowWidthSizeClass != WindowWidthSizeClass.Compact) } - if (!description.isNullOrBlank()) { - val trimmedDescription = remember(description) { - description - .replace(Regex(" +\$", setOf(RegexOption.MULTILINE)), "") - .replace(Regex("[\\r\\n]{2,}", setOf(RegexOption.MULTILINE)), "\n") - } - MangaSummary( - expandedDescription = description, - shrunkDescription = trimmedDescription, - expanded = expanded, - modifier = Modifier - .padding(top = 8.dp) - .padding(horizontal = 16.dp) - .clickableNoIndication( - onLongClick = { context.copyToClipboard(description, description) }, - onClick = { onExpanded(!expanded) }, - ), - ) + val desc = + description.takeIf { !it.isNullOrBlank() } ?: stringResource(id = R.string.description_placeholder) + val trimmedDescription = remember(desc) { + desc + .replace(whitespaceLineRegex, "\n") + .trimEnd() } + MangaSummary( + expandedDescription = desc, + shrunkDescription = trimmedDescription, + expanded = expanded, + modifier = Modifier + .padding(top = 8.dp) + .padding(horizontal = 16.dp) + .clickableNoIndication( + onLongClick = { context.copyToClipboard(desc, desc) }, + onClick = { onExpanded(!expanded) }, + ), + ) val tags = tagsProvider() if (!tags.isNullOrEmpty()) { Box( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e335b7aaeb..2a78bf87f0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -603,6 +603,7 @@ Failed to copy to clipboard Source not installed: %1$s Add manga to library? + No description Chapter %1$s