Skip to content

Commit

Permalink
[UI/#37] 월간-주간-목록 전환 흐름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
boiledEgg-s committed Jul 11, 2024
1 parent 40c8e0f commit a123cf2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -96,7 +96,7 @@ fun CalendarTopBar(
@Composable
fun CalendarTopBarPreview() {
TerningPointTheme {
CalendarTopBar(
CalendarTopAppBar(
date = LocalDate.now(),
isListExpanded = false,
isWeekExpanded = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Scrap>>
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@ 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

@Composable
fun CalendarWeek(
selectedDate: SelectedDateState,
modifier: Modifier = Modifier,
scrapLists: List<List<Scrap>> = 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 ->
Expand Down

0 comments on commit a123cf2

Please sign in to comment.