Skip to content

Commit

Permalink
#19 create WriteAlgorithmScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrudals committed Feb 19, 2022
1 parent eebaac5 commit b5227a5
Showing 1 changed file with 361 additions and 0 deletions.
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 -> {

}
}
}
}



0 comments on commit b5227a5

Please sign in to comment.