diff --git a/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopBar.kt b/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt similarity index 96% rename from core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopBar.kt rename to core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt index d49b62700..a18a80fa6 100644 --- a/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopBar.kt +++ b/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt @@ -26,7 +26,7 @@ import com.terning.core.extension.noRippleClickable import java.time.LocalDate @Composable -fun CalendarTopBar( +fun CalendarTopAppBar( modifier: Modifier = Modifier, date: LocalDate, isWeekExpanded: Boolean, @@ -49,7 +49,7 @@ fun CalendarTopBar( modifier = Modifier.align(Alignment.Center), verticalAlignment = Alignment.CenterVertically ) { - if(!isWeekExpanded) { + if(!isWeekExpanded || isListExpanded) { Icon( painter = painterResource(id = R.drawable.ic_calendar_previous), contentDescription = stringResource(id = R.string.calendar_button_description_previous), @@ -63,7 +63,7 @@ fun CalendarTopBar( color = Black, modifier = Modifier.padding(horizontal = 8.dp) ) - if(!isWeekExpanded) { + if(!isWeekExpanded || isListExpanded) { Icon( painter = painterResource(id = R.drawable.ic_calendar_next), contentDescription = stringResource(id = R.string.calendar_button_description_next), @@ -96,7 +96,7 @@ fun CalendarTopBar( @Composable fun CalendarTopBarPreview() { TerningPointTheme { - CalendarTopBar( + CalendarTopAppBar( date = LocalDate.now(), isListExpanded = false, isWeekExpanded = false diff --git a/core/src/main/java/com/terning/core/extension/LocalDateExt.kt b/core/src/main/java/com/terning/core/extension/LocalDateExt.kt index 31d49e9ce..ae9e81f13 100644 --- a/core/src/main/java/com/terning/core/extension/LocalDateExt.kt +++ b/core/src/main/java/com/terning/core/extension/LocalDateExt.kt @@ -10,6 +10,6 @@ fun LocalDate.getStringAsTitle(): String = fun LocalDate.getDateStringInKorean(): String = "${monthValue}월 ${dayOfMonth}일 ${dayOfWeek.getDisplayName(TextStyle.FULL, Locale.KOREAN)}" -fun LocalDate.getWeekIndexContainingSelectedDate(): Int = dayOfMonth / 7 +fun LocalDate.getWeekIndexContainingSelectedDate(inDays: Int): Int = (inDays + dayOfMonth) / 7 fun LocalDate.isToday(): Boolean = this == LocalDate.now() \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt index ef33b56c8..661e303bf 100644 --- a/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt +++ b/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarRoute.kt @@ -31,7 +31,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.terning.core.designsystem.component.topappbar.CalendarTopBar +import com.terning.core.designsystem.component.topappbar.CalendarTopAppBar import com.terning.core.designsystem.theme.Grey200 import com.terning.feature.R import com.terning.feature.calendar.calendar.component.WeekDaysHeader @@ -84,11 +84,15 @@ fun CalendarScreen( modifier = modifier, topBar = { val coroutineScope = rememberCoroutineScope() - CalendarTopBar( + CalendarTopAppBar( date = currentDate, isListExpanded = isListExpanded, isWeekExpanded = selectedDate.isEnabled, - onListButtonClicked = { isListExpanded = !isListExpanded }, + onListButtonClicked = { + isListExpanded = !isListExpanded + if(selectedDate.isEnabled){ + viewModel.disableWeekCalendar() + } }, onMonthNavigationButtonClicked = { direction -> coroutineScope.launch { listState.animateScrollToItem( diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt index 0d90b33ed..15a33ddf9 100644 --- a/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt +++ b/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarViewModel.kt @@ -39,15 +39,20 @@ class CalendarViewModel @Inject constructor( ) } } else { - _selectedDate.update { currentState -> - currentState.copy( - selectedDate = date, - isEnabled = !_selectedDate.value.isEnabled - ) - } + disableWeekCalendar() } } + fun disableWeekCalendar() { + _selectedDate.update { currentState -> + currentState.copy( + isEnabled = false + ) + } + } + + + //To be erased in future val mockScrapList: List> get() { diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarWeek.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarWeek.kt index 64a2c162d..409b5949c 100644 --- a/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarWeek.kt +++ b/feature/src/main/java/com/terning/feature/calendar/calendar/CalendarWeek.kt @@ -15,6 +15,7 @@ import com.terning.core.extension.isToday import com.terning.feature.calendar.models.MonthData import com.terning.feature.calendar.models.Scrap import com.terning.feature.calendar.models.SelectedDateState +import timber.log.Timber import java.time.LocalDate import java.time.YearMonth @@ -22,18 +23,20 @@ import java.time.YearMonth fun CalendarWeek( selectedDate: SelectedDateState, modifier: Modifier = Modifier, - scrapLists: List> = listOf(), onDateSelected: (LocalDate) -> Unit = {} ) { val date = selectedDate.selectedDate val monthData = MonthData(YearMonth.of(date.year, date.monthValue)) - val currentWeek = date.getWeekIndexContainingSelectedDate() + val currentWeek = date.getWeekIndexContainingSelectedDate(monthData.inDays) val pagerState = rememberPagerState ( initialPage = currentWeek, pageCount = {monthData.totalDays / 7} ) + Timber.tag("CalendarScreen") + .d("currentWeek:$currentWeek, totalDays: ${monthData.totalDays}, ${monthData.totalDays / 7}") + HorizontalPager( modifier = modifier, state = pagerState) { page ->