-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
361 additions
and
0 deletions.
There are no files selected for viewing
361 changes: 361 additions & 0 deletions
361
presentation/src/main/java/com/study/presentation/ui/user/write/WriteAlgorithmScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,361 @@ | ||
package com.study.presentation.ui.user.write | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.input.TextFieldValue | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import com.example.ui.ui.SetSpinner | ||
import com.example.ui.ui.theme.BambooTheme | ||
import com.example.ui.ui.theme.black | ||
import com.example.ui.ui.theme.mainColor | ||
import com.study.base.base.utils.UiState | ||
import com.study.presentation.ui.user.viewmodel.AlgorithmViewModel | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
|
||
@AndroidEntryPoint | ||
class WriteAlgorithmScreen : ComponentActivity() { | ||
|
||
@ExperimentalMaterialApi | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
BambooTheme { | ||
|
||
WriteAlgorithm() | ||
} | ||
} | ||
} | ||
|
||
|
||
@ExperimentalMaterialApi | ||
@Composable | ||
fun WriteAlgorithm() { | ||
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState( | ||
bottomSheetState = BottomSheetState(BottomSheetValue.Collapsed) | ||
) | ||
|
||
val questionText = remember { mutableStateOf(TextFieldValue()) } | ||
val titleText = remember { mutableStateOf(TextFieldValue()) } | ||
val contentText = remember { mutableStateOf(TextFieldValue()) } | ||
val tagText = remember { mutableStateOf("") } | ||
|
||
BottomSheetScaffold( | ||
scaffoldState = bottomSheetScaffoldState, | ||
sheetContent = { | ||
Box( | ||
Modifier | ||
.fillMaxSize() | ||
.height(200.dp) | ||
.padding(20.dp) | ||
.background(color = Color.White) | ||
) { | ||
Column( | ||
modifier = | ||
Modifier | ||
.fillMaxSize() | ||
) { | ||
Text( | ||
text = "๊ธ ์ ๋ ฅํ๊ธฐ", | ||
color = mainColor | ||
) | ||
|
||
Spacer(Modifier.height(10.dp)) | ||
|
||
Text( | ||
text = "์ฌ๋ฆฌ๊ณ ์ถ์ ๊ธ์ ์ ๋ ฅํด์ฃผ์ธ์!", | ||
fontSize = 17.sp, | ||
color = black | ||
) | ||
SetTitle(titleText) | ||
SetSpinner(tagText) | ||
Spacer(Modifier.height(10.dp)) | ||
SetContent(contentText) | ||
Text("Q. ์ง๋ฌธ์ ๋๋ค.") | ||
SetQuestion(questionText) | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
ClickWriteButton( | ||
title = titleText.value.toString(), | ||
content = contentText.value.toString(), | ||
tag = tagText.value, | ||
answer = questionText.value.toString() | ||
) | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
}, | ||
sheetPeekHeight = 56.dp | ||
) { | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
@Composable | ||
fun WriteAlgorithmScreen() { | ||
|
||
} | ||
|
||
@Composable | ||
private fun SetTitle( | ||
titleText: MutableState<TextFieldValue>, | ||
|
||
) { | ||
val titleHintText = remember { mutableStateOf("์ ๋ชฉ์ ์ ๋ ฅํด ์ฃผ์ธ์") } | ||
Row( | ||
Modifier.fillMaxWidth(), | ||
|
||
) { | ||
|
||
OutlinedTextField( | ||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Start), | ||
value = titleText.value, | ||
onValueChange = { newText -> | ||
titleText.value = newText | ||
}, | ||
singleLine = false, | ||
label = { | ||
Text( | ||
text = titleHintText.value, | ||
modifier = Modifier | ||
.wrapContentSize() | ||
.clickable(onClick = { | ||
if (titleText.value | ||
.toString() | ||
.isEmpty() | ||
) titleHintText.value = | ||
"์ ๋ชฉ์ ์ ๋ ฅํด ์ฃผ์ธ์" else titleHintText.value = "" | ||
}), | ||
|
||
|
||
textAlign = TextAlign.Center, | ||
|
||
color = Color.LightGray, | ||
fontSize = 15.sp, | ||
|
||
|
||
) | ||
}, | ||
shape = RoundedCornerShape(10.dp), | ||
|
||
colors = TextFieldDefaults.textFieldColors( | ||
textColor = Color.Gray, | ||
disabledTextColor = Color.Transparent, | ||
backgroundColor = Color.White, | ||
focusedIndicatorColor = Color.Transparent, | ||
unfocusedIndicatorColor = Color.Transparent, | ||
disabledIndicatorColor = Color.Transparent | ||
) | ||
|
||
) | ||
|
||
} | ||
|
||
} | ||
|
||
@Composable | ||
private fun SetSpinner(tag: MutableState<String>) { | ||
val isOpen = remember { mutableStateOf(false) } | ||
val openCloseOfDropDownList: (Boolean) -> Unit = { | ||
isOpen.value = it | ||
} | ||
val userSelectedString: (String) -> Unit = { | ||
tag.value = it | ||
} | ||
SetSpinner( | ||
requestToOpen = isOpen.value, | ||
selectedString = userSelectedString, | ||
request = openCloseOfDropDownList | ||
|
||
) | ||
Spacer( | ||
modifier = Modifier | ||
.wrapContentWidth() | ||
.background(Color.Transparent) | ||
.padding(10.dp) | ||
.clickable( | ||
onClick = { isOpen.value = true } | ||
) | ||
) | ||
|
||
} | ||
|
||
@Composable | ||
private fun SetContent( | ||
contentText: MutableState<TextFieldValue>, | ||
) { | ||
val contentHintText = remember { mutableStateOf("๋ด์ฉ์ ์ ๋ ฅํด ์ฃผ์ธ์") } | ||
Card( | ||
elevation = 5.dp | ||
) { | ||
OutlinedTextField( | ||
modifier = Modifier | ||
.height(100.dp) | ||
.fillMaxWidth(), | ||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Start), | ||
value = contentText.value, | ||
onValueChange = { newText -> | ||
contentText.value = newText | ||
}, | ||
singleLine = false, | ||
label = { | ||
Text( | ||
text = contentHintText.value, | ||
modifier = Modifier | ||
.clickable(onClick = { | ||
if (contentText.value | ||
.toString().isEmpty() | ||
|
||
) contentHintText.value = | ||
"๋ด์ฉ์ ์ ๋ ฅํด ์ฃผ์ธ์" else contentHintText.value = "" | ||
}), | ||
|
||
|
||
textAlign = TextAlign.Center, | ||
|
||
color = Color.LightGray, | ||
fontSize = 15.sp, | ||
|
||
|
||
) | ||
}, | ||
shape = RoundedCornerShape(10.dp), | ||
|
||
colors = TextFieldDefaults.textFieldColors( | ||
textColor = Color.Gray, | ||
disabledTextColor = Color.Transparent, | ||
backgroundColor = Color.White, | ||
focusedIndicatorColor = Color.Transparent, | ||
unfocusedIndicatorColor = Color.Transparent, | ||
disabledIndicatorColor = Color.Transparent | ||
) | ||
|
||
) | ||
|
||
} | ||
} | ||
|
||
@Composable | ||
private fun SetQuestion( | ||
questionText: MutableState<TextFieldValue>, | ||
|
||
) { | ||
val questionHintText = remember { mutableStateOf("์์ดํ์ด ๋น๋ฒ์ ์ ๋ ฅํด ์ฃผ์ธ์") } | ||
|
||
Card( | ||
elevation = 5.dp | ||
) { | ||
OutlinedTextField( | ||
modifier = Modifier | ||
.fillMaxWidth(), | ||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Start), | ||
value = questionText.value, | ||
onValueChange = { newText -> | ||
questionText.value = newText | ||
}, | ||
singleLine = false, | ||
label = { | ||
Text( | ||
text = questionHintText.value, | ||
modifier = Modifier | ||
.clickable(onClick = { | ||
if (questionText.value | ||
.toString().isEmpty() | ||
|
||
) questionHintText.value = | ||
"๋ด์ฉ์ ์ ๋ ฅํด ์ฃผ์ธ์" else questionHintText.value = "" | ||
}), | ||
|
||
|
||
textAlign = TextAlign.Center, | ||
|
||
color = Color.LightGray, | ||
fontSize = 15.sp, | ||
|
||
|
||
) | ||
}, | ||
shape = RoundedCornerShape(10.dp), | ||
|
||
colors = TextFieldDefaults.textFieldColors( | ||
textColor = Color.Gray, | ||
disabledTextColor = Color.Transparent, | ||
backgroundColor = Color.White, | ||
focusedIndicatorColor = Color.Transparent, | ||
unfocusedIndicatorColor = Color.Transparent, | ||
disabledIndicatorColor = Color.Transparent | ||
) | ||
|
||
) | ||
|
||
} | ||
} | ||
|
||
@Composable | ||
private fun ClickWriteButton( | ||
viewModel: AlgorithmViewModel = viewModel(), | ||
title: String, | ||
content: String, | ||
tag: String, | ||
answer: String | ||
) { | ||
val questionId = viewModel.questionId.observeAsState().value ?: "" | ||
Button( | ||
onClick = { | ||
viewModel.postWriteAlgorithm( | ||
title = title, | ||
content = content, | ||
tag = tag, | ||
questionId = questionId, | ||
answer = answer | ||
) | ||
}, | ||
shape = RoundedCornerShape(10.dp), | ||
colors = ButtonDefaults.buttonColors( | ||
backgroundColor = mainColor | ||
), | ||
modifier = Modifier.fillMaxWidth() | ||
) { | ||
Text(text = "์ ์ก", textAlign = TextAlign.Center, color = Color.White) | ||
|
||
} | ||
} | ||
|
||
@Composable | ||
fun WriteAlgorithmScreen(viewModel: AlgorithmViewModel = viewModel()) { | ||
|
||
val uiState = viewModel.uiState.collectAsState() | ||
|
||
when (uiState.value) { | ||
is UiState.Loading -> { | ||
|
||
} | ||
is UiState.Error -> { | ||
|
||
} | ||
is UiState.Success -> { | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|