diff --git a/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt b/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt index de9bc1c0..fc0108ed 100644 --- a/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt +++ b/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt @@ -1,5 +1,6 @@ package com.terning.feature.calendar.calendar +import androidx.activity.compose.BackHandler import androidx.compose.animation.core.tween import androidx.compose.animation.slideInHorizontally import androidx.compose.animation.slideInVertically @@ -25,17 +26,20 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.terning.core.analytics.EventType import com.terning.core.analytics.LocalTracker import com.terning.core.designsystem.component.topappbar.CalendarTopAppBar +import com.terning.core.designsystem.extension.getWeekIndexContainingSelectedDate import com.terning.core.designsystem.theme.Grey200 import com.terning.core.designsystem.theme.White import com.terning.feature.calendar.calendar.component.ScreenTransition import com.terning.feature.calendar.calendar.component.WeekDaysHeader +import com.terning.feature.calendar.calendar.state.CalendarUiState +import com.terning.feature.calendar.calendar.model.DayModel +import com.terning.feature.calendar.calendar.state.LocalPagerState import com.terning.feature.calendar.calendar.model.TerningCalendarModel.Companion.LocalCalendarModel -import com.terning.feature.calendar.calendar.model.CalendarUiState -import com.terning.feature.calendar.calendar.model.LocalPagerState import com.terning.feature.calendar.list.CalendarListRoute import com.terning.feature.calendar.month.CalendarMonthRoute import com.terning.feature.calendar.week.CalendarWeekRoute import kotlinx.coroutines.launch +import timber.log.Timber import java.time.LocalDate @Composable @@ -72,8 +76,8 @@ fun CalendarRoute( private fun CalendarScreen( uiState: CalendarUiState, navigateToAnnouncement: (Long) -> Unit, - onClickNewDate: (LocalDate) -> Unit, - updateSelectedDate: (LocalDate) -> Unit, + onClickNewDate: (DayModel) -> Unit, + updateSelectedDate: (DayModel) -> Unit, disableListVisibility: () -> Unit, disableWeekVisibility: () -> Unit, onClickListButton: () -> Unit, @@ -86,19 +90,26 @@ private fun CalendarScreen( pageCount = { uiState.calendarModel.pageCount } ) + BackHandler(enabled = uiState.isWeekEnabled) { + disableWeekVisibility() + } + LaunchedEffect(key1 = pagerState, key2 = uiState.selectedDate) { snapshotFlow { pagerState.currentPage } .collect { current -> - //val date = getLocalDateByPage(current) val date = uiState.calendarModel.getLocalDateByPage(current) + val month = uiState.calendarModel.getMonthModelByPage(current) val newDate = LocalDate.of( date.year, date.month, - uiState.selectedDate.dayOfMonth.coerceAtMost(date.month.minLength()) + uiState.selectedDate.date.dayOfMonth.coerceAtMost(date.month.minLength()) ) - updateSelectedDate(newDate) + + val currentWeek = newDate.getWeekIndexContainingSelectedDate(month.inDays) + Timber.tag("WeekIndex").d("In CalendarRoute: ${currentWeek.toString()}") + updateSelectedDate(DayModel(newDate, currentWeek)) } } @@ -165,7 +176,9 @@ private fun CalendarScreen( .fillMaxSize(), navigateUp = disableWeekVisibility, navigateToAnnouncement = navigateToAnnouncement, - updateSelectedDate = onClickNewDate + updateSelectedDate = { + onClickNewDate(it) + } ) } ) diff --git a/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt b/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt index 5280ae0a..f242a954 100644 --- a/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt +++ b/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt @@ -1,14 +1,12 @@ package com.terning.feature.calendar.calendar import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import com.terning.feature.calendar.calendar.model.CalendarUiState +import com.terning.feature.calendar.calendar.model.DayModel +import com.terning.feature.calendar.calendar.state.CalendarUiState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch -import java.time.LocalDate import javax.inject.Inject @HiltViewModel @@ -16,13 +14,9 @@ class CalendarViewModel @Inject constructor() : ViewModel() { private var _uiState: MutableStateFlow = MutableStateFlow(CalendarUiState()) val uiState get() = _uiState.asStateFlow() - fun onSelectNewDate(selectedDate: LocalDate) = viewModelScope.launch { - if (_uiState.value.selectedDate == selectedDate) { - _uiState.update { currentState -> - currentState.copy( - isWeekEnabled = !_uiState.value.isWeekEnabled - ) - } + fun onSelectNewDate(selectedDate: DayModel) { + if (_uiState.value.selectedDate.date == selectedDate.date) { + updateWeekVisibility(!_uiState.value.isWeekEnabled) } else { _uiState.update { currentState -> currentState.copy( @@ -33,27 +27,23 @@ class CalendarViewModel @Inject constructor() : ViewModel() { } } - fun updateSelectedDate(date: LocalDate) = viewModelScope.launch { - _uiState.update { currentState -> + fun updateSelectedDate(value: DayModel) = _uiState.update { currentState -> currentState.copy( - selectedDate = date + selectedDate = value ) } - } - fun updateListVisibility(visibility: Boolean) = viewModelScope.launch { - _uiState.update { currentState -> + + fun updateListVisibility(value: Boolean) = _uiState.update { currentState -> currentState.copy( - isListEnabled = visibility + isListEnabled = value ) } - } - fun updateWeekVisibility(visibility: Boolean) = viewModelScope.launch { - _uiState.update { currentState -> + + fun updateWeekVisibility(value: Boolean) = _uiState.update { currentState -> currentState.copy( - isWeekEnabled = visibility + isWeekEnabled = value ) } - } } \ No newline at end of file diff --git a/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/component/CalendarDay.kt b/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/component/CalendarDay.kt deleted file mode 100644 index c54a3b53..00000000 --- a/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/component/CalendarDay.kt +++ /dev/null @@ -1,101 +0,0 @@ -package com.terning.feature.calendar.calendar.component - -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import com.terning.core.designsystem.extension.noRippleClickable -import com.terning.core.designsystem.theme.Black -import com.terning.core.designsystem.theme.Grey150 -import com.terning.core.designsystem.theme.Grey200 -import com.terning.core.designsystem.theme.TerningMain -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.calendar.calendar.model.DayModel -import java.time.LocalDate - -@Composable -fun CalendarDay( - modifier: Modifier = Modifier, - dayData: DayModel, - isSelected: Boolean, - isToday: Boolean, - onDateSelected: (LocalDate) -> Unit = {} -) { - val backgroundColor = - if (isSelected) - TerningMain - else if (isToday) Grey150 - else Color.Transparent - - val textColor = - if (dayData.isOutDate) - Grey200 - else if (isSelected) - White - else - Black - - - Box( - modifier = modifier, - contentAlignment = Alignment.Center - ) { - Box( - modifier = Modifier - .size(22.dp) - .noRippleClickable { - if (!dayData.isOutDate) { - onDateSelected(dayData.date) - } - } - .background( - color = backgroundColor, - shape = CircleShape - ), - contentAlignment = Alignment.Center - ) { - Text( - text = dayData.date.dayOfMonth.toString(), - color = textColor, - style = TerningTheme.typography.calendar - ) - } - } -} - -@Preview(showBackground = true) -@Composable -fun CalendarDayPreview() { - TerningPointTheme { - Row { - CalendarDay( - dayData = DayModel(LocalDate.now(), 0, false), - isSelected = true, - isToday = true, - onDateSelected = {} - ) - CalendarDay( - dayData = DayModel(LocalDate.now(), 0, false), - isSelected = false, - isToday = true, - onDateSelected = {} - ) - CalendarDay( - dayData = DayModel(LocalDate.now(), 0, false), - isSelected = false, - isToday = false, - onDateSelected = {} - ) - } - } -} \ No newline at end of file diff --git a/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/component/CalendarWeekDaysHeader.kt b/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/component/WeekDaysHeader.kt similarity index 96% rename from feature/calendar/src/main/java/com/terning/feature/calendar/calendar/component/CalendarWeekDaysHeader.kt rename to feature/calendar/src/main/java/com/terning/feature/calendar/calendar/component/WeekDaysHeader.kt index 0bb06085..be398b0c 100644 --- a/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/component/CalendarWeekDaysHeader.kt +++ b/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/component/WeekDaysHeader.kt @@ -19,7 +19,7 @@ import com.terning.core.designsystem.theme.TerningTheme import com.terning.feature.calendar.R @Composable -fun CalendarWeekDaysHeader( +fun WeekDaysHeader( modifier: Modifier = Modifier, ) { Row( @@ -56,6 +56,6 @@ fun CalendarWeekDaysHeader( @Composable fun WeekDaysHeaderPreview() { TerningPointTheme { - CalendarWeekDaysHeader() + WeekDaysHeader() } } \ No newline at end of file diff --git a/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt b/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/state/CalendarUiState.kt similarity index 55% rename from feature/calendar/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt rename to feature/calendar/src/main/java/com/terning/feature/calendar/calendar/state/CalendarUiState.kt index 5aa07853..065c1b3c 100644 --- a/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt +++ b/feature/calendar/src/main/java/com/terning/feature/calendar/calendar/state/CalendarUiState.kt @@ -1,14 +1,15 @@ -package com.terning.feature.calendar.calendar.model +package com.terning.feature.calendar.calendar.state import androidx.compose.foundation.pager.PagerState import androidx.compose.runtime.compositionLocalOf -import java.time.LocalDate +import com.terning.feature.calendar.calendar.model.DayModel +import com.terning.feature.calendar.calendar.model.TerningCalendarModel data class CalendarUiState( - val selectedDate: LocalDate = LocalDate.now(), + val selectedDate: DayModel = DayModel(), val calendarModel: TerningCalendarModel = TerningCalendarModel(), val isListEnabled: Boolean = false, - val isWeekEnabled: Boolean = false + val isWeekEnabled: Boolean = false, ) val LocalPagerState = compositionLocalOf { diff --git a/feature/calendar/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt b/feature/calendar/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt index 48fc90ce..9d3028e5 100644 --- a/feature/calendar/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt +++ b/feature/calendar/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt @@ -39,7 +39,7 @@ import com.terning.core.designsystem.theme.TerningTheme import com.terning.domain.calendar.entity.CalendarScrapDetail import com.terning.feature.calendar.R import com.terning.feature.calendar.calendar.model.TerningCalendarModel.Companion.LocalCalendarModel -import com.terning.feature.calendar.calendar.model.LocalPagerState +import com.terning.feature.calendar.calendar.state.LocalPagerState import com.terning.feature.calendar.list.component.CalendarScrapList import com.terning.feature.calendar.list.model.CalendarListUiState import com.terning.feature.dialog.cancel.ScrapCancelDialog diff --git a/feature/calendar/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt b/feature/calendar/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt index 57e0d46b..bc81132c 100644 --- a/feature/calendar/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt +++ b/feature/calendar/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt @@ -1,8 +1,5 @@ package com.terning.feature.calendar.month -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.pager.HorizontalPager -import androidx.compose.foundation.pager.PagerState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -13,18 +10,18 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.flowWithLifecycle -import com.terning.core.designsystem.state.UiState import com.terning.core.designsystem.extension.toast +import com.terning.core.designsystem.state.UiState +import com.terning.domain.calendar.entity.CalendarScrap +import com.terning.feature.calendar.calendar.model.DayModel +import com.terning.feature.calendar.calendar.state.LocalPagerState import com.terning.feature.calendar.calendar.model.TerningCalendarModel.Companion.LocalCalendarModel -import com.terning.feature.calendar.calendar.model.LocalPagerState -import com.terning.feature.calendar.month.component.CalendarMonth -import com.terning.feature.calendar.month.model.CalendarMonthUiState -import java.time.LocalDate +import com.terning.feature.calendar.month.component.CalendarMonthPager @Composable fun CalendarMonthRoute( - selectedDate: LocalDate, - updateSelectedDate: (LocalDate) -> Unit, + selectedDate: DayModel, + updateSelectedDate: (DayModel) -> Unit, modifier: Modifier = Modifier, viewModel: CalendarMonthViewModel = hiltViewModel() ) { @@ -32,7 +29,7 @@ fun CalendarMonthRoute( val pagerState = LocalPagerState.current val context = LocalContext.current val lifecycleOwner = LocalLifecycleOwner.current - val monthUiState by viewModel.uiState.collectAsStateWithLifecycle(lifecycleOwner) + val uiState by viewModel.uiState.collectAsStateWithLifecycle(lifecycleOwner) LaunchedEffect(viewModel.sideEffect, lifecycleOwner) { viewModel.sideEffect.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle) @@ -45,51 +42,26 @@ fun CalendarMonthRoute( LaunchedEffect(key1 = pagerState) { snapshotFlow { pagerState.currentPage } - .collect { currentPage-> + .collect { currentPage -> val localDate = calendarModel.getLocalDateByPage(currentPage) viewModel.getScrapMonth(localDate) } } - CalendarMonthScreen( + CalendarMonthPager( + modifier = modifier, pagerState = pagerState, + calendarModel = calendarModel, selectedDate = selectedDate, - uiState = monthUiState, - updateSelectedDate = updateSelectedDate, - modifier = modifier + onDateSelect = updateSelectedDate, + isWeekEnabled = false, + scrapMap = when (uiState.loadState) { + UiState.Loading -> emptyMap() + UiState.Empty -> emptyMap() + is UiState.Failure -> emptyMap() + is UiState.Success -> (uiState.loadState as UiState.Success>>).data + }, ) } -@Composable -private fun CalendarMonthScreen( - pagerState: PagerState, - selectedDate: LocalDate, - uiState: CalendarMonthUiState, - updateSelectedDate: (LocalDate) -> Unit, - modifier: Modifier = Modifier, -) { - val calendarModel = LocalCalendarModel.current - - HorizontalPager( - state = pagerState, - modifier = modifier.fillMaxSize() - ) { page -> - val monthModel = calendarModel.getMonthModelByPage(page = page) - - CalendarMonth( - modifier = Modifier.fillMaxSize(), - onDateSelected = updateSelectedDate, - monthModel = monthModel, - selectedDate = selectedDate, - isWeekEnabled = false, - scrapMap = when (uiState.loadState) { - UiState.Loading -> emptyMap() - UiState.Empty -> emptyMap() - is UiState.Failure -> emptyMap() - is UiState.Success -> uiState.loadState.data - }, - ) - } -} - diff --git a/feature/calendar/src/main/java/com/terning/feature/calendar/month/component/CalendarMonth.kt b/feature/calendar/src/main/java/com/terning/feature/calendar/month/component/CalendarMonth.kt deleted file mode 100644 index dbd28710..00000000 --- a/feature/calendar/src/main/java/com/terning/feature/calendar/month/component/CalendarMonth.kt +++ /dev/null @@ -1,95 +0,0 @@ -package com.terning.feature.calendar.month.component - -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.HorizontalDivider -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import com.terning.core.designsystem.extension.getDateAsMapString -import com.terning.core.designsystem.extension.isToday -import com.terning.core.designsystem.extension.noRippleClickable -import com.terning.core.designsystem.theme.Grey150 -import com.terning.core.designsystem.theme.TerningPointTheme -import com.terning.domain.calendar.entity.CalendarScrap -import com.terning.feature.calendar.calendar.component.CalendarDay -import com.terning.feature.calendar.calendar.model.MonthModel -import java.time.LocalDate -import java.time.YearMonth - -@Composable -internal fun CalendarMonth( - isWeekEnabled: Boolean, - monthModel: MonthModel, - onDateSelected: (LocalDate) -> Unit, - selectedDate: LocalDate, - modifier: Modifier = Modifier, - scrapMap: Map> = mapOf() -) { - Column( - modifier = modifier - .fillMaxSize() - .padding(horizontal = 20.dp), - ) { - val month = monthModel.calendarMonth - for (week in month) { - Row( - modifier = Modifier.weight(1f), - ) { - for (day in week) { - Column( - modifier = Modifier - .weight(1f) - .fillMaxSize() - .noRippleClickable { - if(!day.isOutDate) { - onDateSelected(day.date) - } - } - .padding(top = 15.dp), - horizontalAlignment = Alignment.CenterHorizontally - ) { - CalendarDay( - dayData = day, - isSelected = selectedDate == day.date && isWeekEnabled, - isToday = day.date.isToday(), - onDateSelected = onDateSelected - ) - if (!day.isOutDate) { - val index = day.date.getDateAsMapString() - CalendarMonthScrap( - weekCount = month.size, - scrapLists = scrapMap[index].orEmpty(), - modifier = Modifier.fillMaxWidth() - ) - } - } - } - } - if (month.indexOf(week) != month.lastIndex) { - HorizontalDivider( - thickness = 1.dp, - color = Grey150 - ) - } - } - } -} - -@Preview(showBackground = true) -@Composable -private fun CalendarMonthPreview() { - TerningPointTheme { - CalendarMonth( - monthModel = MonthModel(YearMonth.now()), - onDateSelected = {}, - selectedDate = LocalDate.now(), - isWeekEnabled = true - ) - } -} \ No newline at end of file diff --git a/feature/calendar/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt b/feature/calendar/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt index 799a918d..ac689e2f 100644 --- a/feature/calendar/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt +++ b/feature/calendar/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt @@ -47,10 +47,12 @@ import com.terning.core.designsystem.theme.TerningTheme import com.terning.core.designsystem.theme.White import com.terning.domain.calendar.entity.CalendarScrapDetail import com.terning.feature.calendar.R -import com.terning.feature.calendar.calendar.model.CalendarUiState -import com.terning.feature.calendar.calendar.model.LocalPagerState +import com.terning.feature.calendar.calendar.state.CalendarUiState +import com.terning.feature.calendar.calendar.model.DayModel +import com.terning.feature.calendar.calendar.state.LocalPagerState +import com.terning.feature.calendar.calendar.model.TerningCalendarModel import com.terning.feature.calendar.list.component.CalendarScrapList -import com.terning.feature.calendar.week.component.HorizontalCalendarWeek +import com.terning.feature.calendar.week.component.CalendarWeekPager import com.terning.feature.calendar.week.model.CalendarWeekUiState import com.terning.feature.dialog.cancel.ScrapCancelDialog import com.terning.feature.dialog.detail.ScrapDialog @@ -61,7 +63,7 @@ import java.time.LocalDate fun CalendarWeekRoute( calendarUiState: CalendarUiState, navigateToAnnouncement: (Long) -> Unit, - updateSelectedDate: (LocalDate) -> Unit, + updateSelectedDate: (DayModel) -> Unit, navigateUp: () -> Unit, modifier: Modifier = Modifier, viewModel: CalendarWeekViewModel = hiltViewModel(), @@ -81,7 +83,7 @@ fun CalendarWeekRoute( } LaunchedEffect(key1 = calendarUiState.selectedDate) { - viewModel.getScrapWeekList(selectedDate = calendarUiState.selectedDate) + viewModel.getScrapWeekList(selectedDate = calendarUiState.selectedDate.date) } BackHandler { @@ -91,6 +93,7 @@ fun CalendarWeekRoute( CalendarWeekScreen( modifier = modifier, pagerState = pagerState, + calendarModel = calendarUiState.calendarModel, uiState = uiState, selectedDate = calendarUiState.selectedDate, updateSelectedDate = updateSelectedDate, @@ -109,7 +112,7 @@ fun CalendarWeekRoute( ) CalendarWeekScrapPatchDialog( - currentDate = calendarUiState.selectedDate, + currentDate = calendarUiState.selectedDate.date, dialogVisibility = uiState.scrapDetailDialogVisibility, internshipModel = uiState.internshipModel, navigateToAnnouncement = { announcementId -> @@ -118,7 +121,7 @@ fun CalendarWeekRoute( }, onDismissInternDialog = { viewModel.updateScrapDetailDialogVisibility(false) }, onClickChangeColor = { - viewModel.getScrapWeekList(calendarUiState.selectedDate) + viewModel.getScrapWeekList(calendarUiState.selectedDate.date) }, ) @@ -128,7 +131,7 @@ fun CalendarWeekRoute( onDismissCancelDialog = { isCancelled -> viewModel.updateScrapCancelDialogVisibility(false) if (isCancelled) { - viewModel.getScrapWeekList(calendarUiState.selectedDate) + viewModel.getScrapWeekList(calendarUiState.selectedDate.date) } } ) @@ -137,9 +140,10 @@ fun CalendarWeekRoute( @Composable private fun CalendarWeekScreen( uiState: CalendarWeekUiState, + calendarModel: TerningCalendarModel, pagerState: PagerState, - selectedDate: LocalDate, - updateSelectedDate: (LocalDate) -> Unit, + selectedDate: DayModel, + updateSelectedDate: (DayModel) -> Unit, onClickInternship: (CalendarScrapDetail) -> Unit, onClickScrapButton: (Long) -> Unit, modifier: Modifier = Modifier, @@ -169,11 +173,10 @@ private fun CalendarWeekScreen( ), shape = RoundedCornerShape(bottomStart = 20.dp, bottomEnd = 20.dp), ) { - HorizontalCalendarWeek( + CalendarWeekPager( + monthModel = calendarModel.getMonthModelByPage(selectedDate.date), selectedDate = selectedDate, - onDateSelected = updateSelectedDate, - modifier = Modifier - .fillMaxWidth() + onDateSelect = updateSelectedDate, ) Spacer( @@ -195,7 +198,7 @@ private fun CalendarWeekScreen( horizontalAlignment = Alignment.CenterHorizontally ) { Text( - text = selectedDate.getDateStringInKorean(), + text = selectedDate.date.getDateStringInKorean(), style = TerningTheme.typography.title5, color = Black, modifier = Modifier diff --git a/feature/calendar/src/main/java/com/terning/feature/calendar/week/component/HorizontalCalendarWeek.kt b/feature/calendar/src/main/java/com/terning/feature/calendar/week/component/HorizontalCalendarWeek.kt deleted file mode 100644 index efb4515e..00000000 --- a/feature/calendar/src/main/java/com/terning/feature/calendar/week/component/HorizontalCalendarWeek.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.terning.feature.calendar.week.component - -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyRow -import androidx.compose.foundation.lazy.items -import androidx.compose.foundation.pager.HorizontalPager -import androidx.compose.foundation.pager.rememberPagerState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp -import com.terning.core.designsystem.extension.getWeekIndexContainingSelectedDate -import com.terning.core.designsystem.extension.isToday -import com.terning.feature.calendar.calendar.component.CalendarDay -import com.terning.feature.calendar.calendar.model.TerningCalendarModel.Companion.LocalCalendarModel -import java.time.LocalDate - -@Composable -fun HorizontalCalendarWeek( - selectedDate: LocalDate, - onDateSelected: (LocalDate) -> Unit, - modifier: Modifier = Modifier -) { - val calendarModel = LocalCalendarModel.current - - val monthModel = calendarModel.getMonthModelByPage(selectedDate) - val currentWeek = selectedDate.getWeekIndexContainingSelectedDate(monthModel.inDays) - - val pagerState = rememberPagerState( - initialPage = currentWeek, - pageCount = { monthModel.totalDays / 7 } - ) - - LaunchedEffect(selectedDate) { - pagerState.animateScrollToPage(selectedDate.getWeekIndexContainingSelectedDate(monthModel.inDays)) - } - - HorizontalPager( - modifier = modifier, - state = pagerState - ) { page -> - LazyRow( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 32.dp, vertical = 20.dp), - horizontalArrangement = Arrangement.SpaceBetween - ) { - items(items = monthModel.calendarMonth[page]) { day -> - CalendarDay( - dayData = day, - isSelected = day.date == selectedDate, - isToday = day.date.isToday(), - onDateSelected = onDateSelected - ) - } - } - } -} \ No newline at end of file