|
|
|
|
@ -9,17 +9,25 @@ import androidx.compose.foundation.layout.Row
@@ -9,17 +9,25 @@ import androidx.compose.foundation.layout.Row
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth |
|
|
|
|
import androidx.compose.foundation.layout.padding |
|
|
|
|
import androidx.compose.foundation.rememberScrollState |
|
|
|
|
import androidx.compose.foundation.text.input.rememberTextFieldState |
|
|
|
|
import androidx.compose.foundation.verticalScroll |
|
|
|
|
import androidx.compose.material.icons.Icons |
|
|
|
|
import androidx.compose.material.icons.filled.Add |
|
|
|
|
import androidx.compose.material.icons.filled.Check |
|
|
|
|
import androidx.compose.material3.Button |
|
|
|
|
import androidx.compose.material3.Icon |
|
|
|
|
import androidx.compose.material3.IconButton |
|
|
|
|
import androidx.compose.material3.InputChip |
|
|
|
|
import androidx.compose.material3.MaterialTheme |
|
|
|
|
import androidx.compose.material3.OutlinedButton |
|
|
|
|
import androidx.compose.material3.Surface |
|
|
|
|
import androidx.compose.material3.Text |
|
|
|
|
import androidx.compose.material3.TextField |
|
|
|
|
import androidx.compose.runtime.Composable |
|
|
|
|
import androidx.compose.runtime.getValue |
|
|
|
|
import androidx.compose.runtime.mutableIntStateOf |
|
|
|
|
import androidx.compose.runtime.mutableStateOf |
|
|
|
|
import androidx.compose.runtime.remember |
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope |
|
|
|
|
import androidx.compose.runtime.saveable.rememberSaveable |
|
|
|
|
import androidx.compose.runtime.setValue |
|
|
|
|
@ -34,6 +42,7 @@ import ru.asakul.feel.R
@@ -34,6 +42,7 @@ import ru.asakul.feel.R
|
|
|
|
|
import ru.asakul.feel.domain.Emotions |
|
|
|
|
import ru.asakul.feel.domain.Reasons |
|
|
|
|
import ru.asakul.feel.ui.mood.MoodEntryViewModel |
|
|
|
|
import java.io.Console |
|
|
|
|
import kotlin.collections.minus |
|
|
|
|
import kotlin.collections.plus |
|
|
|
|
|
|
|
|
|
@ -74,9 +83,12 @@ fun MoodLevelSelector(
@@ -74,9 +83,12 @@ fun MoodLevelSelector(
|
|
|
|
|
fun TagSelector( |
|
|
|
|
tags : Set<String>, |
|
|
|
|
modifier : Modifier = Modifier, |
|
|
|
|
onSelectedChange : (Set<String>) -> Unit |
|
|
|
|
onSelectedChange : (Set<String>) -> Unit, |
|
|
|
|
onNewTag : (String) -> Unit = { tag -> } |
|
|
|
|
) { |
|
|
|
|
var selectedTags by rememberSaveable { mutableStateOf(setOf<String>()) } |
|
|
|
|
var newTagEntry by remember {mutableStateOf(String())} |
|
|
|
|
var newTagEntryEnabled by remember {mutableStateOf(false)} |
|
|
|
|
FlowRow (modifier = modifier) { |
|
|
|
|
for (tag in tags) { |
|
|
|
|
val isSelected = tag in selectedTags |
|
|
|
|
@ -92,6 +104,25 @@ fun TagSelector(
@@ -92,6 +104,25 @@ fun TagSelector(
|
|
|
|
|
modifier = Modifier.padding(2.dp) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
if (!newTagEntryEnabled) { |
|
|
|
|
IconButton(onClick = { newTagEntryEnabled = true }) |
|
|
|
|
{ |
|
|
|
|
Icon(imageVector = Icons.Filled.Add, contentDescription = "Add tag") |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
TextField(value = newTagEntry, |
|
|
|
|
onValueChange = { newTagEntry = it }) |
|
|
|
|
IconButton(onClick = { |
|
|
|
|
val newTag = newTagEntry.replaceFirstChar { it.titlecase() } |
|
|
|
|
newTagEntryEnabled = false |
|
|
|
|
selectedTags += newTag |
|
|
|
|
onNewTag(newTag) |
|
|
|
|
newTagEntry = "" |
|
|
|
|
}) |
|
|
|
|
{ |
|
|
|
|
Icon(imageVector = Icons.Filled.Check, contentDescription = "Done") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -113,16 +144,27 @@ fun NewMoodEntry(
@@ -113,16 +144,27 @@ fun NewMoodEntry(
|
|
|
|
|
moodLevel = it |
|
|
|
|
))}) |
|
|
|
|
Text (stringResource(R.string.what_do_you_feel)) |
|
|
|
|
TagSelector(Emotions().allEmotions(), onSelectedChange = { |
|
|
|
|
TagSelector(Emotions().allEmotions() + viewModel.extraEmotions, |
|
|
|
|
onSelectedChange = { |
|
|
|
|
viewModel.updateUiState(viewModel.moodEntryState.moodEntry.copy( |
|
|
|
|
emotions = it.toList() |
|
|
|
|
)) |
|
|
|
|
}) |
|
|
|
|
emotions = it.toList())) |
|
|
|
|
}, |
|
|
|
|
onNewTag = { |
|
|
|
|
viewModel.extraEmotions += it |
|
|
|
|
viewModel.updateUiState(viewModel.moodEntryState.moodEntry.copy( |
|
|
|
|
emotions = viewModel.moodEntryState.moodEntry.emotions + it)) |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
Text(stringResource(R.string.why_do_you_feel_that_way)) |
|
|
|
|
TagSelector(Reasons().allReasons(), onSelectedChange = { |
|
|
|
|
TagSelector(Reasons().allReasons() + viewModel.extraReasons, |
|
|
|
|
onSelectedChange = { |
|
|
|
|
viewModel.updateUiState(viewModel.moodEntryState.moodEntry.copy( |
|
|
|
|
reasons = it.toList())) |
|
|
|
|
}, |
|
|
|
|
onNewTag = { |
|
|
|
|
viewModel.extraReasons += it |
|
|
|
|
viewModel.updateUiState(viewModel.moodEntryState.moodEntry.copy( |
|
|
|
|
reasons = it.toList() |
|
|
|
|
)) |
|
|
|
|
reasons = viewModel.moodEntryState.moodEntry.reasons + it)) |
|
|
|
|
}) |
|
|
|
|
Button(onClick = { |
|
|
|
|
coroutineScope.launch { |
|
|
|
|
|