Skip to content

Commit

Permalink
[MOD/#309] 변수명 수정 및 NULL_DATE 상수화
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Dec 20, 2024
1 parent 4222935 commit 26a9bb5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ fun HomeFilteringBottomSheet(
// todo: year와 month의 서버통신 값이 null이면 true로 넣어주세요!
var isCheckBoxChecked by remember { mutableStateOf(false) }

var isFirstNullAndFirstChange by remember { mutableStateOf(false) }
var isInitialNullState by remember { mutableStateOf(false) }

val yearsList by remember(isYearNull) {
mutableStateOf(
if (isYearNull || isFirstNullAndFirstChange) years + "-"
if (isYearNull || isInitialNullState) years + NULL_DATE
else years
)
}
val monthsList by remember(isMonthNull) {
mutableStateOf(
if (isMonthNull || isFirstNullAndFirstChange) months + "-"
if (isMonthNull || isInitialNullState) months + NULL_DATE
else months
)
}
Expand Down Expand Up @@ -167,31 +167,30 @@ fun HomeFilteringBottomSheet(
modifier = Modifier.padding(start = 20.dp)
)

// todo: null 처리 제대로
HomeYearMonthPicker(
chosenYear = defaultStartYear ?: Calendar.getInstance().currentYear,
chosenMonth = defaultStartMonth ?: Calendar.getInstance().currentMonth,
onYearChosen = { year, isFirst ->
onYearChosen = { year, isInitialSelection ->
if (year != null) {
currentStartYear = year
isCheckBoxChecked = false
isYearNull = false
isFirstNullAndFirstChange = isFirst
isInitialNullState = isInitialSelection
}
},
onMonthChosen = { month, isFirst ->
onMonthChosen = { month, isInitialSelection ->
if (month != null) {
currentStartMonth = month
isCheckBoxChecked = false
isMonthNull = false
isFirstNullAndFirstChange = isFirst
isInitialNullState = isInitialSelection
}
},
isYearNull = isYearNull,
isMonthNull = isMonthNull,
yearsList = yearsList,
monthsList = monthsList,
isFirstNullAndFirstChange = isFirstNullAndFirstChange
isInitialNullState = isInitialNullState
)

RoundButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ val years = (START_YEAR..END_YEAR).map { "${it}년" }.toImmutableList()

val months = (START_MONTH..END_MONTH).map { "${it}" }.toImmutableList()

const val NULL_DATE = "-"

class PickerState {
var selectedItem by mutableStateOf("")
}
Expand All @@ -64,16 +66,16 @@ fun HomeYearMonthPicker(
isMonthNull: Boolean,
yearsList: List<String>,
monthsList: List<String>,
isFirstNullAndFirstChange: Boolean
isInitialNullState: Boolean
) {
val yearPickerState = rememberPickerState()
val monthPickerState = rememberPickerState()

var isFirst = isFirstNullAndFirstChange
var isInitialSelection by remember { mutableStateOf(isInitialNullState) }

val startYearIndex =
if (isYearNull) yearsList.lastIndex else yearsList.indexOf("${chosenYear ?: "-"}")
.takeIf { it >= 0 } ?: 0
.takeIf { it >= 0 } ?: 0

val startMonthIndex =
if (isMonthNull) monthsList.lastIndex else monthsList.indexOf("${chosenMonth ?: "-"}")
Expand All @@ -91,8 +93,11 @@ fun HomeYearMonthPicker(
items = yearsList,
startIndex = startYearIndex,
onItemSelected = { year ->
if (year == "-" && !isFirst) isFirst = true
onYearChosen(if (year == "-") null else year.dropLast(1).toInt(), isFirst)
if (year == NULL_DATE && !isInitialSelection) isInitialSelection = true
onYearChosen(
if (year == NULL_DATE) null else year.dropLast(1).toInt(),
isInitialSelection
)
}
)
Spacer(modifier = Modifier.width(18.dp))
Expand All @@ -102,8 +107,11 @@ fun HomeYearMonthPicker(
items = monthsList,
startIndex = startMonthIndex,
onItemSelected = { month ->
if (month == "-" && !isFirst) isFirst = true
onMonthChosen(if (month == "-") null else month.dropLast(1).toInt(), isFirst)
if (month == NULL_DATE && !isInitialSelection) isInitialSelection = true
onMonthChosen(
if (month == NULL_DATE) null else month.dropLast(1).toInt(),
isInitialSelection
)
}
)
}
Expand Down Expand Up @@ -138,7 +146,7 @@ fun DatePicker(
snapshotFlow { scrollState.firstVisibleItemIndex }
.map { index ->
var newItem = items
if (isNullSize) newItem = items + "-"
if (isNullSize) newItem = items + NULL_DATE
newItem.getOrNull(index)
}
.distinctUntilChanged()
Expand Down

0 comments on commit 26a9bb5

Please sign in to comment.