From ccd7a36fe56e9b541e5e5c1f447d6b86576eb1a2 Mon Sep 17 00:00:00 2001 From: JJongmen Date: Thu, 15 Feb 2024 00:57:07 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=EB=A9=94=EB=89=B4=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menu/presentation/InputMenuScreen.kt | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt index 44c83cc..f84a34f 100644 --- a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt +++ b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt @@ -13,7 +13,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.AddCircleOutline @@ -24,6 +24,8 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -73,16 +75,17 @@ fun InputMenuScreen() { @Suppress("MagicNumber") // TODO 기능 구현 시 제거 @Composable private fun InputMenuSection() { - // TODO 기능 구현 시 제거 val menus = - listOf( - Menu("비빔밥", 12000), - Menu("떡볶이", 8000), - Menu("김치볶음밥", 9000), - Menu("갈비구이", 18000), - Menu("김치전", 13000), - Menu("해물파전", 15000), - ) + remember { + mutableStateListOf( + Menu("비빔밥", 12000), + Menu("떡볶이", 8000), + Menu("김치볶음밥", 9000), + Menu("갈비구이", 18000), + Menu("김치전", 13000), + Menu("해물파전", 15000), + ) + } LazyColumn( modifier = @@ -93,8 +96,8 @@ private fun InputMenuSection() { horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Top, ) { - items(menus) { menu -> - CompletedMenuItem(menu) + itemsIndexed(menus) { index, menu -> + CompletedMenuItem(menu) { menus.removeAt(index) } } item { @@ -113,7 +116,10 @@ private fun InputMenuSection() { } @Composable -private fun CompletedMenuItem(menu: Menu) { +private fun CompletedMenuItem( + menu: Menu, + onClick: () -> Unit, +) { Row( modifier = Modifier @@ -133,7 +139,7 @@ private fun CompletedMenuItem(menu: Menu) { modifier = Modifier.weight(1f), ) IconButton( - onClick = { /*TODO*/ }, + onClick = onClick, modifier = Modifier .size(20.dp) From 6a90222077cad1eafca82bff345eca3a80341f46 Mon Sep 17 00:00:00 2001 From: JJongmen Date: Thu, 15 Feb 2024 02:36:14 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20InputTextBox=20=EC=BB=B4=ED=8F=AC?= =?UTF-8?q?=EC=A0=80=EB=B8=94=20=EC=82=AC=EC=9A=A9=EC=9E=90=EA=B0=80=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=ED=95=9C=20=EA=B0=92=20=EB=B0=9B=EC=9D=84=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=BD=9C=EB=B0=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/presentation/component/GsTextBox.kt | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt b/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt index 974119a..fd7f90e 100644 --- a/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt +++ b/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt @@ -44,7 +44,7 @@ fun GsTextBox( modifier: Modifier, innerTextModifier: Modifier, ) { - val text by remember { mutableStateOf(TextFieldValue(hintText)) } + var text by remember { mutableStateOf(TextFieldValue(hintText)) } var expanded by remember { mutableStateOf(false) } var selectedOption by remember { mutableStateOf("") } Column { @@ -66,9 +66,10 @@ fun GsTextBox( ) } else { InputTextBox( - text, - innerTextModifier, - modifier, + hintText = text.text, + onValueChange = { text = TextFieldValue(it) }, + modifier = innerTextModifier, + innerTextModifier = modifier, ) } } @@ -168,20 +169,22 @@ private fun DropdownTextBox( @Composable fun InputTextBox( - hintText: TextFieldValue, + hintText: String, + onValueChange: (String) -> Unit, modifier: Modifier, innerTextModifier: Modifier, ) { - var text by remember { - mutableStateOf(hintText) + var textState by remember { + mutableStateOf(TextFieldValue("")) } var isFocused by remember { mutableStateOf(false) } BasicTextField( - value = text, + value = textState, onValueChange = { updatedText -> - text = updatedText + textState = updatedText + onValueChange(updatedText.text) }, singleLine = true, modifier = @@ -193,10 +196,8 @@ fun InputTextBox( RoundedCornerShape(percent = 15), ).onFocusChanged { focusState -> isFocused = focusState.isFocused - if (isFocused && text == hintText) { - text = TextFieldValue("") - } else if (!isFocused && text.text.isEmpty()) { - text = hintText + if (isFocused && textState.text == hintText) { + textState = TextFieldValue("") } }, decorationBox = { innerTextField -> @@ -204,8 +205,8 @@ fun InputTextBox( modifier = innerTextModifier, verticalAlignment = Alignment.CenterVertically, ) { - if (!isFocused && text == hintText) { - Text(hintText.text, color = Color.Gray) + if (!isFocused && textState.text.isBlank()) { + Text(hintText, color = Color.Gray) Spacer(modifier = Modifier.weight(1f)) } else { innerTextField() From f8271918d421425553797732c7301946920c6c4b Mon Sep 17 00:00:00 2001 From: JJongmen Date: Thu, 15 Feb 2024 02:40:54 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20=EB=A9=94=EB=89=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menu/presentation/InputMenuScreen.kt | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt index f84a34f..db856b3 100644 --- a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt +++ b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt @@ -25,11 +25,11 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.erica.gamsung.core.presentation.component.GsButton @@ -72,20 +72,11 @@ fun InputMenuScreen() { } } -@Suppress("MagicNumber") // TODO 기능 구현 시 제거 @Composable private fun InputMenuSection() { - val menus = - remember { - mutableStateListOf( - Menu("비빔밥", 12000), - Menu("떡볶이", 8000), - Menu("김치볶음밥", 9000), - Menu("갈비구이", 18000), - Menu("김치전", 13000), - Menu("해물파전", 15000), - ) - } + val menus = remember { mutableStateListOf() } + val (name, setName) = remember { mutableStateOf("") } + val (price, setPrice) = remember { mutableStateOf("") } LazyColumn( modifier = @@ -101,11 +92,19 @@ private fun InputMenuSection() { } item { - InputMenuItem() + InputMenuItem( + nameChanged = { setName(it) }, + priceChanged = { setPrice(it) }, + ) } item { - IconButton(onClick = { /*TODO*/ }) { + IconButton(onClick = { + // TODO 입력값 검증 + menus.add(Menu(name, price.toInt())) + setName("") + setPrice("") + }) { Icon( imageVector = Icons.Default.AddCircleOutline, contentDescription = "메뉴 추가 아이콘", @@ -176,7 +175,10 @@ private fun MenuItemContainer( } @Composable -private fun InputMenuItem() { +private fun InputMenuItem( + nameChanged: (String) -> Unit, + priceChanged: (String) -> Unit, +) { Row( modifier = Modifier @@ -186,22 +188,24 @@ private fun InputMenuItem() { .border(1.dp, Color.Black, RoundedCornerShape(10.dp)), ) { TitleTextField( - title = "메뉴 이름", - hintText = "ex. 고등어 구이 정식", modifier = Modifier .fillMaxHeight() .padding(5.dp) .weight(1f), + title = "메뉴 이름", + hintText = "ex. 고등어 구이 정식", + onValueChange = nameChanged, ) TitleTextField( - title = "가격", - hintText = "ex. 15000", modifier = Modifier .fillMaxHeight() .padding(5.dp) .weight(1f), + title = "가격", + hintText = "ex. 15000", + onValueChange = priceChanged, ) Spacer(modifier = Modifier.padding(10.dp)) } @@ -212,6 +216,7 @@ private fun TitleTextField( modifier: Modifier = Modifier, title: String, hintText: String, + onValueChange: (String) -> Unit, ) { Column( modifier = modifier, @@ -219,7 +224,8 @@ private fun TitleTextField( ) { TextTitle(title = title, isRequired = true, description = null) InputTextBox( - hintText = TextFieldValue(hintText), + hintText = hintText, + onValueChange = onValueChange, modifier = Modifier .weight(1f) From 6ca559e6e8b57c045858a9d6fa8d0d9c5cf8cebf Mon Sep 17 00:00:00 2001 From: JJongmen Date: Thu, 15 Feb 2024 02:49:32 +0900 Subject: [PATCH 4/9] =?UTF-8?q?feat:=20=EA=B0=80=EA=B2=A9=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=ED=95=A0=20=EC=8B=9C=EC=97=90=20=EC=88=AB=EC=9E=90=20?= =?UTF-8?q?=EB=B0=B0=EC=97=B4=20=ED=82=A4=EB=B3=B4=EB=93=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../erica/gamsung/core/presentation/component/GsTextBox.kt | 5 +++++ .../com/erica/gamsung/menu/presentation/InputMenuScreen.kt | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt b/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt index fd7f90e..499a233 100644 --- a/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt +++ b/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt @@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.BasicTextField +import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowDropDown import androidx.compose.material3.DropdownMenu @@ -28,6 +29,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.withStyle import androidx.compose.ui.tooling.preview.Preview @@ -70,6 +72,7 @@ fun GsTextBox( onValueChange = { text = TextFieldValue(it) }, modifier = innerTextModifier, innerTextModifier = modifier, + keyboardType = KeyboardType.Text, ) } } @@ -171,6 +174,7 @@ private fun DropdownTextBox( fun InputTextBox( hintText: String, onValueChange: (String) -> Unit, + keyboardType: KeyboardType = KeyboardType.Text, modifier: Modifier, innerTextModifier: Modifier, ) { @@ -186,6 +190,7 @@ fun InputTextBox( textState = updatedText onValueChange(updatedText.text) }, + keyboardOptions = KeyboardOptions(keyboardType = keyboardType), singleLine = true, modifier = modifier diff --git a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt index db856b3..9e2de26 100644 --- a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt +++ b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt @@ -30,6 +30,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.erica.gamsung.core.presentation.component.GsButton @@ -196,6 +197,7 @@ private fun InputMenuItem( title = "메뉴 이름", hintText = "ex. 고등어 구이 정식", onValueChange = nameChanged, + keyboardType = KeyboardType.Text, ) TitleTextField( modifier = @@ -206,6 +208,7 @@ private fun InputMenuItem( title = "가격", hintText = "ex. 15000", onValueChange = priceChanged, + keyboardType = KeyboardType.Number, ) Spacer(modifier = Modifier.padding(10.dp)) } @@ -217,6 +220,7 @@ private fun TitleTextField( title: String, hintText: String, onValueChange: (String) -> Unit, + keyboardType: KeyboardType = KeyboardType.Text, ) { Column( modifier = modifier, @@ -231,6 +235,7 @@ private fun TitleTextField( .weight(1f) .padding(end = 10.dp), innerTextModifier = Modifier.padding(start = 5.dp), + keyboardType = keyboardType, ) } } From 7fa807e3d0ab64101208e5f0a314731aa6e876bc Mon Sep 17 00:00:00 2001 From: JJongmen Date: Thu, 15 Feb 2024 03:41:59 +0900 Subject: [PATCH 5/9] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=EA=B0=92=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gamsung/menu/presentation/InputMenuScreen.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt index 9e2de26..b5e75bd 100644 --- a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt +++ b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt @@ -101,10 +101,11 @@ private fun InputMenuSection() { item { IconButton(onClick = { - // TODO 입력값 검증 - menus.add(Menu(name, price.toInt())) - setName("") - setPrice("") + if (name.isNotBlank() && price.isZeroOrPrimitiveInt()) { + menus.add(Menu(name, price.toInt())) + setName("") + setPrice("") + } }) { Icon( imageVector = Icons.Default.AddCircleOutline, @@ -115,6 +116,11 @@ private fun InputMenuSection() { } } +private fun String.isZeroOrPrimitiveInt(): Boolean { + val int = this.toIntOrNull() ?: return false + return int >= 0 +} + @Composable private fun CompletedMenuItem( menu: Menu, From 357270842aebda3f0967ba442608710950ab5d71 Mon Sep 17 00:00:00 2001 From: JJongmen Date: Thu, 15 Feb 2024 21:49:33 +0900 Subject: [PATCH 6/9] =?UTF-8?q?feat:=20=EB=A9=94=EB=89=B4=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EB=B2=84=ED=8A=BC=20=ED=81=B4=EB=A6=AD=20=EC=8B=9C?= =?UTF-8?q?=20=EB=A9=94=EC=9D=B8=20=ED=99=94=EB=A9=B4=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gamsung/core/presentation/MainActivity.kt | 4 +++- .../erica/gamsung/core/presentation/Screen.kt | 1 + .../menu/presentation/InputMenuScreen.kt | 20 ++++++++++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/erica/gamsung/core/presentation/MainActivity.kt b/app/src/main/java/com/erica/gamsung/core/presentation/MainActivity.kt index da7719f..574759b 100644 --- a/app/src/main/java/com/erica/gamsung/core/presentation/MainActivity.kt +++ b/app/src/main/java/com/erica/gamsung/core/presentation/MainActivity.kt @@ -13,6 +13,7 @@ import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController +import com.erica.gamsung.menu.presentation.InputMenuScreen import com.erica.gamsung.ui.theme.GamsungTheme class MainActivity : ComponentActivity() { @@ -35,11 +36,12 @@ class MainActivity : ComponentActivity() { @Composable fun MainNavHost(navController: NavHostController) { - NavHost(navController = navController, startDestination = "main") { + NavHost(navController = navController, startDestination = Screen.MAIN.route) { composable(Screen.MAIN.route) { MainScreen(navController = navController) } composable(Screen.SETTING.route) { SettingScreen() } composable(Screen.PUBLISH_POSTING.route) { PublishPostingScreen() } composable(Screen.CHECK_POSTING.route) { CheckPostingScreen() } + composable(Screen.INPUT_MENU.route) { InputMenuScreen(navController = navController) } } } diff --git a/app/src/main/java/com/erica/gamsung/core/presentation/Screen.kt b/app/src/main/java/com/erica/gamsung/core/presentation/Screen.kt index f0ec2ef..992b1a4 100644 --- a/app/src/main/java/com/erica/gamsung/core/presentation/Screen.kt +++ b/app/src/main/java/com/erica/gamsung/core/presentation/Screen.kt @@ -7,4 +7,5 @@ enum class Screen( SETTING("setting"), PUBLISH_POSTING("publishPosting"), CHECK_POSTING("checkPosting"), + INPUT_MENU("inputMenu"), } diff --git a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt index b5e75bd..ed67172 100644 --- a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt +++ b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt @@ -1,5 +1,6 @@ package com.erica.gamsung.menu.presentation +import android.util.Log import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -27,12 +28,16 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.navigation.NavHostController +import androidx.navigation.compose.rememberNavController +import com.erica.gamsung.core.presentation.Screen import com.erica.gamsung.core.presentation.component.GsButton import com.erica.gamsung.core.presentation.component.GsTopAppBar import com.erica.gamsung.core.presentation.component.InputTextBox @@ -40,7 +45,7 @@ import com.erica.gamsung.core.presentation.component.TextTitle import com.erica.gamsung.menu.domain.Menu @Composable -fun InputMenuScreen() { +fun InputMenuScreen(navController: NavHostController = rememberNavController()) { Scaffold( topBar = { GsTopAppBar(title = "메뉴 입력 (2/2)") }, ) { paddingValues -> @@ -51,13 +56,14 @@ fun InputMenuScreen() { .padding(paddingValues), horizontalAlignment = Alignment.CenterHorizontally, ) { + val menus = remember { mutableStateListOf() } Box( modifier = Modifier .fillMaxWidth() .weight(1f), ) { - InputMenuSection() + InputMenuSection(menus) } Divider() GsButton( @@ -67,15 +73,19 @@ fun InputMenuScreen() { .fillMaxWidth() .height(70.dp) .padding(horizontal = 8.dp, vertical = 12.dp), - onClick = { TODO() }, + onClick = { + // TODO 서버로 메뉴 전송 + Log.d("InputMenuScreen", "서버로 전송할 메뉴 목록\n ${menus.toList().joinToString("\n")}") + + navController.navigate(Screen.MAIN.route) + }, ) } } } @Composable -private fun InputMenuSection() { - val menus = remember { mutableStateListOf() } +private fun InputMenuSection(menus: SnapshotStateList) { val (name, setName) = remember { mutableStateOf("") } val (price, setPrice) = remember { mutableStateOf("") } From 31613bf3fb8bac761a24e96f616980d389e723a8 Mon Sep 17 00:00:00 2001 From: JJongmen Date: Thu, 15 Feb 2024 23:39:39 +0900 Subject: [PATCH 7/9] =?UTF-8?q?refactor:=20InputTextBox=20=EC=BB=B4?= =?UTF-8?q?=ED=8F=AC=EC=A0=80=EB=B8=94=20OutlinedTextField=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/presentation/component/GsTextBox.kt | 73 ++++++++----------- .../menu/presentation/InputMenuScreen.kt | 16 ++-- 2 files changed, 38 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt b/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt index 499a233..406a0a4 100644 --- a/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt +++ b/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt @@ -16,15 +16,16 @@ import androidx.compose.material.icons.filled.ArrowDropDown import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text +import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.focus.onFocusChanged import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString @@ -50,7 +51,7 @@ fun GsTextBox( var expanded by remember { mutableStateOf(false) } var selectedOption by remember { mutableStateOf("") } Column { - TextTitle(title, isRequired, description) + TextTitle(title, isRequired, description, Modifier) if (options != null) { DropdownTextBox( text, @@ -70,9 +71,8 @@ fun GsTextBox( InputTextBox( hintText = text.text, onValueChange = { text = TextFieldValue(it) }, - modifier = innerTextModifier, - innerTextModifier = modifier, keyboardType = KeyboardType.Text, + modifier = innerTextModifier, ) } } @@ -83,6 +83,7 @@ fun TextTitle( title: String, isRequired: Boolean, description: String?, + modifier: Modifier = Modifier, ) { Text( text = @@ -112,6 +113,8 @@ fun TextTitle( description?.let { append(description) } } }, + style = MaterialTheme.typography.titleSmall, + modifier = modifier, ) } @@ -172,53 +175,37 @@ private fun DropdownTextBox( @Composable fun InputTextBox( + modifier: Modifier = Modifier, hintText: String, onValueChange: (String) -> Unit, keyboardType: KeyboardType = KeyboardType.Text, - modifier: Modifier, - innerTextModifier: Modifier, ) { var textState by remember { - mutableStateOf(TextFieldValue("")) + mutableStateOf("") } - var isFocused by remember { - mutableStateOf(false) - } - BasicTextField( + OutlinedTextField( value = textState, - onValueChange = { updatedText -> - textState = updatedText - onValueChange(updatedText.text) + onValueChange = { + textState = it + onValueChange(it) }, - keyboardOptions = KeyboardOptions(keyboardType = keyboardType), - singleLine = true, - modifier = - modifier - .background(Color.Transparent) - .border( - 1.dp, - Color.LightGray, - RoundedCornerShape(percent = 15), - ).onFocusChanged { focusState -> - isFocused = focusState.isFocused - if (isFocused && textState.text == hintText) { - textState = TextFieldValue("") - } - }, - decorationBox = { innerTextField -> - Row( - modifier = innerTextModifier, - verticalAlignment = Alignment.CenterVertically, - ) { - if (!isFocused && textState.text.isBlank()) { - Text(hintText, color = Color.Gray) - Spacer(modifier = Modifier.weight(1f)) - } else { - innerTextField() - Spacer(modifier = Modifier.weight(1f)) - } - } + placeholder = { + Text( + text = hintText, + color = Color.Gray, + style = MaterialTheme.typography.bodyLarge, + ) }, + singleLine = true, + colors = + TextFieldDefaults.colors( + unfocusedContainerColor = Color.Transparent, + unfocusedIndicatorColor = Color.LightGray, + ), + shape = RoundedCornerShape(percent = 15), + keyboardOptions = KeyboardOptions(keyboardType = keyboardType), + textStyle = MaterialTheme.typography.bodyLarge, + modifier = modifier, ) } diff --git a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt index ed67172..ce9295d 100644 --- a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt +++ b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt @@ -186,6 +186,7 @@ private fun MenuItemContainer( title = title, isRequired = false, description = null, + modifier = Modifier, ) Text(text = content) } @@ -200,7 +201,7 @@ private fun InputMenuItem( modifier = Modifier .fillMaxWidth() - .height(70.dp) + .height(100.dp) .padding(6.dp) .border(1.dp, Color.Black, RoundedCornerShape(10.dp)), ) { @@ -240,18 +241,17 @@ private fun TitleTextField( ) { Column( modifier = modifier, - verticalArrangement = Arrangement.SpaceEvenly, ) { - TextTitle(title = title, isRequired = true, description = null) + TextTitle( + title = title, + isRequired = true, + description = null, + ) InputTextBox( hintText = hintText, onValueChange = onValueChange, - modifier = - Modifier - .weight(1f) - .padding(end = 10.dp), - innerTextModifier = Modifier.padding(start = 5.dp), keyboardType = keyboardType, + modifier = Modifier.padding(top = 5.dp, end = 10.dp), ) } } From 10b4319708662b8542d854aebb89172f010515a7 Mon Sep 17 00:00:00 2001 From: JJongmen Date: Fri, 16 Feb 2024 00:12:20 +0900 Subject: [PATCH 8/9] =?UTF-8?q?feat:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EA=B0=92=20=EC=9E=85=EB=A0=A5=EC=8B=9C=20=EB=B9=A8=EA=B0=84?= =?UTF-8?q?=EC=83=89=EC=9C=BC=EB=A1=9C=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/presentation/component/GsTextBox.kt | 7 ++++++- .../menu/presentation/InputMenuScreen.kt | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt b/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt index 406a0a4..66a1a82 100644 --- a/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt +++ b/app/src/main/java/com/erica/gamsung/core/presentation/component/GsTextBox.kt @@ -69,10 +69,11 @@ fun GsTextBox( ) } else { InputTextBox( + modifier = innerTextModifier, hintText = text.text, onValueChange = { text = TextFieldValue(it) }, keyboardType = KeyboardType.Text, - modifier = innerTextModifier, + isError = false, ) } } @@ -179,6 +180,7 @@ fun InputTextBox( hintText: String, onValueChange: (String) -> Unit, keyboardType: KeyboardType = KeyboardType.Text, + isError: Boolean = false, ) { var textState by remember { mutableStateOf("") @@ -201,11 +203,14 @@ fun InputTextBox( TextFieldDefaults.colors( unfocusedContainerColor = Color.Transparent, unfocusedIndicatorColor = Color.LightGray, + focusedContainerColor = Color.Transparent, + errorContainerColor = Color.Transparent, ), shape = RoundedCornerShape(percent = 15), keyboardOptions = KeyboardOptions(keyboardType = keyboardType), textStyle = MaterialTheme.typography.bodyLarge, modifier = modifier, + isError = isError, ) } diff --git a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt index ce9295d..e48521e 100644 --- a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt +++ b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt @@ -88,6 +88,8 @@ fun InputMenuScreen(navController: NavHostController = rememberNavController()) private fun InputMenuSection(menus: SnapshotStateList) { val (name, setName) = remember { mutableStateOf("") } val (price, setPrice) = remember { mutableStateOf("") } + val isNameValid = remember { mutableStateOf(true) } + val isPriceValid = remember { mutableStateOf(true) } LazyColumn( modifier = @@ -106,12 +108,17 @@ private fun InputMenuSection(menus: SnapshotStateList) { InputMenuItem( nameChanged = { setName(it) }, priceChanged = { setPrice(it) }, + isNameValid = isNameValid.value, + isPriceValid = isPriceValid.value, ) } item { IconButton(onClick = { - if (name.isNotBlank() && price.isZeroOrPrimitiveInt()) { + isNameValid.value = name.isNotBlank() + isPriceValid.value = price.isZeroOrPrimitiveInt() + + if (isNameValid.value && isPriceValid.value) { menus.add(Menu(name, price.toInt())) setName("") setPrice("") @@ -196,6 +203,8 @@ private fun MenuItemContainer( private fun InputMenuItem( nameChanged: (String) -> Unit, priceChanged: (String) -> Unit, + isNameValid: Boolean = true, + isPriceValid: Boolean = true, ) { Row( modifier = @@ -215,6 +224,7 @@ private fun InputMenuItem( hintText = "ex. 고등어 구이 정식", onValueChange = nameChanged, keyboardType = KeyboardType.Text, + isValid = isNameValid, ) TitleTextField( modifier = @@ -226,6 +236,7 @@ private fun InputMenuItem( hintText = "ex. 15000", onValueChange = priceChanged, keyboardType = KeyboardType.Number, + isValid = isPriceValid, ) Spacer(modifier = Modifier.padding(10.dp)) } @@ -238,6 +249,7 @@ private fun TitleTextField( hintText: String, onValueChange: (String) -> Unit, keyboardType: KeyboardType = KeyboardType.Text, + isValid: Boolean = true, ) { Column( modifier = modifier, @@ -248,10 +260,11 @@ private fun TitleTextField( description = null, ) InputTextBox( + modifier = Modifier.padding(top = 5.dp, end = 10.dp), hintText = hintText, onValueChange = onValueChange, keyboardType = keyboardType, - modifier = Modifier.padding(top = 5.dp, end = 10.dp), + isError = !isValid, ) } } From 3b2632ab4a92d7211df400aaf2e07f6f0d429129 Mon Sep 17 00:00:00 2001 From: JJongmen Date: Fri, 16 Feb 2024 00:25:27 +0900 Subject: [PATCH 9/9] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=EB=90=9C=20?= =?UTF-8?q?=EB=A9=94=EB=89=B4=EA=B0=80=20=ED=95=98=EB=82=98=EB=8F=84=20?= =?UTF-8?q?=EC=97=86=EC=9D=84=20=EC=8B=9C=20=EB=A9=94=EB=89=B4=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EC=99=84=EB=A3=8C=20=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menu/presentation/InputMenuScreen.kt | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt index e48521e..de8175c 100644 --- a/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt +++ b/app/src/main/java/com/erica/gamsung/menu/presentation/InputMenuScreen.kt @@ -25,6 +25,7 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -57,13 +58,16 @@ fun InputMenuScreen(navController: NavHostController = rememberNavController()) horizontalAlignment = Alignment.CenterHorizontally, ) { val menus = remember { mutableStateListOf() } + val isNameValid = remember { mutableStateOf(true) } + val isPriceValid = remember { mutableStateOf(true) } + Box( modifier = Modifier .fillMaxWidth() .weight(1f), ) { - InputMenuSection(menus) + InputMenuSection(menus, isNameValid, isPriceValid) } Divider() GsButton( @@ -77,7 +81,12 @@ fun InputMenuScreen(navController: NavHostController = rememberNavController()) // TODO 서버로 메뉴 전송 Log.d("InputMenuScreen", "서버로 전송할 메뉴 목록\n ${menus.toList().joinToString("\n")}") - navController.navigate(Screen.MAIN.route) + if (menus.isEmpty()) { + isNameValid.value = false + isPriceValid.value = false + } else { + navController.navigate(Screen.MAIN.route) + } }, ) } @@ -85,11 +94,13 @@ fun InputMenuScreen(navController: NavHostController = rememberNavController()) } @Composable -private fun InputMenuSection(menus: SnapshotStateList) { +private fun InputMenuSection( + menus: SnapshotStateList, + isNameValid: MutableState, + isPriceValid: MutableState, +) { val (name, setName) = remember { mutableStateOf("") } val (price, setPrice) = remember { mutableStateOf("") } - val isNameValid = remember { mutableStateOf(true) } - val isPriceValid = remember { mutableStateOf(true) } LazyColumn( modifier =