Skip to content

Commit

Permalink
#178 [refact] domain에 model 이름 수정 및 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
murjune committed Aug 11, 2022
1 parent c6a7409 commit 9c09cf1
Show file tree
Hide file tree
Showing 20 changed files with 177 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.hous.domain.model.Homie
import com.hous.domain.model.HomieInfo
import com.hous.hous_aos.R
import com.hous.hous_aos.ui.newrules.component.CategoryItem
import com.hous.hous_aos.ui.newrules.component.ManagerItem
Expand Down Expand Up @@ -143,7 +143,7 @@ fun NewRulesScreen(
Spacer(modifier = Modifier.size(12.dp))
}

itemsIndexed(uiState.ManagerList) { index, value ->
itemsIndexed(uiState.managerList) { index, value ->
ManagerItem(
manager = value,
currentIndex = index,
Expand Down Expand Up @@ -177,7 +177,7 @@ fun NewRulesScreen(
}

fun isAddDay(
homies: List<Homie>,
homies: List<HomieInfo>,
homieState: HashMap<String, Boolean>
): Boolean {
var temp = false
Expand Down
132 changes: 66 additions & 66 deletions app/src/main/java/com/hous/hous_aos/ui/newrules/NewRulesViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.hous.hous_aos.ui.newrules
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.hous.domain.model.Category
import com.hous.domain.model.DayData
import com.hous.domain.model.Homie
import com.hous.domain.model.CategoryInfo
import com.hous.domain.model.DayDataInfo
import com.hous.domain.model.HomieInfo
import com.hous.domain.model.Manager
import com.hous.domain.model.State
import com.hous.domain.usecase.AddNewRuleUseCase
Expand All @@ -29,8 +29,8 @@ class NewRulesViewModel @Inject constructor(
val uiState = _uiState.asStateFlow()
val buttonState: StateFlow<Boolean> = uiState.map {
it.ruleName.isNotEmpty() &&
it.categoryName.isNotEmpty() &&
(uiState.value.checkBoxState == State.SELECT || isDayCheck())
it.categoryName.isNotEmpty() &&
(uiState.value.checkBoxState == State.SELECT || isDayCheck())
}
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(3000L), false)

Expand All @@ -52,7 +52,7 @@ class NewRulesViewModel @Inject constructor(

private fun isDayCheck(): Boolean {
var isDay = true
for (manager in uiState.value.ManagerList) {
for (manager in uiState.value.managerList) {
var temp = false
for (dayList in manager.dayDataList) {
if (dayList.dayState == State.SELECT) {
Expand Down Expand Up @@ -105,89 +105,89 @@ class NewRulesViewModel @Inject constructor(
if (isChange) {
val tempManager = listOf(
Manager(
uiState.value.ManagerList[0].managerHomie,
uiState.value.managerList[0].managerHomie,
dayDataList = listOf(
DayData("", State.UNSELECT),
DayData("", State.UNSELECT),
DayData("", State.UNSELECT),
DayData("", State.UNSELECT),
DayData("", State.UNSELECT),
DayData("", State.UNSELECT),
DayData("", State.UNSELECT)
DayDataInfo("", State.UNSELECT),
DayDataInfo("", State.UNSELECT),
DayDataInfo("", State.UNSELECT),
DayDataInfo("", State.UNSELECT),
DayDataInfo("", State.UNSELECT),
DayDataInfo("", State.UNSELECT),
DayDataInfo("", State.UNSELECT)
)
)
)
_uiState.value = _uiState.value.copy(ManagerList = tempManager)
_uiState.value = _uiState.value.copy(managerList = tempManager)
} else {
val tempManager = listOf(
Manager(
uiState.value.ManagerList[0].managerHomie,
uiState.value.managerList[0].managerHomie,
dayDataList = listOf(
DayData("", State.BLOCK),
DayData("", State.BLOCK),
DayData("", State.BLOCK),
DayData("", State.BLOCK),
DayData("", State.BLOCK),
DayData("", State.BLOCK),
DayData("", State.BLOCK)
DayDataInfo("", State.BLOCK),
DayDataInfo("", State.BLOCK),
DayDataInfo("", State.BLOCK),
DayDataInfo("", State.BLOCK),
DayDataInfo("", State.BLOCK),
DayDataInfo("", State.BLOCK),
DayDataInfo("", State.BLOCK)
)
)
)
_uiState.value = _uiState.value.copy(ManagerList = tempManager)
_uiState.value = _uiState.value.copy(managerList = tempManager)
}
}

fun deleteManager(index: Int) {
uiState.value.homieState[uiState.value.ManagerList[index].managerHomie.userName] = true
if (uiState.value.ManagerList.size > 1) {
uiState.value.homieState[uiState.value.managerList[index].managerHomie.userName] = true
if (uiState.value.managerList.size > 1) {
val tempManager = mutableListOf<Manager>()
_uiState.value.ManagerList.forEach { manager -> tempManager.add(manager) }
_uiState.value.managerList.forEach { manager -> tempManager.add(manager) }
tempManager.removeAt(index)
_uiState.value = _uiState.value.copy(ManagerList = tempManager)
_uiState.value = _uiState.value.copy(managerList = tempManager)
} else {
_uiState.value = _uiState.value.copy(ManagerList = listOf(Manager()))
_uiState.value = _uiState.value.copy(managerList = listOf(Manager()))
setCheckBoxState("deleteManager", State.UNSELECT)
}
}

fun choiceManager(managerIndex: Int, homie: Homie) {
if (uiState.value.ManagerList[managerIndex].managerHomie.userName != "담당자 없음") {
_uiState.value.homieState[uiState.value.ManagerList[managerIndex].managerHomie.userName] =
fun choiceManager(managerIndex: Int, homie: HomieInfo) {
if (uiState.value.managerList[managerIndex].managerHomie.userName != "담당자 없음") {
_uiState.value.homieState[uiState.value.managerList[managerIndex].managerHomie.userName] =
true
}
val tempManager = Manager(
managerHomie = homie,
dayDataList = uiState.value.ManagerList[managerIndex].dayDataList
dayDataList = uiState.value.managerList[managerIndex].dayDataList
)
val tempManagerList = mutableListOf<Manager>()
_uiState.value.ManagerList.forEach { manager -> tempManagerList.add(manager) }
_uiState.value.managerList.forEach { manager -> tempManagerList.add(manager) }
tempManagerList[managerIndex] = tempManager
_uiState.value.homieState[homie.userName] = false
_uiState.value = _uiState.value.copy(ManagerList = tempManagerList)
_uiState.value = _uiState.value.copy(managerList = tempManagerList)
}

fun selectDay(managerIndex: Int, dayData: DayData) {
fun selectDay(managerIndex: Int, dayData: DayDataInfo) {
if (dayData.dayState != State.BLOCK) {
val tempManager = Manager(
managerHomie = _uiState.value.ManagerList[managerIndex].managerHomie,
managerHomie = _uiState.value.managerList[managerIndex].managerHomie,
dayDataList = changeDayState(dayData, managerIndex)
)
val tempManagerList = mutableListOf<Manager>()
uiState.value.ManagerList.forEach { manager -> tempManagerList.add(manager) }
uiState.value.managerList.forEach { manager -> tempManagerList.add(manager) }
tempManagerList[managerIndex] = tempManager
_uiState.value = _uiState.value.copy(ManagerList = tempManagerList)
_uiState.value = _uiState.value.copy(managerList = tempManagerList)
}
}

fun isShowAddButton(): Boolean =
uiState.value.ManagerList[uiState.value.ManagerList.size - 1].managerHomie.userName != "담당자 없음"
uiState.value.managerList[uiState.value.managerList.size - 1].managerHomie.userName != "담당자 없음"

fun addManager() {
val tempManagerList = mutableListOf<Manager>()
val nextManager = Manager(managerHomie = nextManager())
uiState.value.ManagerList.forEach { manager -> tempManagerList.add(manager) }
uiState.value.managerList.forEach { manager -> tempManagerList.add(manager) }
tempManagerList.add(nextManager)
_uiState.value = _uiState.value.copy(ManagerList = tempManagerList)
_uiState.value = _uiState.value.copy(managerList = tempManagerList)
}

fun addNewRule() {
Expand All @@ -197,16 +197,16 @@ class NewRulesViewModel @Inject constructor(
categoryId = uiState.value.categoryId,
notificationState = uiState.value.notificationState,
checkBoxState = uiState.value.checkBoxState,
managerList = uiState.value.ManagerList
managerList = uiState.value.managerList
)
}
}

private fun nextManager(): Homie {
var tempHomie = Homie("", "담당자 없음", typeColor = "NULL")
private fun nextManager(): HomieInfo {
var tempHomie = HomieInfo("", "담당자 없음", typeColor = "NULL")
for (i in uiState.value.homies) {
if (uiState.value.homieState[i.userName]!!) {
tempHomie = Homie(
tempHomie = HomieInfo(
id = i.id,
userName = i.userName,
typeColor = i.typeColor
Expand All @@ -218,23 +218,23 @@ class NewRulesViewModel @Inject constructor(
return tempHomie
}

private fun changeDayState(dayData: DayData, managerIndex: Int): List<DayData> {
val tempDay = mutableListOf<DayData>()
uiState.value.ManagerList[managerIndex].dayDataList.forEach { d ->
private fun changeDayState(dayData: DayDataInfo, managerIndex: Int): List<DayDataInfo> {
val tempDay = mutableListOf<DayDataInfo>()
uiState.value.managerList[managerIndex].dayDataList.forEach { d ->
if (d.day == dayData.day) {
when (dayData.dayState) {
State.UNSELECT -> {
tempDay.add(DayData(d.day, State.SELECT))
tempDay.add(DayDataInfo(d.day, State.SELECT))
setCheckBoxState("changeDayState Unselect", State.BLOCK)
}
State.SELECT -> {
tempDay.add(DayData(d.day, State.UNSELECT))
if (uiState.value.ManagerList.size == 1) {
tempDay.add(DayDataInfo(d.day, State.UNSELECT))
if (uiState.value.managerList.size == 1) {
var isCheck = true
uiState.value.ManagerList[0].dayDataList.forEach { dayData ->
uiState.value.managerList[0].dayDataList.forEach { dayData ->
if (dayData.dayState == State.SELECT) isCheck = false
}
if (isCheck && uiState.value.ManagerList[0].managerHomie.userName == "담당자 없음") {
if (isCheck && uiState.value.managerList[0].managerHomie.userName == "담당자 없음") {
setCheckBoxState("changeDayState select", State.UNSELECT)
}
}
Expand All @@ -252,20 +252,20 @@ data class NewRulesUiState(
val categoryId: String = "",
val notificationState: Boolean = false,
val checkBoxState: State = State.UNSELECT,
val ruleCategory: List<Category> =
val ruleCategory: List<CategoryInfo> =
listOf(
Category("1", "청소기"),
Category("2", "분리수거"),
Category("3", "세탁기"),
Category("4", "물 주기")
CategoryInfo("1", "청소기"),
CategoryInfo("2", "분리수거"),
CategoryInfo("3", "세탁기"),
CategoryInfo("4", "물 주기")
),
val homies: List<Homie> =
val homies: List<HomieInfo> =
listOf(
Homie("1", "강원용", typeColor = "RED"),
Homie("2", "이영주", typeColor = "BLUE"),
Homie("3", "이준원", typeColor = "YELLOW"),
Homie("4", "최인영", typeColor = "GREEN"),
Homie("5", "최소현", typeColor = "PURPLE")
HomieInfo("1", "강원용", typeColor = "RED"),
HomieInfo("2", "이영주", typeColor = "BLUE"),
HomieInfo("3", "이준원", typeColor = "YELLOW"),
HomieInfo("4", "최인영", typeColor = "GREEN"),
HomieInfo("5", "최소현", typeColor = "PURPLE")
),
val homieState: HashMap<String, Boolean> = hashMapOf(
"강원용" to true,
Expand All @@ -274,5 +274,5 @@ data class NewRulesUiState(
"최인영" to true,
"최소현" to true
),
val ManagerList: List<Manager> = listOf(Manager())
val managerList: List<Manager> = listOf(Manager())
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import com.hous.domain.model.CategoryInfo
import com.hous.hous_aos.R
import com.hous.domain.model.Category

@Composable
fun CategoryDropDownMenu(
ruleCategoryList: List<Category>,
ruleCategoryList: List<CategoryInfo>,
setCategory: (String, String) -> Unit
) {
var isExpanded by remember { mutableStateOf(false) }
Expand All @@ -40,14 +40,14 @@ fun CategoryDropDownMenu(
expanded = isExpanded,
onDismissRequest = { isExpanded = false }
) {
ruleCategoryList.forEach { category ->
ruleCategoryList.forEach { categoryInfo ->
DropdownMenuItem(
onClick = {
setCategory(category.id, category.categoryName)
setCategory(categoryInfo.id, categoryInfo.categoryName)
isExpanded = false
}
) {
Text(category.categoryName)
Text(categoryInfo.categoryName)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.hous.domain.model.CategoryInfo
import com.hous.hous_aos.R
import com.hous.domain.model.Category

@Composable
fun CategoryItem(
radius: Dp,
categoryName: String,
ruleCategoryList: List<Category>,
ruleCategoryList: List<CategoryInfo>,
setCategory: (String, String) -> Unit
) {
Box(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.dp
import com.hous.domain.model.DayData
import com.hous.domain.model.DayDataInfo
import com.hous.domain.model.State
import com.hous.hous_aos.R

@Composable
fun NewRulesDay(
dayData: DayData,
dayData: DayDataInfo,
currentIndex: Int,
selectDay: (Int, DayData) -> Unit
selectDay: (Int, DayDataInfo) -> Unit
) {
val color = when (dayData.dayState) {
State.UNSELECT -> colorResource(id = R.color.white)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import com.hous.domain.model.DayData
import com.hous.domain.model.DayDataInfo
import com.hous.domain.model.Manager

@Composable
fun NewRulesDayList(
manager: Manager,
currentIndex: Int,
selectDay: (Int, DayData) -> Unit
selectDay: (Int, DayDataInfo) -> Unit
) {
LazyRow(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
itemsIndexed(manager.dayDataList) { _, value ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.hous.domain.model.Homie
import com.hous.domain.model.HomieInfo
import com.hous.hous_aos.R
import com.hous.hous_aos.ui.newrules.isAddDay

@Composable
fun NewRulesAddMangerButton(
homies: List<Homie>,
homies: List<HomieInfo>,
homieState: HashMap<String, Boolean>,
isShowAddButton: () -> Boolean,
addManager: () -> Unit
Expand Down
Loading

0 comments on commit 9c09cf1

Please sign in to comment.