Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT/#309] 홈 필터링 재설정 뷰 / 데이트 피커 비활성화 아이템 추가 #314

Merged
merged 22 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b550128
[FEAT/#309] 데이트피커 함수명 수정 및 비활성화 아이템 추가
leeeyubin Dec 10, 2024
8aed3ef
[CHORE/#309] import문 수정
leeeyubin Dec 16, 2024
5871a4e
[FEAT/#309] git pull from develop
leeeyubin Dec 19, 2024
523b60a
[FEAT/#309] 체크박스 및 데이트피커의 년과 월의 독립적 구현
leeeyubin Dec 19, 2024
39f647b
[FEAT/#309] 바뀐 값을 원래의 값으로 수정
leeeyubin Dec 19, 2024
23f2f6a
[FEAT/#309] 데이트피커 명세서대로 구현
leeeyubin Dec 20, 2024
81e0769
[DEL/#309] 로그 삭제
leeeyubin Dec 20, 2024
5ea0e4b
[DEL/#309] 불필요한 remember 제거
leeeyubin Dec 20, 2024
24d3ccd
[DEL/#309] 불필요한 매개변수 제거
leeeyubin Dec 20, 2024
d68a2eb
[MOD/#309] 변수명 수정
leeeyubin Dec 20, 2024
4222935
[MOD/#309] 체크박스 로직 수정
leeeyubin Dec 20, 2024
26a9bb5
[MOD/#309] 변수명 수정 및 NULL_DATE 상수화
leeeyubin Dec 20, 2024
708c457
[MOD/#309] 원래의 형태에 맞게 수정
leeeyubin Dec 20, 2024
449ae7b
[MOD/#309] 변수명 및 로직 수정
leeeyubin Dec 20, 2024
0b4fa70
[MOD/#309] 불필요한 변수 삭제
leeeyubin Dec 20, 2024
d47d73f
[MOD/#309] 로직 알맞게 수정
leeeyubin Dec 20, 2024
8079dc1
[FEAT/#309] ImmutableList 적용
leeeyubin Dec 20, 2024
a4424aa
[MOD/#309] 불필요한 블록 삭제
leeeyubin Dec 20, 2024
c2e1a66
[MOD/#309] 변수간 공백 삭제
leeeyubin Dec 20, 2024
e9c0323
[MOD/#309] 변수간 공백 삭제
leeeyubin Dec 20, 2024
3a7b3e1
[FEAT/#309] git pull from develop
leeeyubin Dec 21, 2024
f34da9a
[FEAT/#309] git pull from develop
leeeyubin Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import com.terning.core.designsystem.theme.TerningPointTheme
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.designsystem.theme.White
import com.terning.feature.filtering.R
import com.terning.feature.filtering.filteringthree.component.YearMonthPicker
import com.terning.feature.filtering.filteringthree.component.FilteringYearMonthPicker
import java.util.Calendar

@Composable
Expand Down Expand Up @@ -147,7 +147,7 @@ fun FilteringThreeScreen(
)
)
Spacer(modifier = Modifier.height(61.dp))
YearMonthPicker(
FilteringYearMonthPicker(
chosenYear = chosenYear,
chosenMonth = chosenMonth,
onYearChosen = { onYearChosen(it) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PickerState {
fun rememberPickerState() = remember { PickerState() }

@Composable
fun YearMonthPicker(
fun FilteringYearMonthPicker(
modifier: Modifier = Modifier,
chosenYear: Int,
chosenMonth: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.material3.Checkbox
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
Expand All @@ -21,6 +22,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.terning.core.designsystem.R
import com.terning.core.designsystem.component.bottomsheet.TerningBasicBottomSheet
import com.terning.core.designsystem.component.button.ChangeFilterButton
import com.terning.core.designsystem.component.button.RoundButton
Expand All @@ -31,7 +33,7 @@ import com.terning.core.designsystem.theme.Grey200
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.designsystem.type.Grade
import com.terning.core.designsystem.type.WorkingPeriod
import com.terning.core.designsystem.R
import kotlinx.collections.immutable.toImmutableList
import java.util.Calendar

@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -60,6 +62,26 @@ fun HomeFilteringBottomSheet(
)
}

var isYearNull by remember { mutableStateOf(defaultStartYear != null) }
var isMonthNull by remember { mutableStateOf(defaultStartMonth != null) }

var isCheckBoxChecked by remember { mutableStateOf(false) }

var isInitialNullState by remember { mutableStateOf(false) }

val yearsList by remember(isYearNull) {
mutableStateOf(
if (isYearNull || isInitialNullState) years + NULL_DATE
else years
)
}
val monthsList by remember(isMonthNull) {
mutableStateOf(
if (isMonthNull || isInitialNullState) months + NULL_DATE
else months
)
}

TerningBasicBottomSheet(
content = {
Column(
Expand Down Expand Up @@ -132,13 +154,45 @@ fun HomeFilteringBottomSheet(
.padding(horizontal = 24.dp)
)

YearMonthPicker(
chosenYear = defaultStartYear ?: Calendar.getInstance().currentYear,
chosenMonth = defaultStartMonth
?: Calendar.getInstance().currentMonth,
onYearChosen = { currentStartYear = it },
onMonthChosen = { currentStartMonth = it }
//TODO: 아래는 임시 체크박스로, 추후 수정 부탁합니다!
Checkbox(
checked = isCheckBoxChecked,
onCheckedChange = { isChecked ->
if (isChecked) {
isYearNull = true
isMonthNull = true
}
isCheckBoxChecked = isChecked
},
modifier = Modifier.padding(start = 20.dp)
)

HomeYearMonthPicker(
chosenYear = defaultStartYear,
chosenMonth = defaultStartMonth,
onYearChosen = { year, isInitialSelection ->
if (year != null) {
currentStartYear = year
isCheckBoxChecked = false
isYearNull = false
isInitialNullState = isInitialSelection
}
},
onMonthChosen = { month, isInitialSelection ->
if (month != null) {
currentStartMonth = month
isCheckBoxChecked = false
isMonthNull = false
isInitialNullState = isInitialSelection
}
},
isYearNull = isYearNull,
isMonthNull = isMonthNull,
yearsList = yearsList.toImmutableList(),
monthsList = monthsList.toImmutableList(),
isInitialNullState = isInitialNullState
)

RoundButton(
style = TerningTheme.typography.button0,
paddingVertical = 19.dp,
Expand All @@ -162,7 +216,6 @@ fun HomeFilteringBottomSheet(
isEnabled = currentGrade != null && currentPeriod != null
)
}

},
onDismissRequest = onDismiss,
sheetState = sheetState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ import com.terning.core.designsystem.util.CalendarDefaults.END_MONTH
import com.terning.core.designsystem.util.CalendarDefaults.END_YEAR
import com.terning.core.designsystem.util.CalendarDefaults.START_MONTH
import com.terning.core.designsystem.util.CalendarDefaults.START_YEAR
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import okhttp3.internal.toImmutableList

private val years =
(START_YEAR..END_YEAR).map { "${it}" }.toImmutableList()
val years = (START_YEAR..END_YEAR).map { "${it}년" }
val months = (START_MONTH..END_MONTH).map { "${it}" }

private val months =
(START_MONTH..END_MONTH).map { "${it}월" }.toImmutableList()
const val NULL_DATE = "-"

class PickerState {
var selectedItem by mutableStateOf("")
Expand All @@ -56,26 +55,29 @@ class PickerState {
fun rememberPickerState() = remember { PickerState() }

@Composable
fun YearMonthPicker(
fun HomeYearMonthPicker(
modifier: Modifier = Modifier,
chosenYear: Int,
chosenMonth: Int,
onYearChosen: (Int) -> Unit,
onMonthChosen: (Int) -> Unit,
chosenYear: Int?,
chosenMonth: Int?,
onYearChosen: (Int?, Boolean) -> Unit,
onMonthChosen: (Int?, Boolean) -> Unit,
isYearNull: Boolean,
isMonthNull: Boolean,
yearsList: ImmutableList<String>,
monthsList: ImmutableList<String>,
isInitialNullState: Boolean
) {
val yearPickerState = rememberPickerState()
val monthPickerState = rememberPickerState()

val startYearIndex = years.indexOf("${chosenYear}년").takeIf { it >= 0 } ?: 0
val startMonthIndex = months.indexOf("${chosenMonth}월").takeIf { it >= 0 } ?: 0
var isInitialSelection by remember { mutableStateOf(isInitialNullState) }

LaunchedEffect(chosenYear) {
yearPickerState.selectedItem = "${chosenYear}년"
}

LaunchedEffect(chosenMonth) {
monthPickerState.selectedItem = "${chosenMonth}월"
}
val startYearIndex =
if (isYearNull) yearsList.lastIndex else yearsList.indexOf("${chosenYear ?: "-"}년")
.takeIf { it >= 0 } ?: 0
val startMonthIndex =
if (isMonthNull) monthsList.lastIndex else monthsList.indexOf("${chosenMonth ?: "-"}월")
.takeIf { it >= 0 } ?: 0

Row(
modifier = modifier
Expand All @@ -86,28 +88,36 @@ fun YearMonthPicker(
DatePicker(
modifier = Modifier.weight(1f),
pickerState = yearPickerState,
items = years,
items = yearsList,
startIndex = startYearIndex,
onItemSelected = { year ->
onYearChosen(year.dropLast(1).toInt())
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))
DatePicker(
modifier = Modifier.weight(1f),
pickerState = monthPickerState,
items = months,
items = monthsList,
startIndex = startMonthIndex,
onItemSelected = { month ->
onMonthChosen(month.dropLast(1).toInt())
if (month == NULL_DATE && !isInitialSelection) isInitialSelection = true
onMonthChosen(
if (month == NULL_DATE) null else month.dropLast(1).toInt(),
isInitialSelection
)
}
)
}
}

@Composable
fun DatePicker(
items: List<String>,
items: ImmutableList<String>,
modifier: Modifier = Modifier,
pickerState: PickerState = rememberPickerState(),
startIndex: Int = 0,
Expand All @@ -121,13 +131,18 @@ fun DatePicker(
val scrollState = rememberLazyListState(initialFirstVisibleItemIndex = startIndex)
val flingBehavior = rememberSnapFlingBehavior(lazyListState = scrollState)

LaunchedEffect(itemHeightPixel) {
if (itemHeightPixel > 0) scrollState.scrollToItem(startIndex)
LaunchedEffect(itemHeightPixel, startIndex) {
if (itemHeightPixel > 0 && startIndex >= 0) scrollState.scrollToItem(startIndex)
}

LaunchedEffect(scrollState) {
snapshotFlow { scrollState.firstVisibleItemIndex }
.map { index -> items.getOrNull(index) }
.map { index ->
val hasNullDate =
items.size == (END_YEAR - START_YEAR + 1) || items.size == (END_MONTH - START_MONTH + 1)
val adjustedItems = if (hasNullDate) items + NULL_DATE else items
adjustedItems.getOrNull(index)
}
.distinctUntilChanged()
.collect { item ->
item?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHost
Expand Down Expand Up @@ -309,7 +310,7 @@ private fun MainBottomBar(
fontSize = 9.sp
)
},
colors = androidx.compose.material3.NavigationBarItemDefaults
colors = NavigationBarItemDefaults
.colors(
selectedIconColor = TerningMain,
selectedTextColor = TerningMain,
Expand Down
Loading