Skip to content

Commit

Permalink
Merge pull request #61 from TeamHous/feature/#60-create-new-rule-view…
Browse files Browse the repository at this point in the history
…model

[feat] 규칙 추가 뷰 / 규칙 추가 뷰 기능 구현
  • Loading branch information
KWY0218 authored Jul 16, 2022
2 parents 6706b79 + d353464 commit 0481b0a
Show file tree
Hide file tree
Showing 16 changed files with 456 additions and 299 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.hous.hous_aos.ui.newrules

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.hous.hous_aos.databinding.ActivityNewRuleBinding

class NewRuleActivity : AppCompatActivity() {
private lateinit var binding: ActivityNewRuleBinding
private val viewModel: NewRulesViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityNewRuleBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.cvNewRuleScreen.setContent {
NewRulesScreen()
NewRulesScreen(viewModel)
}
}
}
146 changes: 50 additions & 96 deletions app/src/main/java/com/hous/hous_aos/ui/newrules/NewRulesScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalFocusManager
Expand All @@ -34,58 +34,12 @@ import com.hous.hous_aos.ui.newrules.component.NewRulesTextField
import com.hous.hous_aos.ui.newrules.component.NewRulesToolbar
import com.hous.hous_aos.ui.newrules.component.State

data class NewRulesUiState(
val ruleName: String = "",
val categoryName: String = "",
val categoryId: String = "",
val notificationState: Boolean = false,
val ruleCategory: List<NewRulesResponse.Category> =
listOf(
NewRulesResponse.Category("1", "청소기"),
NewRulesResponse.Category("2", "분리수거"),
NewRulesResponse.Category("3", "세탁기"),
NewRulesResponse.Category("4", "물 주기"),
),
val homies: List<NewRulesResponse.Homie> =
listOf(
NewRulesResponse.Homie("1", "강원용", "RED"),
NewRulesResponse.Homie("2", "이영주", "BLUE"),
NewRulesResponse.Homie("3", "이준원", "YELLOW"),
NewRulesResponse.Homie("4", "최인영", "GREEN"),
NewRulesResponse.Homie("5", "최소현", "PURPLE"),
),
val homieState: HashMap<String, Boolean> = hashMapOf(
"강원용" to true,
"이영주" to true,
"이준원" to true,
"최인영" to true,
"최소현" to true,
)
)

