Note widget: add placeholder
This commit is contained in:
parent
2a8d4e3445
commit
1ab89fc9b8
@ -3,11 +3,14 @@ package de.mm20.launcher2.ui.component.markdown
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.ProvideTextStyle
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -24,7 +27,6 @@ import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.input.OffsetMapping
|
||||
import androidx.compose.ui.text.input.TransformedText
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import org.intellij.markdown.ast.ASTNode
|
||||
import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor
|
||||
import org.intellij.markdown.parser.MarkdownParser
|
||||
|
||||
@ -33,6 +35,7 @@ fun MarkdownEditor(
|
||||
value: String,
|
||||
onValueChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
placeholder: (@Composable () -> Unit)? = null
|
||||
) {
|
||||
val typography = MaterialTheme.typography
|
||||
val delimiterColor = MaterialTheme.colorScheme.secondary
|
||||
@ -69,16 +72,35 @@ fun MarkdownEditor(
|
||||
)
|
||||
|
||||
} else {
|
||||
MarkdownText(
|
||||
value,
|
||||
modifier = modifier.clickable(
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
if (placeholder != null && value.isBlank()) {
|
||||
Box(
|
||||
modifier = modifier.clickable(
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
) {
|
||||
focused = true
|
||||
},
|
||||
) {
|
||||
focused = true
|
||||
},
|
||||
onTextChange = onValueChange,
|
||||
)
|
||||
ProvideTextStyle(MaterialTheme.typography.bodyMedium) {
|
||||
CompositionLocalProvider(
|
||||
LocalContentColor provides MaterialTheme.colorScheme.secondary
|
||||
) {
|
||||
placeholder()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MarkdownText(
|
||||
value,
|
||||
modifier = modifier.clickable(
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
) {
|
||||
focused = true
|
||||
},
|
||||
onTextChange = onValueChange,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,14 +5,17 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.component.markdown.MarkdownEditor
|
||||
import de.mm20.launcher2.widgets.NotesWidget
|
||||
|
||||
@ -30,5 +33,8 @@ fun NotesWidget(widget: NotesWidget) {
|
||||
value = text,
|
||||
onValueChange = { viewModel.setText(it) },
|
||||
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
||||
placeholder = {
|
||||
Text(stringResource(R.string.notes_widget_placeholder))
|
||||
}
|
||||
)
|
||||
}
|
||||
@ -224,6 +224,7 @@
|
||||
<string name="widget_add_widget">Add widget</string>
|
||||
<!-- Add a third party widget (=a standard Android app widget) -->
|
||||
<string name="widget_add_external">More</string>
|
||||
<string name="notes_widget_placeholder">Write a note…</string>
|
||||
<!-- Indicates to which app a shortcuts belongs. %1$s: the name of the app -->
|
||||
<string name="shortcut_summary">By %1$s</string>
|
||||
<!-- Progress of the installation of another app. %1$s: the formatted percentage of the installation progress -->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user