Reduce char limit, switch encoding

This commit is contained in:
imkunet 2024-09-20 16:17:48 -04:00
parent 2159eb37a0
commit 1b39810397
No known key found for this signature in database
GPG key ID: 32E0ECFB90A68C42
2 changed files with 31 additions and 21 deletions

View file

@ -14,7 +14,7 @@ fun MangaNotesDisplay(
content: String, content: String,
modifier: Modifier, modifier: Modifier,
) { ) {
val richTextState = rememberRichTextState().setHtml(html = content) val richTextState = rememberRichTextState().setMarkdown(markdown = content)
richTextState.config.linkColor = MaterialTheme.colorScheme.primary richTextState.config.linkColor = MaterialTheme.colorScheme.primary
richTextState.config.listIndent = 15 richTextState.config.listIndent = 15

View file

@ -19,7 +19,6 @@ import androidx.compose.material.icons.automirrored.outlined.FormatListBulleted
import androidx.compose.material.icons.outlined.FormatBold import androidx.compose.material.icons.outlined.FormatBold
import androidx.compose.material.icons.outlined.FormatItalic import androidx.compose.material.icons.outlined.FormatItalic
import androidx.compose.material.icons.outlined.FormatListNumbered import androidx.compose.material.icons.outlined.FormatListNumbered
import androidx.compose.material.icons.outlined.FormatSize
import androidx.compose.material.icons.outlined.FormatUnderlined import androidx.compose.material.icons.outlined.FormatUnderlined
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
@ -42,13 +41,27 @@ import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.mohamedrejeb.richeditor.model.RichTextState
import com.mohamedrejeb.richeditor.model.rememberRichTextState import com.mohamedrejeb.richeditor.model.rememberRichTextState
import com.mohamedrejeb.richeditor.ui.material3.RichTextEditor import com.mohamedrejeb.richeditor.ui.material3.RichTextEditor
import eu.kanade.tachiyomi.ui.manga.notes.MangaNotesScreenState import eu.kanade.tachiyomi.ui.manga.notes.MangaNotesScreenState
import tachiyomi.i18n.MR import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource import tachiyomi.presentation.core.i18n.stringResource
private const val MAX_LENGTH = 10_000 private const val MAX_LENGTH = 250
private fun RichTextState.render(): String {
var current: String
var mutated = this.toMarkdown().replace("\n<br>\n<br>", "")
do {
current = mutated
mutated = mutated.trim { it.isWhitespace() || it == '\n' }
mutated = mutated.removeSuffix("<br>").removePrefix("<br>")
} while (mutated != current)
return current
}
@Composable @Composable
fun MangaNotesTextArea( fun MangaNotesTextArea(
@ -61,19 +74,29 @@ fun MangaNotesTextArea(
richTextState.config.listIndent = 15 richTextState.config.listIndent = 15
val focusRequester = remember { FocusRequester() } val focusRequester = remember { FocusRequester() }
val largeFontSize = MaterialTheme.typography.headlineMedium.fontSize
Column( Column(
modifier = modifier modifier = modifier
.fillMaxSize(), .fillMaxSize(),
) { ) {
RichTextEditor( RichTextEditor(
state = richTextState, state = richTextState,
textStyle = MaterialTheme.typography.bodyMedium, textStyle = MaterialTheme.typography.bodyLarge,
maxLength = MAX_LENGTH, maxLength = MAX_LENGTH,
placeholder = { placeholder = {
Text(text = stringResource(MR.strings.notes_placeholder)) Text(text = stringResource(MR.strings.notes_placeholder))
}, },
supportingText = {
Text(
text = (MAX_LENGTH - richTextState.render().length).toString(),
color = if (richTextState.render().length >
MAX_LENGTH / 10 * 9
) {
MaterialTheme.colorScheme.error
} else {
Color.Unspecified
},
)
},
modifier = Modifier modifier = Modifier
.weight(1f) .weight(1f)
.fillMaxWidth() .fillMaxWidth()
@ -132,31 +155,18 @@ fun MangaNotesTextArea(
icon = Icons.Outlined.FormatListNumbered, icon = Icons.Outlined.FormatListNumbered,
) )
} }
item {
VerticalDivider(
modifier = Modifier
.height(24.dp),
)
}
item {
MangaNotesTextAreaButton(
onClick = { richTextState.toggleSpanStyle(SpanStyle(fontSize = largeFontSize)) },
isSelected = richTextState.currentSpanStyle.fontSize == largeFontSize,
icon = Icons.Outlined.FormatSize,
)
}
} }
} }
} }
LaunchedEffect(focusRequester) { LaunchedEffect(focusRequester) {
state.notes?.let { richTextState.setHtml(it) } state.notes?.let { richTextState.setMarkdown(it) }
focusRequester.requestFocus() focusRequester.requestFocus()
} }
DisposableEffect(Unit) { DisposableEffect(Unit) {
onDispose { onDispose {
onSave(richTextState.toHtml()) onSave(richTextState.render())
} }
} }
} }