feat: migrate remaining IMessageField implementors to TextFieldState

Completes the TextFieldState migration for ShortNotePostViewModel,
LongFormPostViewModel, and their associated post screens (GeoHash,
Hashtag, ShortNote, LongForm).

https://claude.ai/code/session_01FDGf1Zi1pVvzFi3JY5agnJ
This commit is contained in:
Claude
2026-03-28 19:11:09 +00:00
parent 1d208edd33
commit f997586e4b
6 changed files with 18 additions and 13 deletions
@@ -62,8 +62,9 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.commons.model.EmptyTagList import com.vitorpamplona.amethyst.commons.model.EmptyTagList
import com.vitorpamplona.amethyst.ui.actions.StrippingFailureDialog import com.vitorpamplona.amethyst.ui.actions.StrippingFailureDialog
import com.vitorpamplona.amethyst.ui.actions.UrlUserTagTransformation import com.vitorpamplona.amethyst.ui.actions.UrlUserTagOutputTransformation
import com.vitorpamplona.amethyst.ui.actions.uploads.SelectFromFiles import com.vitorpamplona.amethyst.ui.actions.uploads.SelectFromFiles
import com.vitorpamplona.amethyst.ui.components.ThinPaddingTextField
import com.vitorpamplona.amethyst.ui.actions.uploads.SelectFromGallery import com.vitorpamplona.amethyst.ui.actions.uploads.SelectFromGallery
import com.vitorpamplona.amethyst.ui.actions.uploads.SelectSingleFromGallery import com.vitorpamplona.amethyst.ui.actions.uploads.SelectSingleFromGallery
import com.vitorpamplona.amethyst.ui.actions.uploads.TakePictureButton import com.vitorpamplona.amethyst.ui.actions.uploads.TakePictureButton
@@ -293,7 +294,7 @@ private fun MarkdownPostScreenBody(
.padding(Size10dp), .padding(Size10dp),
) { ) {
RenderContentAsMarkdown( RenderContentAsMarkdown(
content = postViewModel.message.text, content = postViewModel.message.text.toString(),
tags = EmptyTagList, tags = EmptyTagList,
canPreview = true, canPreview = true,
quotesLeft = 1, quotesLeft = 1,
@@ -304,9 +305,9 @@ private fun MarkdownPostScreenBody(
} }
} else { } else {
// Markdown editor // Markdown editor
OutlinedTextField( ThinPaddingTextField(
value = postViewModel.message, state = postViewModel.message,
onValueChange = postViewModel::updateMessage, onTextChanged = postViewModel::onMessageChanged,
modifier = modifier =
Modifier Modifier
.fillMaxWidth() .fillMaxWidth()
@@ -328,7 +329,7 @@ private fun MarkdownPostScreenBody(
focusedBorderColor = Color.Transparent, focusedBorderColor = Color.Transparent,
unfocusedBorderColor = Color.Transparent, unfocusedBorderColor = Color.Transparent,
), ),
visualTransformation = UrlUserTagTransformation(MaterialTheme.colorScheme.primary), outputTransformation = UrlUserTagOutputTransformation(MaterialTheme.colorScheme.primary),
keyboardOptions = keyboardOptions =
KeyboardOptions.Default.copy( KeyboardOptions.Default.copy(
capitalization = KeyboardCapitalization.Sentences, capitalization = KeyboardCapitalization.Sentences,
@@ -700,7 +700,7 @@ class LongFormPostViewModel :
override fun updateZapFromText() { override fun updateZapFromText() {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
val tagger = val tagger =
NewMessageTagger(message.text, emptyList(), emptyList(), accountViewModel) NewMessageTagger(message.text.toString(), emptyList(), emptyList(), accountViewModel)
tagger.run() tagger.run()
tagger.pTags?.forEach { taggedUser -> tagger.pTags?.forEach { taggedUser ->
if (!forwardZapTo.value.items.any { it.key == taggedUser }) { if (!forwardZapTo.value.items.any { it.key == taggedUser }) {
@@ -23,7 +23,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.geohash
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import com.vitorpamplona.amethyst.ui.actions.uploads.SelectedMedia import com.vitorpamplona.amethyst.ui.actions.uploads.SelectedMedia
@@ -67,7 +67,8 @@ fun GeoHashPostScreen(
postViewModel.quote(it) postViewModel.quote(it)
} }
message?.ifBlank { null }?.let { message?.ifBlank { null }?.let {
postViewModel.updateMessage(TextFieldValue(it)) postViewModel.message.setTextAndPlaceCursorAtEnd(it)
postViewModel.onMessageChanged()
} }
attachment?.ifBlank { null }?.toUri()?.let { attachment?.ifBlank { null }?.toUri()?.let {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
@@ -23,7 +23,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.hashtag
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import com.vitorpamplona.amethyst.ui.actions.uploads.SelectedMedia import com.vitorpamplona.amethyst.ui.actions.uploads.SelectedMedia
@@ -67,7 +67,8 @@ fun HashtagPostScreen(
postViewModel.quote(it) postViewModel.quote(it)
} }
message?.ifBlank { null }?.let { message?.ifBlank { null }?.let {
postViewModel.updateMessage(TextFieldValue(it)) postViewModel.message.setTextAndPlaceCursorAtEnd(it)
postViewModel.onMessageChanged()
} }
attachment?.ifBlank { null }?.toUri()?.let { attachment?.ifBlank { null }?.toUri()?.let {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
@@ -55,7 +55,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment.Companion.CenterVertically import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.net.toUri import androidx.core.net.toUri
@@ -150,7 +150,8 @@ fun ShortNotePostScreen(
val draft = draftId?.let { accountViewModel.getNoteIfExists(it) } val draft = draftId?.let { accountViewModel.getNoteIfExists(it) }
postViewModel.load(baseReplyTo, quote, fork, version, draft) postViewModel.load(baseReplyTo, quote, fork, version, draft)
message?.ifBlank { null }?.let { message?.ifBlank { null }?.let {
postViewModel.updateMessage(TextFieldValue(it)) postViewModel.message.setTextAndPlaceCursorAtEnd(it)
postViewModel.onMessageChanged()
} }
attachment?.ifBlank { null }?.toUri()?.let { attachment?.ifBlank { null }?.toUri()?.let {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
@@ -30,6 +30,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshots.SnapshotStateMap import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.compose.foundation.text.input.TextFieldState import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
import androidx.compose.ui.text.input.TextFieldValue
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.vitorpamplona.amethyst.Amethyst import com.vitorpamplona.amethyst.Amethyst