@Composable
fun NewRulesScreen() {
val uiState = remember { mutableStateOf(NewRulesUiState()) }
val checkBoxState: MutableState<State> = remember { mutableStateOf(State.UNSELECT) }
val isRuleAddButton = remember { mutableStateOf(false) }
val test = remember {
mutableStateOf(
listOf(
Pair(
mutableStateOf(NewRulesResponse.Homie("", "담당자 없음", "NULL")),
listOf(
Pair("", mutableStateOf(State.UNSELECT)),
Pair("", mutableStateOf(State.UNSELECT)),
Pair("", mutableStateOf(State.UNSELECT)),
Pair("", mutableStateOf(State.UNSELECT)),
Pair("", mutableStateOf(State.UNSELECT)),
Pair("", mutableStateOf(State.UNSELECT)),
Pair("", mutableStateOf(State.UNSELECT)),
)
)
)
)
}
fun NewRulesScreen(
viewModel: NewRulesViewModel
) {
val uiState by viewModel.uiState.collectAsState()
val buttonState by viewModel.buttonState.collectAsState()
val focusManager = LocalFocusManager.current

Column(
Expand All @@ -99,18 +53,18 @@ fun NewRulesScreen() {
})
}
) {
/* 버튼 on / off */
// isRuleAddButton.value = uiState.value.ruleName.isNotEmpty() &&
// uiState.value.categoryName.isNotEmpty() &&
// (checkBoxState.value == State.SELECT || IsAdd(test))
LazyColumn(
modifier = Modifier
.weight(1f)
) {
item {
Spacer(modifier = Modifier.size(50.dp))

NewRulesToolbar(uiState, checkBoxState)
NewRulesToolbar(
notificationState = uiState.notificationState,
checkBoxState = uiState.checkBoxState,
toggleState = viewModel::toggleNotificationState
)
Spacer(modifier = Modifier.size(27.dp))

Text(
Expand All @@ -120,7 +74,11 @@ fun NewRulesScreen() {
)
Spacer(modifier = Modifier.size(8.dp))

NewRulesTextField(uiState, focusManager)
NewRulesTextField(
ruleName = uiState.ruleName,
changeRuleName = viewModel::setRuleName,
focusManager = focusManager
)
Spacer(modifier = Modifier.size(16.dp))

Text(
Expand All @@ -130,10 +88,19 @@ fun NewRulesScreen() {
)
Spacer(modifier = Modifier.size(8.dp))

CategoryItem(10.dp, uiState)
CategoryItem(
radius = 10.dp,
categoryName = uiState.categoryName,
ruleCategoryList = uiState.ruleCategory,
setCategory = viewModel::setCategoryName
)
Spacer(modifier = Modifier.size(16.dp))

NewRulesCheckBox(checkBoxState, test.value[0].second)
NewRulesCheckBox(
checkBoxState = uiState.checkBoxState,
setCheckBoxState = viewModel::setCheckBoxState,
setAllDayData = viewModel::setAllDayData
)
Spacer(modifier = Modifier.size(4.dp))

Row {
Expand All @@ -154,23 +121,31 @@ fun NewRulesScreen() {
Spacer(modifier = Modifier.size(12.dp))
}

itemsIndexed(test.value) { index, value ->
itemsIndexed(uiState.ManagerList) { index, value ->
ManagerItem(
test,
value.second,
index,
checkBoxState,
test.value.size,
uiState
manager = value,
currentIndex = index,
checkBoxState = uiState.checkBoxState,
homies = uiState.homies,
homieState = uiState.homieState,
deleteManager = viewModel::deleteManager,
setCheckBoxState = viewModel::setCheckBoxState,
choiceManager = viewModel::choiceManager,
selectDay = viewModel::selectDay
)
Spacer(modifier = Modifier.size(16.dp))
}

item {
NewRulesAddMangerButton(test, uiState)
NewRulesAddMangerButton(
homies = uiState.homies,
homieState = uiState.homieState,
isShowAddButton = viewModel::isShowAddButton,
addManager = viewModel::addManager
)
}
}
NewRulesAddRuleButton(isRuleAddButton)
NewRulesAddRuleButton(buttonState)
}
}

Expand All @@ -195,39 +170,18 @@ fun IsAdd(
}

fun isAddDay(
uiState: MutableState<NewRulesUiState>
homies: List<NewRulesResponse.Homie>,
homieState: HashMap<String, Boolean>
): Boolean {
var temp = false
uiState.value.homies.forEach { homie ->
if (uiState.value.homieState[homie.name]!!) temp = true
homies.forEach { h ->
if (homieState[h.name]!!) temp = true
}
return temp
}

fun addDay(
uiState: MutableState<NewRulesUiState>
): Pair<MutableState<NewRulesResponse.Homie>, List<Pair<String, MutableState<State>>>> {
var temp: NewRulesResponse.Homie = NewRulesResponse.Homie("", "", "")
for (i in uiState.value.homies) {
if (uiState.value.homieState[i.name]!!) {
temp = NewRulesResponse.Homie(i._id, i.name, i.typeColor)
uiState.value.homieState[temp.name] = false
break
}
}
return Pair(
mutableStateOf(NewRulesResponse.Homie(temp._id, temp.name, temp.typeColor)),
listOf("", "", "", "", "", "", "").map {
Pair(
it,
mutableStateOf(State.UNSELECT)
)
}
)
}

@Preview
@Composable
fun NewRulesPreview() {
NewRulesScreen()
// NewRulesScreen()
}
Loading

0 comments on commit 0481b0a

Please sign in to comment.