From 05fc1d7b4f31cd7a0413f102d87c3a9345501ca9 Mon Sep 17 00:00:00 2001 From: imkunet Date: Tue, 20 Feb 2024 02:43:16 -0500 Subject: [PATCH] Impose note editor length limit --- .../manga/components/MangaNotesTextArea.kt | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaNotesTextArea.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaNotesTextArea.kt index 86245f2fa..7737f08ac 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaNotesTextArea.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaNotesTextArea.kt @@ -1,8 +1,12 @@ package eu.kanade.presentation.manga.components +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect @@ -11,12 +15,15 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.text.TextRange import androidx.compose.ui.text.input.TextFieldValue import eu.kanade.tachiyomi.ui.manga.notes.MangaNotesScreenState +private const val MAX_LENGTH = 10_000 + @Composable fun MangaNotesTextArea( state: MangaNotesScreenState.Success, @@ -34,10 +41,28 @@ fun MangaNotesTextArea( ) { OutlinedTextField( value = text, - onValueChange = { text = it }, + onValueChange = { if (it.text.length <= MAX_LENGTH) text = it }, modifier = Modifier .fillMaxSize() .focusRequester(focusRequester), + supportingText = { + val displayWarning = text.text.length > MAX_LENGTH / 10 * 9 + if (!displayWarning) { + Text( + text = "0", + modifier = Modifier.alpha(0f), + ) + } + AnimatedVisibility( + displayWarning, + enter = fadeIn(), + exit = fadeOut(), + ) { + Text( + text = "${text.text.length} / $MAX_LENGTH", + ) + } + }, ) }