From 54fdb64c40b816edd6254a8353438fd6a29ec0ae Mon Sep 17 00:00:00 2001 From: Ben Martin Date: Tue, 21 Jan 2025 12:50:47 +0000 Subject: [PATCH] feat: Add Sentiment and UI Changes (#14) - Adds a `Sentiment` enum with friendly names and leading icons for `HAPPY`, `NEUTRAL`, and `SAD`. - Replaces the previous `Greeting` class with this new `Sentiment` based approach. - Updates the main UI (`App`) to use `FilterChip` for sentiment selection. - Adds a `TextField` for user comments and a "Submit" button. Closes #1 Reviewed-on: https://git.brmartin.co.uk/bob/mobile-application/pulls/14 Co-authored-by: Ben Martin Co-committed-by: Ben Martin --- .../kotlin/uk/sky/bob/application/App.kt | 62 ++++++++++++++----- .../kotlin/uk/sky/bob/application/Greeting.kt | 9 --- .../uk/sky/bob/application/Sentiment.kt | 7 +++ 3 files changed, 53 insertions(+), 25 deletions(-) delete mode 100644 composeApp/src/commonMain/kotlin/uk/sky/bob/application/Greeting.kt create mode 100644 composeApp/src/commonMain/kotlin/uk/sky/bob/application/Sentiment.kt diff --git a/composeApp/src/commonMain/kotlin/uk/sky/bob/application/App.kt b/composeApp/src/commonMain/kotlin/uk/sky/bob/application/App.kt index ca19bda..89b542e 100644 --- a/composeApp/src/commonMain/kotlin/uk/sky/bob/application/App.kt +++ b/composeApp/src/commonMain/kotlin/uk/sky/bob/application/App.kt @@ -1,37 +1,67 @@ package uk.sky.bob.application -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding import androidx.compose.material.Button +import androidx.compose.material.ExperimentalMaterialApi +import androidx.compose.material.FilterChip import androidx.compose.material.MaterialTheme import androidx.compose.material.Text -import androidx.compose.runtime.* +import androidx.compose.material.TextField +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import org.jetbrains.compose.resources.painterResource +import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.unit.dp import org.jetbrains.compose.ui.tooling.preview.Preview -import bob.composeapp.generated.resources.Res -import bob.composeapp.generated.resources.compose_multiplatform - +@OptIn(ExperimentalMaterialApi::class) @Composable @Preview fun App() { MaterialTheme { - var showContent by remember { mutableStateOf(false) } Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { - Button(onClick = { showContent = !showContent }) { - Text("Click me!") + Row { + val state = remember { mutableStateOf(Sentiment.HAPPY) } + for (emotion in Sentiment.entries) { + FilterChip( + onClick = { state.value = emotion }, + selected = state.value == emotion, + modifier = Modifier.padding(8.dp), + leadingIcon = { Text(emotion.leadingIcon) }, + ) { + Text(emotion.friendlyName) + } + } } - AnimatedVisibility(showContent) { - val greeting = remember { Greeting().greet() } - Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { - Image(painterResource(Res.drawable.compose_multiplatform), null) - Text("Compose: $greeting") + + Row { + var text by rememberSaveable(stateSaver = TextFieldValue.Saver) { + mutableStateOf( + TextFieldValue("") + ) + } + TextField( + value = text, + onValueChange = { text = it }, + label = { Text("Your comment") }, + maxLines = 3, + ) + } + + Row { + Button(onClick = { /* Handle submit */ }) { + Text("Submit") } } } } -} \ No newline at end of file +} + diff --git a/composeApp/src/commonMain/kotlin/uk/sky/bob/application/Greeting.kt b/composeApp/src/commonMain/kotlin/uk/sky/bob/application/Greeting.kt deleted file mode 100644 index 83a450f..0000000 --- a/composeApp/src/commonMain/kotlin/uk/sky/bob/application/Greeting.kt +++ /dev/null @@ -1,9 +0,0 @@ -package uk.sky.bob.application - -class Greeting { - private val platform = getPlatform() - - fun greet(): String { - return "Hello, ${platform.name}!" - } -} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/uk/sky/bob/application/Sentiment.kt b/composeApp/src/commonMain/kotlin/uk/sky/bob/application/Sentiment.kt new file mode 100644 index 0000000..bfe83d2 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/uk/sky/bob/application/Sentiment.kt @@ -0,0 +1,7 @@ +package uk.sky.bob.application + +enum class Sentiment(val friendlyName: String, val leadingIcon: String) { + HAPPY("Happy", "\uD83D\uDE03"), + NEUTRAL("Neutral", "\uD83D\uDE10"), + SAD("Sad", "\uD83D\uDE1E"); +} \ No newline at end of file