|
1 | 1 | package co.yml.ychat.android.presentation.edits |
2 | 2 |
|
3 | 3 | import androidx.compose.foundation.background |
4 | | -import androidx.compose.foundation.layout.Arrangement |
5 | 4 | import androidx.compose.foundation.layout.Column |
6 | | -import androidx.compose.foundation.layout.fillMaxHeight |
| 5 | +import androidx.compose.foundation.layout.fillMaxSize |
| 6 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 7 | +import androidx.compose.foundation.layout.height |
| 8 | +import androidx.compose.foundation.layout.padding |
7 | 9 | import androidx.compose.runtime.Composable |
8 | 10 | import androidx.compose.ui.Modifier |
| 11 | +import androidx.compose.ui.res.stringResource |
9 | 12 | import androidx.compose.ui.tooling.preview.Preview |
10 | | -import co.yml.ychat.android.ui.components.feedback.Feedback |
11 | | -import co.yml.ychat.android.ui.components.feedback.model.FeedbackState |
| 13 | +import androidx.compose.ui.unit.dp |
| 14 | +import co.yml.ychat.YChat |
| 15 | +import co.yml.ychat.android.BuildConfig |
| 16 | +import co.yml.ychat.android.R |
| 17 | +import co.yml.ychat.android.ui.components.button.ButtonContained |
| 18 | +import co.yml.ychat.android.ui.components.output.OutputBox |
| 19 | +import co.yml.ychat.android.ui.components.textfield.StandardTextField |
| 20 | +import co.yml.ychat.android.ui.theme.Dimens |
| 21 | +import co.yml.ychat.android.ui.theme.TypographyStyle |
12 | 22 | import co.yml.ychat.android.ui.theme.YChatTheme |
| 23 | +import org.koin.androidx.compose.getViewModel |
13 | 24 |
|
14 | 25 | @Composable |
15 | | -internal fun EditsScreen() { |
| 26 | +internal fun EditsScreen(viewModel: EditsViewModel = getViewModel()) { |
16 | 27 | Column( |
17 | 28 | modifier = Modifier |
18 | 29 | .background(YChatTheme.colors.background) |
19 | | - .fillMaxHeight(), |
20 | | - verticalArrangement = Arrangement.Center, |
| 30 | + .padding(Dimens.MD) |
| 31 | + .fillMaxSize(), |
21 | 32 | ) { |
22 | | - Feedback(feedbackState = FeedbackState.CONSTRUCTION) |
| 33 | + TypographyStyle.MediumBody.Text(text = stringResource(id = R.string.edits_input_title)) |
| 34 | + StandardTextField( |
| 35 | + value = viewModel.inputMessage.value, |
| 36 | + hint = stringResource(id = R.string.edits_input_hint), |
| 37 | + modifier = Modifier |
| 38 | + .height(100.dp) |
| 39 | + .fillMaxWidth() |
| 40 | + .padding(top = Dimens.SM, bottom = Dimens.MD), |
| 41 | + onTextChanged = { viewModel.onInputMessage(it) }, |
| 42 | + enabled = viewModel.onEnableTextField.value, |
| 43 | + ) |
| 44 | + TypographyStyle.MediumBody.Text(text = stringResource(id = R.string.edits_instruction_title)) |
| 45 | + StandardTextField( |
| 46 | + value = viewModel.instructionMessage.value, |
| 47 | + hint = stringResource(id = R.string.edits_instruction_hint), |
| 48 | + modifier = Modifier |
| 49 | + .fillMaxWidth() |
| 50 | + .padding(top = Dimens.SM, bottom = Dimens.XM) |
| 51 | + , |
| 52 | + onTextChanged = { viewModel.onInstructionMessage(it) }, |
| 53 | + enabled = viewModel.onEnableTextField.value, |
| 54 | + ) |
| 55 | + ButtonContained( |
| 56 | + text = stringResource(id = R.string.edits_action), |
| 57 | + modifier = Modifier |
| 58 | + .fillMaxWidth() |
| 59 | + .padding(vertical = Dimens.XM), |
| 60 | + enabled = viewModel.onEnableButton.value, |
| 61 | + onClick = { viewModel.requestEdits() } |
| 62 | + ) |
| 63 | + OutputBox(outputBoxStates = viewModel.outputBoxStates) |
23 | 64 | } |
24 | 65 | } |
25 | 66 |
|
26 | 67 | @Preview |
27 | 68 | @Composable |
28 | 69 | private fun EditsScreenPreview() { |
29 | 70 | YChatTheme { |
30 | | - EditsScreen() |
| 71 | + val yChat = YChat.create(BuildConfig.API_KEY) |
| 72 | + val viewModel = EditsViewModel(yChat) |
| 73 | + EditsScreen(viewModel) |
31 | 74 | } |
32 | 75 | } |
0 commit comments