Skip to content

Commit

Permalink
[MERGE] #309 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#309] ํ™ˆ ํ•„ํ„ฐ๋ง ์žฌ์„ค์ • ๋ทฐ / ๋ฐ์ดํŠธ ํ”ผ์ปค ๋น„ํ™œ์„ฑํ™” ์•„์ดํ…œ ์ถ”๊ฐ€
  • Loading branch information
leeeyubin authored Dec 23, 2024
2 parents 37d01e0 + f34da9a commit 916b2da
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 39 deletions.
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

0 comments on commit 916b2da

Please sign in to comment.