From 5c7cfc3da1ca5027ab6f8fee395a82e72adb2cef Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 13 Sep 2024 17:37:19 +0900 Subject: [PATCH 01/15] =?UTF-8?q?[FIX/#246]=20=EB=82=A0=EC=A7=9C=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=8B=9C=EC=A0=90=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terning/feature/calendar/calendar/CalendarRoute.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 d173cbd4b..053a40a27 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 @@ -8,10 +8,8 @@ import androidx.compose.animation.togetherWith import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -80,10 +78,12 @@ private fun CalendarScreen( ) LaunchedEffect(key1 = listState) { - snapshotFlow { listState.firstVisibleItemIndex } + snapshotFlow { listState.firstVisibleItemIndex to listState.firstVisibleItemScrollOffset} .distinctUntilChanged() - .collect { - updatePage(listState.firstVisibleItemIndex) + .collect { (index, offset) -> + if (offset == 0) { + updatePage(index) + } } } From d8461dfe33fd83168111335cd21accfe71bdb227 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 13 Sep 2024 17:38:46 +0900 Subject: [PATCH 02/15] =?UTF-8?q?[DEL/#246]=20=EB=A1=9C=EB=94=A9=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=EB=B7=B0=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/list/CalendarListScreen.kt | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt index 6e145abbc..4f32f527c 100644 --- a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt @@ -151,24 +151,7 @@ private fun CalendarListScreen( .background(Back) ) { when (uiState.loadState) { - UiState.Loading -> { - item { - Box( - modifier = Modifier.fillMaxSize(), - contentAlignment = Alignment.Center - ) { - Text( - modifier = Modifier - .padding(top = 42.dp) - .fillMaxWidth(), - text = stringResource(id = R.string.calendar_text_friday), - textAlign = TextAlign.Center, - style = TerningTheme.typography.body5, - color = Grey400 - ) - } - } - } + UiState.Loading -> {} UiState.Empty -> { item { Column( From 7bf4b6c480ddff12a288c41cc9a007ae6bff0e48 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 13 Sep 2024 22:20:40 +0900 Subject: [PATCH 03/15] =?UTF-8?q?[FEAT/#246]=20PagerState=20=EB=8F=84?= =?UTF-8?q?=EC=9E=85,=20=EC=9B=94=EA=B0=84=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/calendar/CalendarRoute.kt | 159 ++++++++++-------- .../calendar/model/CalendarUiState.kt | 6 + .../calendar/month/CalendarMonthScreen.kt | 100 ++++------- 3 files changed, 128 insertions(+), 137 deletions(-) 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 053a40a27..5f14289ea 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 @@ -9,8 +9,10 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberCoroutineScope @@ -27,6 +29,7 @@ import com.terning.feature.calendar.calendar.component.ScreenTransition import com.terning.feature.calendar.calendar.component.WeekDaysHeader import com.terning.feature.calendar.calendar.model.CalendarModel.Companion.getYearMonthByPage 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 @@ -73,6 +76,18 @@ private fun CalendarScreen( ) { val coroutineScope = rememberCoroutineScope() + val pagerState = rememberPagerState( + initialPage = uiState.calendarModel.initialPage, + pageCount = { uiState.calendarModel.pageCount } + ) + + LaunchedEffect(key1 = pagerState) { + snapshotFlow { pagerState.currentPage} + .collect { current -> + updatePage(current) + } + } + val listState = rememberLazyListState( initialFirstVisibleItemIndex = uiState.calendarModel.initialPage ) @@ -87,81 +102,83 @@ private fun CalendarScreen( } } - Column( - modifier = modifier, - ){ - CalendarTopAppBar( - date = getYearMonthByPage(uiState.currentPage), - isListExpanded = uiState.isListEnabled, - isWeekExpanded = uiState.isWeekEnabled, - onListButtonClicked = onClickListButton, - onMonthNavigationButtonClicked = { direction -> - coroutineScope.launch { - listState.animateScrollToItem( - index = listState.firstVisibleItemIndex + direction, - ) + CompositionLocalProvider( + LocalPagerState provides pagerState + ) { + Column( + modifier = modifier, + ) { + CalendarTopAppBar( + date = getYearMonthByPage(uiState.currentPage), + isListExpanded = uiState.isListEnabled, + isWeekExpanded = uiState.isWeekEnabled, + onListButtonClicked = onClickListButton, + onMonthNavigationButtonClicked = { direction -> + coroutineScope.launch { + listState.animateScrollToItem( + index = listState.firstVisibleItemIndex + direction, + ) + } } - } - ) - ScreenTransition( - targetState = !uiState.isListEnabled, - transitionOne = slideInHorizontally { fullWidth -> -fullWidth } togetherWith - slideOutHorizontally { fullWidth -> fullWidth }, - transitionTwo = slideInHorizontally { fullWidth -> fullWidth } togetherWith - slideOutHorizontally { fullWidth -> -fullWidth }, - contentOne = { - Column( - modifier = Modifier - .fillMaxSize() - ) { - WeekDaysHeader() + ) + ScreenTransition( + targetState = !uiState.isListEnabled, + transitionOne = slideInHorizontally { fullWidth -> -fullWidth } togetherWith + slideOutHorizontally { fullWidth -> fullWidth }, + transitionTwo = slideInHorizontally { fullWidth -> fullWidth } togetherWith + slideOutHorizontally { fullWidth -> -fullWidth }, + contentOne = { + Column( + modifier = Modifier + .fillMaxSize() + ) { + WeekDaysHeader() - HorizontalDivider( - thickness = 1.dp, - color = Grey200 - ) + HorizontalDivider( + thickness = 1.dp, + color = Grey200 + ) - ScreenTransition( - targetState = !uiState.isWeekEnabled, - transitionOne = slideInVertically { fullHeight -> -fullHeight } togetherWith - slideOutVertically { fullHeight -> fullHeight }, - transitionTwo = slideInVertically { fullHeight -> fullHeight } togetherWith - slideOutVertically { fullHeight -> -fullHeight }, - contentOne = { - CalendarMonthRoute( - listState = listState, - pages = uiState.calendarModel.pageCount, - selectedDate = uiState.selectedDate, - updateSelectedDate = updateSelectedDate, - modifier = Modifier - .fillMaxSize() - .background(White), - ) - }, - contentTwo = { - CalendarWeekRoute( - calendarUiState = uiState, - modifier = Modifier - .fillMaxSize(), - navigateUp = disableWeekVisibility, - navigateToAnnouncement = navigateToAnnouncement, - updateSelectedDate = updateSelectedDate - ) - } + ScreenTransition( + targetState = !uiState.isWeekEnabled, + transitionOne = slideInVertically { fullHeight -> -fullHeight } togetherWith + slideOutVertically { fullHeight -> fullHeight }, + transitionTwo = slideInVertically { fullHeight -> fullHeight } togetherWith + slideOutVertically { fullHeight -> -fullHeight }, + contentOne = { + CalendarMonthRoute( + selectedDate = uiState.selectedDate, + updateSelectedDate = updateSelectedDate, + modifier = Modifier + .fillMaxSize() + .background(White), + ) + }, + contentTwo = { + CalendarWeekRoute( + calendarUiState = uiState, + modifier = Modifier + .fillMaxSize(), + navigateUp = disableWeekVisibility, + navigateToAnnouncement = navigateToAnnouncement, + updateSelectedDate = updateSelectedDate + ) + } + ) + } + }, + contentTwo = { + CalendarListRoute( + listState = listState, + pages = uiState.calendarModel.pageCount, + navigateToAnnouncement = navigateToAnnouncement, + navigateUp = disableListVisibility, + modifier = Modifier + .fillMaxSize() ) - } - }, - contentTwo = { - CalendarListRoute( - listState = listState, - pages = uiState.calendarModel.pageCount, - navigateToAnnouncement = navigateToAnnouncement, - navigateUp = disableListVisibility, - modifier = Modifier - .fillMaxSize() - ) - }, - ) + }, + ) + } } } diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt index e4d75e7ef..4e84cb41c 100644 --- a/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt +++ b/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt @@ -1,5 +1,7 @@ package com.terning.feature.calendar.calendar.model +import androidx.compose.foundation.pager.PagerState +import androidx.compose.runtime.compositionLocalOf import java.time.LocalDate data class CalendarUiState( @@ -9,3 +11,7 @@ data class CalendarUiState( val isListEnabled: Boolean = false, val isWeekEnabled: Boolean = false ) + +val LocalPagerState = compositionLocalOf { + error("No PagerState provided") +} diff --git a/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt b/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt index 5ebbabdd4..f2a5a01c5 100644 --- a/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt @@ -1,7 +1,8 @@ package com.terning.feature.calendar.month -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.foundation.lazy.LazyRow +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 @@ -14,25 +15,23 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.flowWithLifecycle import com.terning.core.extension.toast import com.terning.core.state.UiState -import com.terning.domain.entity.calendar.CalendarScrap -import com.terning.feature.calendar.calendar.model.CalendarDefaults.flingBehavior import com.terning.feature.calendar.calendar.model.CalendarModel.Companion.getLocalDateByPage -import com.terning.feature.calendar.month.model.MonthModel +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 kotlinx.coroutines.flow.distinctUntilChanged +import com.terning.feature.calendar.month.model.MonthModel +import timber.log.Timber import java.time.LocalDate import java.time.YearMonth @Composable fun CalendarMonthRoute( - listState: LazyListState, - pages: Int, selectedDate: LocalDate, updateSelectedDate: (LocalDate) -> Unit, modifier: Modifier = Modifier, viewModel: CalendarMonthViewModel = hiltViewModel() ) { + val pagerState = LocalPagerState.current val context = LocalContext.current val lifecycleOwner = LocalLifecycleOwner.current val monthUiState by viewModel.uiState.collectAsStateWithLifecycle(lifecycleOwner) @@ -46,21 +45,19 @@ fun CalendarMonthRoute( } } - LaunchedEffect(key1 = listState) { - snapshotFlow { listState.firstVisibleItemIndex } - .distinctUntilChanged() - .collect { - val page = listState.firstVisibleItemIndex - val date = getLocalDateByPage(page) + LaunchedEffect(key1 = pagerState) { + snapshotFlow { pagerState.settledPage } + .collect { settled-> + val date = getLocalDateByPage(settled) viewModel.getScrapMonth(date.year, date.monthValue) + Timber.tag("Calendar").d("MonthAPI date:${date} ") } } CalendarMonthScreen( + pagerState = pagerState, selectedDate = selectedDate, - calendarMonthUiState = monthUiState, - listState = listState, - pages = pages, + uiState = monthUiState, updateSelectedDate = updateSelectedDate, modifier = modifier ) @@ -68,62 +65,33 @@ fun CalendarMonthRoute( @Composable private fun CalendarMonthScreen( - listState: LazyListState, - calendarMonthUiState: CalendarMonthUiState, - pages: Int, + pagerState: PagerState, selectedDate: LocalDate, + uiState: CalendarMonthUiState, updateSelectedDate: (LocalDate) -> Unit, modifier: Modifier = Modifier, ) { - when (calendarMonthUiState.loadState) { - UiState.Loading -> {} - UiState.Empty -> {} - is UiState.Failure -> {} - is UiState.Success -> { - val scrapMap = calendarMonthUiState.loadState.data - MonthSuccessScreen( - pages = pages, - listState = listState, - scrapMap = scrapMap, - onDateSelected = updateSelectedDate, - selectedDate = selectedDate, - modifier = modifier - ) - } - } -} + HorizontalPager( + state = pagerState, + modifier = modifier.fillMaxSize() + ) {page -> + val date = getLocalDateByPage(page) + val monthModel = MonthModel(YearMonth.of(date.year, date.month)) -@Composable -private fun MonthSuccessScreen( - pages: Int, - listState: LazyListState, - selectedDate: LocalDate, - scrapMap: Map>, - onDateSelected: (LocalDate) -> Unit, - modifier: Modifier = Modifier, -) { - LazyRow( - modifier = modifier, - state = listState, - userScrollEnabled = true, - flingBehavior = flingBehavior( - state = listState + 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 + }, ) - ) { - items(pages) { page -> - val date = getLocalDateByPage(page) - val monthModel = MonthModel(YearMonth.of(date.year, date.month)) - - CalendarMonth( - modifier = Modifier.fillParentMaxSize(), - onDateSelected = onDateSelected, - monthModel = monthModel, - scrapMap = scrapMap, - selectedDate = selectedDate, - isWeekEnabled = false - ) - } } } From b0eb8752cd8a487886ae9ffd6f5c5a8a825ad2ee Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 13 Sep 2024 22:33:52 +0900 Subject: [PATCH 04/15] =?UTF-8?q?[MOD/#246]=20Dialog,=20List=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/list/CalendarListScreen.kt | 128 +++++++++++------- 1 file changed, 78 insertions(+), 50 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt index 4f32f527c..2c9dd57a6 100644 --- a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt @@ -29,6 +29,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.flowWithLifecycle +import com.google.devtools.ksp.symbol.Visibility import com.terning.core.designsystem.theme.Back import com.terning.core.designsystem.theme.Black import com.terning.core.designsystem.theme.Grey400 @@ -91,20 +92,9 @@ fun CalendarListRoute( listState = listState, uiState = uiState, modifier = modifier, - navigateToAnnouncement = { announcementId -> - navigateToAnnouncement(announcementId) - viewModel.updateInternDialogVisibility(false) - }, - onDismissCancelDialog = { isCancelled -> - viewModel.updateScrapCancelDialogVisibility(false) - if (isCancelled) { viewModel.getScrapMonthList(uiState.currentDate) } - }, - onDismissInternDialog = { viewModel.updateInternDialogVisibility(false) }, - onClickChangeColor = { - viewModel.getScrapMonthList(uiState.currentDate) - }, + onClickScrapButton = { scrapId -> - with(viewModel){ + with(viewModel) { updateAnnouncementId(scrapId) updateScrapCancelDialogVisibility(true) } @@ -116,6 +106,31 @@ fun CalendarListRoute( } } ) + + CalendarListScrapPatchDialog( + currentDate = uiState.currentDate, + dialogVisibility = uiState.internDialogVisibility, + internshipModel = uiState.internshipModel, + navigateToAnnouncement = { announcementId -> + navigateToAnnouncement(announcementId) + viewModel.updateInternDialogVisibility(false) + }, + onDismissInternDialog = { viewModel.updateInternDialogVisibility(false) }, + onClickChangeColor = { + viewModel.getScrapMonthList(uiState.currentDate) + }, + ) + + CalendarListScrapCancelDialog( + scrapVisibility = uiState.scrapDialogVisibility, + internshipAnnouncementId = uiState.internshipAnnouncementId, + onDismissCancelDialog = { isCancelled -> + viewModel.updateScrapCancelDialogVisibility(false) + if (isCancelled) { + viewModel.getScrapMonthList(uiState.currentDate) + } + } + ) } @Composable @@ -123,10 +138,6 @@ private fun CalendarListScreen( pages: Int, listState: LazyListState, uiState: CalendarListUiState, - navigateToAnnouncement: (Long) -> Unit, - onDismissCancelDialog: (Boolean) -> Unit, - onDismissInternDialog: () -> Unit, - onClickChangeColor: () -> Unit, onClickInternship: (CalendarScrapDetail) -> Unit, onClickScrapButton: (Long) -> Unit, modifier: Modifier = Modifier @@ -167,7 +178,8 @@ private fun CalendarListScreen( is UiState.Success -> { val scrapMap = uiState.loadState.data items(getDate.lengthOfMonth()) { day -> - val currentDate = LocalDate.of(getDate.year, getDate.monthValue, day + 1) + val currentDate = + LocalDate.of(getDate.year, getDate.monthValue, day + 1) val dateInKorean = currentDate.getFullDateStringInKorean() if (scrapMap[dateInKorean].isListNotEmpty()) { @@ -198,37 +210,7 @@ private fun CalendarListScreen( } } - if (uiState.scrapDialogVisibility) { - uiState.internshipAnnouncementId?.run { - ScrapCancelDialog( - internshipAnnouncementId = this, - onDismissRequest = onDismissCancelDialog - ) - } - } - if (uiState.internDialogVisibility) { - uiState.internshipModel?.let { - val scrapColor = Color( - android.graphics.Color.parseColor( - uiState.internshipModel.color - ) - ) - ScrapDialog( - title = uiState.internshipModel.title, - scrapColor = scrapColor, - deadline = uiState.currentDate.getFullDateStringInKorean(), - startYearMonth = uiState.internshipModel.startYearMonth, - workingPeriod = uiState.internshipModel.workingPeriod, - internshipAnnouncementId = uiState.internshipModel.internshipAnnouncementId, - companyImage = uiState.internshipModel.companyImage, - isScrapped = true, - onDismissRequest = onDismissInternDialog, - onClickChangeColor = onClickChangeColor, - onClickNavigateButton = navigateToAnnouncement - ) - } - } } @Composable @@ -244,8 +226,7 @@ private fun CalendarListEmpty( ) Text( - modifier = modifier - .fillMaxWidth(), + modifier = modifier.fillMaxWidth(), text = stringResource(id = R.string.calendar_empty_scrap), textAlign = TextAlign.Center, style = TerningTheme.typography.body5, @@ -253,4 +234,51 @@ private fun CalendarListEmpty( ) } +@Composable +private fun CalendarListScrapCancelDialog( + scrapVisibility: Boolean, + internshipAnnouncementId: Long?, + onDismissCancelDialog: (Boolean) -> Unit +) { + if (scrapVisibility) { + internshipAnnouncementId?.run { + ScrapCancelDialog( + internshipAnnouncementId = this, + onDismissRequest = onDismissCancelDialog + ) + } + } +} +@Composable +private fun CalendarListScrapPatchDialog( + currentDate: LocalDate, + dialogVisibility: Boolean, + internshipModel: CalendarScrapDetail?, + navigateToAnnouncement: (Long) -> Unit, + onDismissInternDialog: () -> Unit, + onClickChangeColor: () -> Unit, +) { + if (dialogVisibility) { + internshipModel?.let { internship -> + val scrapColor = Color( + android.graphics.Color.parseColor( + internship.color + ) + ) + ScrapDialog( + title = internship.title, + scrapColor = scrapColor, + deadline = currentDate.getFullDateStringInKorean(), + startYearMonth = internship.startYearMonth, + workingPeriod = internship.workingPeriod, + internshipAnnouncementId = internship.internshipAnnouncementId, + companyImage = internship.companyImage, + isScrapped = true, + onDismissRequest = onDismissInternDialog, + onClickChangeColor = onClickChangeColor, + onClickNavigateButton = navigateToAnnouncement + ) + } + } +} From c966343e601ee57dcc2f784fa56d262e80e4bcca Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 13 Sep 2024 22:40:44 +0900 Subject: [PATCH 05/15] =?UTF-8?q?[MOD/#246]=20List=20=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?PagerState=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/calendar/CalendarRoute.kt | 8 +- .../calendar/list/CalendarListScreen.kt | 140 ++++++++---------- 2 files changed, 65 insertions(+), 83 deletions(-) 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 5f14289ea..888f2eb11 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 @@ -1,5 +1,6 @@ package com.terning.feature.calendar.calendar +import androidx.compose.animation.core.tween import androidx.compose.animation.slideInHorizontally import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideOutHorizontally @@ -115,8 +116,9 @@ private fun CalendarScreen( onListButtonClicked = onClickListButton, onMonthNavigationButtonClicked = { direction -> coroutineScope.launch { - listState.animateScrollToItem( - index = listState.firstVisibleItemIndex + direction, + pagerState.animateScrollToPage( + page = pagerState.settledPage + direction, + animationSpec = tween(500) ) } } @@ -169,8 +171,6 @@ private fun CalendarScreen( }, contentTwo = { CalendarListRoute( - listState = listState, - pages = uiState.calendarModel.pageCount, navigateToAnnouncement = navigateToAnnouncement, navigateUp = disableListVisibility, modifier = Modifier diff --git a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt index 2c9dd57a6..7b70c292a 100644 --- a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt @@ -3,15 +3,14 @@ package com.terning.feature.calendar.list import androidx.activity.compose.BackHandler import androidx.compose.foundation.Image import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.foundation.pager.HorizontalPager +import androidx.compose.foundation.pager.PagerState import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -29,40 +28,37 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.flowWithLifecycle -import com.google.devtools.ksp.symbol.Visibility import com.terning.core.designsystem.theme.Back import com.terning.core.designsystem.theme.Black import com.terning.core.designsystem.theme.Grey400 import com.terning.core.designsystem.theme.TerningTheme -import com.terning.core.designsystem.theme.White import com.terning.core.extension.getFullDateStringInKorean import com.terning.core.extension.isListNotEmpty import com.terning.core.extension.toast import com.terning.core.state.UiState import com.terning.domain.entity.calendar.CalendarScrapDetail import com.terning.feature.R -import com.terning.feature.calendar.calendar.model.CalendarDefaults.flingBehavior import com.terning.feature.calendar.calendar.model.CalendarModel.Companion.getLocalDateByPage +import com.terning.feature.calendar.calendar.model.LocalPagerState import com.terning.feature.calendar.list.component.CalendarScrapList import com.terning.feature.calendar.list.model.CalendarListUiState import com.terning.feature.dialog.cancel.ScrapCancelDialog import com.terning.feature.dialog.detail.ScrapDialog -import kotlinx.coroutines.flow.distinctUntilChanged +import timber.log.Timber import java.time.LocalDate @Composable fun CalendarListRoute( - pages: Int, - listState: LazyListState, modifier: Modifier = Modifier, navigateUp: () -> Unit, navigateToAnnouncement: (Long) -> Unit, viewModel: CalendarListViewModel = hiltViewModel() ) { + val pagerState = LocalPagerState.current val lifecycleOwner = LocalLifecycleOwner.current val uiState by viewModel.uiState.collectAsStateWithLifecycle(lifecycleOwner) - val context = LocalContext.current + LaunchedEffect(viewModel.sideEffect, lifecycleOwner) { viewModel.sideEffect.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle) .collect { sideEffect -> @@ -72,14 +68,13 @@ fun CalendarListRoute( } } - LaunchedEffect(key1 = listState) { - snapshotFlow { listState.firstVisibleItemIndex } - .distinctUntilChanged() - .collect { - val page = listState.firstVisibleItemIndex - val date = getLocalDateByPage(page) + LaunchedEffect(key1 = pagerState) { + snapshotFlow { pagerState.settledPage } + .collect { settled -> + val date = getLocalDateByPage(settled) viewModel.updateCurrentDate(date) viewModel.getScrapMonthList(date) + Timber.tag("Calendar").d("MonthAPI date:${date} ") } } @@ -88,11 +83,9 @@ fun CalendarListRoute( } CalendarListScreen( - pages = pages, - listState = listState, + pagerState = pagerState, uiState = uiState, modifier = modifier, - onClickScrapButton = { scrapId -> with(viewModel) { updateAnnouncementId(scrapId) @@ -135,84 +128,73 @@ fun CalendarListRoute( @Composable private fun CalendarListScreen( - pages: Int, - listState: LazyListState, + pagerState: PagerState, uiState: CalendarListUiState, onClickInternship: (CalendarScrapDetail) -> Unit, onClickScrapButton: (Long) -> Unit, modifier: Modifier = Modifier ) { - Box { - LazyRow( - modifier = modifier - .background(White), - state = listState, - userScrollEnabled = true, - flingBehavior = flingBehavior( - state = listState - ) - ) { - items(pages) { page -> - val getDate = getLocalDateByPage(page) + HorizontalPager( + state = pagerState, + modifier = modifier + ) { page -> + val getDate = getLocalDateByPage(page) - LazyColumn( - modifier = Modifier - .fillParentMaxWidth() - .fillMaxHeight() - .background(Back) - ) { - when (uiState.loadState) { - UiState.Loading -> {} - UiState.Empty -> { - item { - Column( - modifier = Modifier.fillMaxSize(), - horizontalAlignment = Alignment.CenterHorizontally - ) { - CalendarListEmpty() - } - } + LazyColumn( + modifier = Modifier + .fillMaxSize() + .fillMaxHeight() + .background(Back) + ) { + when (uiState.loadState) { + UiState.Loading -> {} + UiState.Empty -> { + item { + Column( + modifier = Modifier.fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally + ) { + CalendarListEmpty() } + } + } - is UiState.Failure -> {} - is UiState.Success -> { - val scrapMap = uiState.loadState.data - items(getDate.lengthOfMonth()) { day -> - val currentDate = - LocalDate.of(getDate.year, getDate.monthValue, day + 1) - val dateInKorean = currentDate.getFullDateStringInKorean() + is UiState.Failure -> {} + is UiState.Success -> { + val scrapMap = uiState.loadState.data + items(getDate.lengthOfMonth()) { day -> + val currentDate = + LocalDate.of(getDate.year, getDate.monthValue, day + 1) + val dateInKorean = currentDate.getFullDateStringInKorean() - if (scrapMap[dateInKorean].isListNotEmpty()) { - Text( - text = dateInKorean, - style = TerningTheme.typography.title5, - color = Black, - modifier = Modifier - .padding(start = 24.dp, top = 16.dp, bottom = 15.dp) - ) + if (scrapMap[dateInKorean].isListNotEmpty()) { + Text( + text = dateInKorean, + style = TerningTheme.typography.title5, + color = Black, + modifier = Modifier + .padding(start = 24.dp, top = 16.dp, bottom = 15.dp) + ) - CalendarScrapList( - selectedDate = currentDate, - scrapList = scrapMap[dateInKorean].orEmpty(), - onScrapButtonClicked = onClickScrapButton, - onInternshipClicked = onClickInternship, - isFromList = true, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 24.dp) - ) - } - } + CalendarScrapList( + selectedDate = currentDate, + scrapList = scrapMap[dateInKorean].orEmpty(), + onScrapButtonClicked = onClickScrapButton, + onInternshipClicked = onClickInternship, + isFromList = true, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 24.dp) + ) } } } } } } - - } + @Composable private fun CalendarListEmpty( modifier: Modifier = Modifier From fe4e5ab036407fa969824f7a301230b16cf6c7d7 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 13 Sep 2024 22:42:43 +0900 Subject: [PATCH 06/15] =?UTF-8?q?[DEL/#246]=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/terning/feature/calendar/list/CalendarListScreen.kt | 2 -- .../com/terning/feature/calendar/month/CalendarMonthScreen.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt index 7b70c292a..b5786d8bd 100644 --- a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt @@ -44,7 +44,6 @@ import com.terning.feature.calendar.list.component.CalendarScrapList import com.terning.feature.calendar.list.model.CalendarListUiState import com.terning.feature.dialog.cancel.ScrapCancelDialog import com.terning.feature.dialog.detail.ScrapDialog -import timber.log.Timber import java.time.LocalDate @Composable @@ -74,7 +73,6 @@ fun CalendarListRoute( val date = getLocalDateByPage(settled) viewModel.updateCurrentDate(date) viewModel.getScrapMonthList(date) - Timber.tag("Calendar").d("MonthAPI date:${date} ") } } diff --git a/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt b/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt index f2a5a01c5..9c530b282 100644 --- a/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt @@ -20,7 +20,6 @@ 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 com.terning.feature.calendar.month.model.MonthModel -import timber.log.Timber import java.time.LocalDate import java.time.YearMonth @@ -50,7 +49,6 @@ fun CalendarMonthRoute( .collect { settled-> val date = getLocalDateByPage(settled) viewModel.getScrapMonth(date.year, date.monthValue) - Timber.tag("Calendar").d("MonthAPI date:${date} ") } } From b5652ee4f90292f6ef8ccb0f75898f610d45caea Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 13 Sep 2024 22:50:32 +0900 Subject: [PATCH 07/15] =?UTF-8?q?[MOD/#246]=20=ED=83=91=EB=B0=94=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/topappbar/CalendarTopAppBar.kt | 9 ++------- .../terning/feature/calendar/calendar/CalendarRoute.kt | 1 - 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt b/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt index 30364b680..f7c7d0a60 100644 --- a/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt +++ b/core/src/main/java/com/terning/core/designsystem/component/topappbar/CalendarTopAppBar.kt @@ -40,7 +40,6 @@ import java.time.YearMonth @Composable fun CalendarTopAppBar( date: YearMonth, - isWeekExpanded: Boolean, isListExpanded: Boolean, onListButtonClicked: () -> Unit, onMonthNavigationButtonClicked: (Int) -> Unit, @@ -59,28 +58,26 @@ fun CalendarTopAppBar( modifier = Modifier.align(Alignment.Center), verticalAlignment = Alignment.CenterVertically ) { - if(!isWeekExpanded || isListExpanded) { Icon( painter = painterResource(id = R.drawable.ic_calendar_previous), contentDescription = stringResource(id = R.string.calendar_button_description_previous), tint = TerningMain, modifier = Modifier.noRippleClickable { onMonthNavigationButtonClicked(-1) } ) - } + Text( text = LocalDate.of(date.year, date.month, 1).getStringAsTitle(), style = TerningTheme.typography.title2, color = Black, modifier = Modifier.padding(horizontal = 8.dp) ) - if(!isWeekExpanded || isListExpanded) { Icon( painter = painterResource(id = R.drawable.ic_calendar_next), contentDescription = stringResource(id = R.string.calendar_button_description_next), tint = TerningMain, modifier = Modifier.noRippleClickable { onMonthNavigationButtonClicked(1) } ) - } + } Box( modifier = Modifier @@ -109,8 +106,6 @@ fun CalendarTopBarPreview() { CalendarTopAppBar( date = YearMonth.now(), isListExpanded = false, - isWeekExpanded = false - , onListButtonClicked = {}, onMonthNavigationButtonClicked = {} ) 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 888f2eb11..943be59e5 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 @@ -112,7 +112,6 @@ private fun CalendarScreen( CalendarTopAppBar( date = getYearMonthByPage(uiState.currentPage), isListExpanded = uiState.isListEnabled, - isWeekExpanded = uiState.isWeekEnabled, onListButtonClicked = onClickListButton, onMonthNavigationButtonClicked = { direction -> coroutineScope.launch { From f8722568b348ff6a6ce9154a3780dcfa9ba0f3e8 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 13 Sep 2024 23:14:16 +0900 Subject: [PATCH 08/15] =?UTF-8?q?[MOD/#246]=20CalendarViewModel=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/calendar/CalendarRoute.kt | 31 ++++--------------- .../calendar/calendar/CalendarViewModel.kt | 22 ++++++++++--- 2 files changed, 23 insertions(+), 30 deletions(-) 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 943be59e5..6f227ac2d 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 @@ -9,7 +9,6 @@ import androidx.compose.animation.togetherWith import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable @@ -34,7 +33,6 @@ 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.flow.distinctUntilChanged import kotlinx.coroutines.launch import java.time.LocalDate @@ -51,16 +49,12 @@ fun CalendarRoute( modifier = modifier, uiState = uiState, navigateToAnnouncement = navigateToAnnouncement, + onClickNewDate = viewModel::onSelectNewDate, updateSelectedDate = viewModel::updateSelectedDate, updatePage = viewModel::updatePage, disableListVisibility = { viewModel.updateListVisibility(false) }, disableWeekVisibility = { viewModel.updateSelectedDate(uiState.selectedDate) }, - onClickListButton = { - viewModel.updateListVisibility(!uiState.isListEnabled) - if (uiState.isWeekEnabled) { - viewModel.updateWeekVisibility(false) - } - } + onClickListButton = { viewModel.updateListVisibility(!uiState.isListEnabled) } ) } @@ -68,6 +62,7 @@ fun CalendarRoute( private fun CalendarScreen( uiState: CalendarUiState, navigateToAnnouncement: (Long) -> Unit, + onClickNewDate: (LocalDate) -> Unit, updateSelectedDate: (LocalDate) -> Unit, disableListVisibility: () -> Unit, disableWeekVisibility: () -> Unit, @@ -83,26 +78,12 @@ private fun CalendarScreen( ) LaunchedEffect(key1 = pagerState) { - snapshotFlow { pagerState.currentPage} + snapshotFlow { pagerState.currentPage } .collect { current -> updatePage(current) } } - val listState = rememberLazyListState( - initialFirstVisibleItemIndex = uiState.calendarModel.initialPage - ) - - LaunchedEffect(key1 = listState) { - snapshotFlow { listState.firstVisibleItemIndex to listState.firstVisibleItemScrollOffset} - .distinctUntilChanged() - .collect { (index, offset) -> - if (offset == 0) { - updatePage(index) - } - } - } - CompositionLocalProvider( LocalPagerState provides pagerState ) { @@ -149,7 +130,7 @@ private fun CalendarScreen( contentOne = { CalendarMonthRoute( selectedDate = uiState.selectedDate, - updateSelectedDate = updateSelectedDate, + updateSelectedDate = onClickNewDate, modifier = Modifier .fillMaxSize() .background(White), @@ -162,7 +143,7 @@ private fun CalendarScreen( .fillMaxSize(), navigateUp = disableWeekVisibility, navigateToAnnouncement = navigateToAnnouncement, - updateSelectedDate = updateSelectedDate + updateSelectedDate = onClickNewDate ) } ) 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 4b525140a..480d812c3 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 @@ -16,16 +16,28 @@ class CalendarViewModel @Inject constructor() : ViewModel() { private var _uiState: MutableStateFlow = MutableStateFlow(CalendarUiState()) val uiState get() = _uiState.asStateFlow() - fun updateSelectedDate(date: LocalDate) = viewModelScope.launch { - if (_uiState.value.selectedDate != date) { + fun onSelectNewDate(selectedDate: LocalDate) = viewModelScope.launch { + if (_uiState.value.selectedDate == selectedDate) { _uiState.update { currentState -> currentState.copy( - selectedDate = date + isWeekEnabled = !_uiState.value.isWeekEnabled ) } - updateWeekVisibility(true) } else { - updateWeekVisibility(!_uiState.value.isWeekEnabled) + _uiState.update { currentState -> + currentState.copy( + selectedDate = selectedDate, + isWeekEnabled = true + ) + } + } + } + + fun updateSelectedDate(date: LocalDate) = viewModelScope.launch { + _uiState.update { currentState -> + currentState.copy( + selectedDate = date + ) } } From 0655243f8dc441c9f5d296efadb2b926470228d7 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Fri, 13 Sep 2024 23:21:20 +0900 Subject: [PATCH 09/15] =?UTF-8?q?[MOD/#246]=20Dialog,=20Week=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/week/CalendarWeekScreen.kt | 122 +++++++++++------- 1 file changed, 74 insertions(+), 48 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt index ca882549f..4f5bc4800 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt @@ -88,18 +88,6 @@ fun CalendarWeekRoute( uiState = uiState, selectedDate = calendarUiState.selectedDate, updateSelectedDate = updateSelectedDate, - navigateToAnnouncement = { announcementId -> - navigateToAnnouncement(announcementId) - viewModel.updateInternDialogVisibility(false) - }, - onDismissCancelDialog = { isCancelled -> - viewModel.updateScrapCancelDialogVisibility(false) - if (isCancelled) { - viewModel.getScrapWeekList(uiState.selectedDate) - } - }, - onDismissInternDialog = { viewModel.updateInternDialogVisibility(false) }, - onClickChangeColor = { viewModel.getScrapWeekList(uiState.selectedDate) }, onClickScrapButton = { scrapId -> with(viewModel) { updateInternshipAnnouncementId(scrapId) @@ -113,6 +101,31 @@ fun CalendarWeekRoute( } }, ) + + CalendarWeekScrapPatchDialog( + currentDate = uiState.selectedDate, + dialogVisibility = uiState.internDialogVisibility, + internshipModel = uiState.internshipModel, + navigateToAnnouncement = { announcementId -> + navigateToAnnouncement(announcementId) + viewModel.updateInternDialogVisibility(false) + }, + onDismissInternDialog = { viewModel.updateInternDialogVisibility(false) }, + onClickChangeColor = { + viewModel.getScrapWeekList(uiState.selectedDate) + }, + ) + + CalendarWeekScrapCancelDialog( + scrapVisibility = uiState.scrapDialogVisibility, + internshipAnnouncementId = uiState.internshipAnnouncementId, + onDismissCancelDialog = { isCancelled -> + viewModel.updateScrapCancelDialogVisibility(false) + if (isCancelled) { + viewModel.getScrapWeekList(uiState.selectedDate) + } + } + ) } @Composable @@ -120,12 +133,8 @@ private fun CalendarWeekScreen( uiState: CalendarWeekUiState, selectedDate: LocalDate, updateSelectedDate: (LocalDate) -> Unit, - onDismissCancelDialog: (Boolean) -> Unit, - onDismissInternDialog: () -> Unit, - onClickChangeColor: () -> Unit, onClickInternship: (CalendarScrapDetail) -> Unit, onClickScrapButton: (Long) -> Unit, - navigateToAnnouncement: (Long) -> Unit, modifier: Modifier = Modifier ) { var swiped by remember { mutableStateOf(false) } @@ -189,38 +198,6 @@ private fun CalendarWeekScreen( } } } - - if (uiState.scrapDialogVisibility) { - uiState.internshipAnnouncementId?.run { - ScrapCancelDialog( - internshipAnnouncementId = this, - onDismissRequest = onDismissCancelDialog - ) - } - } - - if (uiState.internDialogVisibility) { - uiState.internshipModel?.let { - val scrapColor = Color( - android.graphics.Color.parseColor( - uiState.internshipModel.color - ) - ) - ScrapDialog( - title = uiState.internshipModel.title, - scrapColor = scrapColor, - deadline = uiState.selectedDate.getFullDateStringInKorean(), - startYearMonth = uiState.internshipModel.startYearMonth, - workingPeriod = uiState.internshipModel.workingPeriod, - internshipAnnouncementId = uiState.internshipModel.internshipAnnouncementId, - companyImage = uiState.internshipModel.companyImage, - isScrapped = true, - onDismissRequest = onDismissInternDialog, - onClickChangeColor = onClickChangeColor, - onClickNavigateButton = navigateToAnnouncement - ) - } - } } @Composable @@ -262,6 +239,55 @@ private fun CalendarWeekSuccess( ) } +@Composable +private fun CalendarWeekScrapCancelDialog( + scrapVisibility: Boolean, + internshipAnnouncementId: Long?, + onDismissCancelDialog: (Boolean) -> Unit +) { + if (scrapVisibility) { + internshipAnnouncementId?.run { + ScrapCancelDialog( + internshipAnnouncementId = this, + onDismissRequest = onDismissCancelDialog + ) + } + } +} + +@Composable +private fun CalendarWeekScrapPatchDialog( + currentDate: LocalDate, + dialogVisibility: Boolean, + internshipModel: CalendarScrapDetail?, + navigateToAnnouncement: (Long) -> Unit, + onDismissInternDialog: () -> Unit, + onClickChangeColor: () -> Unit, +) { + if (dialogVisibility) { + internshipModel?.let { internship -> + val scrapColor = Color( + android.graphics.Color.parseColor( + internship.color + ) + ) + ScrapDialog( + title = internship.title, + scrapColor = scrapColor, + deadline = currentDate.getFullDateStringInKorean(), + startYearMonth = internship.startYearMonth, + workingPeriod = internship.workingPeriod, + internshipAnnouncementId = internship.internshipAnnouncementId, + companyImage = internship.companyImage, + isScrapped = true, + onDismissRequest = onDismissInternDialog, + onClickChangeColor = onClickChangeColor, + onClickNavigateButton = navigateToAnnouncement + ) + } + } +} + From 6475edeb044469875cff1dc0a0b6004a6f3946ba Mon Sep 17 00:00:00 2001 From: boiledegg Date: Sat, 14 Sep 2024 02:58:40 +0900 Subject: [PATCH 10/15] =?UTF-8?q?[FEAT/#246]=20=EB=8B=AC=EB=A0=A5=20?= =?UTF-8?q?=EC=A0=84=ED=99=98=20=EB=A1=9C=EC=A7=81=20=EC=9E=AC=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/calendar/CalendarRoute.kt | 13 +-- .../calendar/calendar/CalendarViewModel.kt | 10 +-- .../calendar/model/CalendarUiState.kt | 1 - .../calendar/week/CalendarWeekScreen.kt | 79 +++++++++++-------- .../calendar/week/CalendarWeekViewModel.kt | 8 -- .../week/component/HorizontalCalendarWeek.kt | 5 ++ .../week/model/CalendarWeekUiState.kt | 1 - 7 files changed, 63 insertions(+), 54 deletions(-) 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 6f227ac2d..a6519820f 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 @@ -27,6 +27,7 @@ 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.model.CalendarModel.Companion.getLocalDateByPage import com.terning.feature.calendar.calendar.model.CalendarModel.Companion.getYearMonthByPage import com.terning.feature.calendar.calendar.model.CalendarUiState import com.terning.feature.calendar.calendar.model.LocalPagerState @@ -34,6 +35,7 @@ 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 @@ -51,7 +53,6 @@ fun CalendarRoute( navigateToAnnouncement = navigateToAnnouncement, onClickNewDate = viewModel::onSelectNewDate, updateSelectedDate = viewModel::updateSelectedDate, - updatePage = viewModel::updatePage, disableListVisibility = { viewModel.updateListVisibility(false) }, disableWeekVisibility = { viewModel.updateSelectedDate(uiState.selectedDate) }, onClickListButton = { viewModel.updateListVisibility(!uiState.isListEnabled) } @@ -66,7 +67,6 @@ private fun CalendarScreen( updateSelectedDate: (LocalDate) -> Unit, disableListVisibility: () -> Unit, disableWeekVisibility: () -> Unit, - updatePage: (Int) -> Unit, onClickListButton: () -> Unit, modifier: Modifier = Modifier, ) { @@ -77,10 +77,13 @@ private fun CalendarScreen( pageCount = { uiState.calendarModel.pageCount } ) - LaunchedEffect(key1 = pagerState) { + LaunchedEffect(key1 = pagerState, key2 = uiState.selectedDate) { snapshotFlow { pagerState.currentPage } .collect { current -> - updatePage(current) + val date = getLocalDateByPage(current) + val newDate = LocalDate.of(date.year, date.month, uiState.selectedDate.dayOfMonth) + updateSelectedDate(newDate) + Timber.tag("Calendar").d("new:$newDate old:${uiState.selectedDate}") } } @@ -91,7 +94,7 @@ private fun CalendarScreen( modifier = modifier, ) { CalendarTopAppBar( - date = getYearMonthByPage(uiState.currentPage), + date = getYearMonthByPage(pagerState.settledPage), isListExpanded = uiState.isListEnabled, onListButtonClicked = onClickListButton, onMonthNavigationButtonClicked = { direction -> 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 480d812c3..16d23aa30 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 @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch +import timber.log.Timber import java.time.LocalDate import javax.inject.Inject @@ -34,6 +35,7 @@ class CalendarViewModel @Inject constructor() : ViewModel() { } fun updateSelectedDate(date: LocalDate) = viewModelScope.launch { + Timber.tag("Calendar").d("in calendar viewmodel:${_uiState.value.selectedDate}") _uiState.update { currentState -> currentState.copy( selectedDate = date @@ -41,14 +43,6 @@ class CalendarViewModel @Inject constructor() : ViewModel() { } } - fun updatePage(page: Int) = viewModelScope.launch { - _uiState.update { currentState -> - currentState.copy( - currentPage = page - ) - } - } - fun updateListVisibility( visibility: Boolean ) { diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt index 4e84cb41c..6231be95b 100644 --- a/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt +++ b/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarUiState.kt @@ -7,7 +7,6 @@ import java.time.LocalDate data class CalendarUiState( val selectedDate: LocalDate = LocalDate.now(), val calendarModel: CalendarModel = CalendarModel(), - val currentPage: Int = 0, val isListEnabled: Boolean = false, val isWeekEnabled: Boolean = false ) diff --git a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt index 4f5bc4800..5219b75e7 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt @@ -4,8 +4,11 @@ import androidx.activity.compose.BackHandler import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.pager.HorizontalPager +import androidx.compose.foundation.pager.PagerState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Card import androidx.compose.material3.Text @@ -15,6 +18,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.shadow @@ -40,13 +44,16 @@ import com.terning.core.extension.toast import com.terning.core.state.UiState import com.terning.domain.entity.calendar.CalendarScrapDetail import com.terning.feature.R +import com.terning.feature.calendar.calendar.model.CalendarModel.Companion.getLocalDateByPage import com.terning.feature.calendar.calendar.model.CalendarUiState +import com.terning.feature.calendar.calendar.model.LocalPagerState import com.terning.feature.calendar.list.component.CalendarScrapList import com.terning.feature.calendar.week.component.HorizontalCalendarWeek import com.terning.feature.calendar.week.model.CalendarWeekUiState import com.terning.feature.dialog.cancel.ScrapCancelDialog import com.terning.feature.dialog.detail.ScrapDialog import okhttp3.internal.toImmutableList +import timber.log.Timber import java.time.LocalDate @Composable @@ -58,6 +65,7 @@ fun CalendarWeekRoute( modifier: Modifier = Modifier, viewModel: CalendarWeekViewModel = hiltViewModel() ) { + val pagerState = LocalPagerState.current val lifecycleOwner = LocalLifecycleOwner.current val uiState by viewModel.uiState.collectAsStateWithLifecycle(lifecycleOwner) @@ -72,11 +80,7 @@ fun CalendarWeekRoute( } LaunchedEffect(key1 = calendarUiState.selectedDate) { - viewModel.updateSelectedDate(selectedDate = calendarUiState.selectedDate) - } - - LaunchedEffect(key1 = uiState.selectedDate) { - viewModel.getScrapWeekList(selectedDate = uiState.selectedDate) + viewModel.getScrapWeekList(selectedDate = calendarUiState.selectedDate) } BackHandler { @@ -85,6 +89,7 @@ fun CalendarWeekRoute( CalendarWeekScreen( modifier = modifier, + pagerState = pagerState, uiState = uiState, selectedDate = calendarUiState.selectedDate, updateSelectedDate = updateSelectedDate, @@ -103,7 +108,7 @@ fun CalendarWeekRoute( ) CalendarWeekScrapPatchDialog( - currentDate = uiState.selectedDate, + currentDate = calendarUiState.selectedDate, dialogVisibility = uiState.internDialogVisibility, internshipModel = uiState.internshipModel, navigateToAnnouncement = { announcementId -> @@ -112,7 +117,7 @@ fun CalendarWeekRoute( }, onDismissInternDialog = { viewModel.updateInternDialogVisibility(false) }, onClickChangeColor = { - viewModel.getScrapWeekList(uiState.selectedDate) + viewModel.getScrapWeekList(calendarUiState.selectedDate) }, ) @@ -122,7 +127,7 @@ fun CalendarWeekRoute( onDismissCancelDialog = { isCancelled -> viewModel.updateScrapCancelDialogVisibility(false) if (isCancelled) { - viewModel.getScrapWeekList(uiState.selectedDate) + viewModel.getScrapWeekList(calendarUiState.selectedDate) } } ) @@ -131,6 +136,7 @@ fun CalendarWeekRoute( @Composable private fun CalendarWeekScreen( uiState: CalendarWeekUiState, + pagerState: PagerState, selectedDate: LocalDate, updateSelectedDate: (LocalDate) -> Unit, onClickInternship: (CalendarScrapDetail) -> Unit, @@ -169,32 +175,43 @@ private fun CalendarWeekScreen( ) } - Text( - text = selectedDate.getDateStringInKorean(), - style = TerningTheme.typography.title5, - color = Black, - modifier = Modifier - .fillMaxWidth() - .padding(start = 24.dp, top = 16.dp, bottom = 15.dp) - ) + HorizontalPager( + state = pagerState, + modifier = Modifier.fillMaxSize(), + userScrollEnabled = false + ) { + Column( + modifier = Modifier.fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = selectedDate.getDateStringInKorean(), + style = TerningTheme.typography.title5, + color = Black, + modifier = Modifier + .fillMaxWidth() + .padding(start = 24.dp, top = 16.dp, bottom = 15.dp) + ) - when (uiState.loadState) { - is UiState.Loading -> {} - is UiState.Empty -> { - CalendarWeekEmpty() - } + when (uiState.loadState) { + is UiState.Loading -> {} + is UiState.Empty -> { + CalendarWeekEmpty() + } - is UiState.Failure -> { - CalendarWeekEmpty() - } + is UiState.Failure -> { + CalendarWeekEmpty() + } - is UiState.Success -> { - CalendarWeekSuccess( - scrapList = uiState.loadState.data.toImmutableList(), - selectedDate = uiState.selectedDate, - onScrapButtonClicked = onClickScrapButton, - onInternshipClicked = onClickInternship - ) + is UiState.Success -> { + CalendarWeekSuccess( + scrapList = uiState.loadState.data.toImmutableList(), + selectedDate = selectedDate, + onScrapButtonClicked = onClickScrapButton, + onInternshipClicked = onClickInternship + ) + } + } } } } diff --git a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekViewModel.kt b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekViewModel.kt index 0ebe403c3..52c824dc6 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekViewModel.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekViewModel.kt @@ -28,14 +28,6 @@ class CalendarWeekViewModel @Inject constructor( private val _sideEffect: MutableSharedFlow = MutableSharedFlow() val sideEffect = _sideEffect.asSharedFlow() - fun updateSelectedDate(selectedDate: LocalDate) { - _uiState.update { currentState -> - currentState.copy( - selectedDate = selectedDate - ) - } - } - fun updateScrapCancelDialogVisibility(visibility: Boolean) { _uiState.update { currentState -> currentState.copy( diff --git a/feature/src/main/java/com/terning/feature/calendar/week/component/HorizontalCalendarWeek.kt b/feature/src/main/java/com/terning/feature/calendar/week/component/HorizontalCalendarWeek.kt index 593a927dd..e179cc7cc 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/component/HorizontalCalendarWeek.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/component/HorizontalCalendarWeek.kt @@ -8,6 +8,7 @@ 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.extension.getWeekIndexContainingSelectedDate @@ -31,6 +32,10 @@ fun HorizontalCalendarWeek( pageCount = { monthModel.totalDays / 7 } ) + LaunchedEffect(selectedDate) { + pagerState.animateScrollToPage(selectedDate.getWeekIndexContainingSelectedDate(monthModel.inDays)) + } + HorizontalPager( modifier = modifier, state = pagerState diff --git a/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt b/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt index 08932e1e7..fbf539b61 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt @@ -6,7 +6,6 @@ import java.time.LocalDate data class CalendarWeekUiState( val loadState: UiState> = UiState.Loading, - val selectedDate: LocalDate = LocalDate.now(), val scrapDialogVisibility: Boolean = false, val internDialogVisibility: Boolean = false, val internshipAnnouncementId: Long? = null, From 9fb6115bd2dea23b9f42b59ef9074dcfafd28c1b Mon Sep 17 00:00:00 2001 From: boiledegg Date: Sat, 14 Sep 2024 02:59:46 +0900 Subject: [PATCH 11/15] =?UTF-8?q?[DEL/#246]=20=EB=9D=BC=EC=9D=B4=EB=B8=8C?= =?UTF-8?q?=EB=9F=AC=EB=A6=AC=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/calendar/calendar/CalendarRoute.kt | 2 -- .../feature/calendar/calendar/CalendarViewModel.kt | 12 ------------ .../calendar/list/component/CalendarScrapList.kt | 7 ------- .../feature/calendar/week/CalendarWeekScreen.kt | 3 --- .../calendar/week/model/CalendarWeekUiState.kt | 1 - 5 files changed, 25 deletions(-) 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 a6519820f..6ac781127 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 @@ -35,7 +35,6 @@ 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 @@ -83,7 +82,6 @@ private fun CalendarScreen( val date = getLocalDateByPage(current) val newDate = LocalDate.of(date.year, date.month, uiState.selectedDate.dayOfMonth) updateSelectedDate(newDate) - Timber.tag("Calendar").d("new:$newDate old:${uiState.selectedDate}") } } 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 16d23aa30..9d8c5893d 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 @@ -8,7 +8,6 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch -import timber.log.Timber import java.time.LocalDate import javax.inject.Inject @@ -35,7 +34,6 @@ class CalendarViewModel @Inject constructor() : ViewModel() { } fun updateSelectedDate(date: LocalDate) = viewModelScope.launch { - Timber.tag("Calendar").d("in calendar viewmodel:${_uiState.value.selectedDate}") _uiState.update { currentState -> currentState.copy( selectedDate = date @@ -52,14 +50,4 @@ class CalendarViewModel @Inject constructor() : ViewModel() { ) } } - - fun updateWeekVisibility( - visibility: Boolean - ) { - _uiState.update { currentState -> - currentState.copy( - isWeekEnabled = visibility - ) - } - } } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/calendar/list/component/CalendarScrapList.kt b/feature/src/main/java/com/terning/feature/calendar/list/component/CalendarScrapList.kt index a2ff8bb49..6ac83ab5b 100644 --- a/feature/src/main/java/com/terning/feature/calendar/list/component/CalendarScrapList.kt +++ b/feature/src/main/java/com/terning/feature/calendar/list/component/CalendarScrapList.kt @@ -2,19 +2,12 @@ package com.terning.feature.calendar.list.component import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import com.terning.core.designsystem.theme.Black -import com.terning.core.designsystem.theme.TerningTheme -import com.terning.core.extension.getDateStringInKorean -import com.terning.core.extension.isListNotEmpty import com.terning.domain.entity.calendar.CalendarScrapDetail import java.time.LocalDate diff --git a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt index 5219b75e7..33a911d83 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt @@ -18,7 +18,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.shadow @@ -44,7 +43,6 @@ import com.terning.core.extension.toast import com.terning.core.state.UiState import com.terning.domain.entity.calendar.CalendarScrapDetail import com.terning.feature.R -import com.terning.feature.calendar.calendar.model.CalendarModel.Companion.getLocalDateByPage import com.terning.feature.calendar.calendar.model.CalendarUiState import com.terning.feature.calendar.calendar.model.LocalPagerState import com.terning.feature.calendar.list.component.CalendarScrapList @@ -53,7 +51,6 @@ import com.terning.feature.calendar.week.model.CalendarWeekUiState import com.terning.feature.dialog.cancel.ScrapCancelDialog import com.terning.feature.dialog.detail.ScrapDialog import okhttp3.internal.toImmutableList -import timber.log.Timber import java.time.LocalDate @Composable diff --git a/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt b/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt index fbf539b61..18b586b77 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt @@ -2,7 +2,6 @@ package com.terning.feature.calendar.week.model import com.terning.core.state.UiState import com.terning.domain.entity.calendar.CalendarScrapDetail -import java.time.LocalDate data class CalendarWeekUiState( val loadState: UiState> = UiState.Loading, From 4b6db8f79a5f1d9e81b4bea80d899e4d4a4d040c Mon Sep 17 00:00:00 2001 From: boiledegg Date: Sat, 14 Sep 2024 03:16:16 +0900 Subject: [PATCH 12/15] =?UTF-8?q?[REFACTOR/#246]=20=EB=B7=B0=EB=AA=A8?= =?UTF-8?q?=EB=8D=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/calendar/CalendarRoute.kt | 2 +- .../calendar/calendar/CalendarViewModel.kt | 12 +++- .../calendar/list/CalendarListScreen.kt | 10 +-- .../calendar/list/CalendarListViewModel.kt | 67 ++++++++++--------- .../list/model/CalendarListUiState.kt | 4 +- .../calendar/week/CalendarWeekScreen.kt | 10 +-- .../calendar/week/CalendarWeekViewModel.kt | 25 +++---- .../week/model/CalendarWeekUiState.kt | 4 +- 8 files changed, 73 insertions(+), 61 deletions(-) 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 6ac781127..640b2ca55 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 @@ -53,7 +53,7 @@ fun CalendarRoute( onClickNewDate = viewModel::onSelectNewDate, updateSelectedDate = viewModel::updateSelectedDate, disableListVisibility = { viewModel.updateListVisibility(false) }, - disableWeekVisibility = { viewModel.updateSelectedDate(uiState.selectedDate) }, + disableWeekVisibility = { viewModel.updateWeekVisibility(false) }, onClickListButton = { viewModel.updateListVisibility(!uiState.isListEnabled) } ) } 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 9d8c5893d..5280ae0af 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 @@ -41,13 +41,19 @@ class CalendarViewModel @Inject constructor() : ViewModel() { } } - fun updateListVisibility( - visibility: Boolean - ) { + fun updateListVisibility(visibility: Boolean) = viewModelScope.launch { _uiState.update { currentState -> currentState.copy( isListEnabled = visibility ) } } + + fun updateWeekVisibility(visibility: Boolean) = viewModelScope.launch { + _uiState.update { currentState -> + currentState.copy( + isWeekEnabled = visibility + ) + } + } } \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt index b5786d8bd..cddf094bd 100644 --- a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListScreen.kt @@ -93,27 +93,27 @@ fun CalendarListRoute( onClickInternship = { calendarScrapDetail -> with(viewModel) { updateInternshipModel(calendarScrapDetail) - updateInternDialogVisibility(true) + updateScrapDetailDialogVisibility(true) } } ) CalendarListScrapPatchDialog( currentDate = uiState.currentDate, - dialogVisibility = uiState.internDialogVisibility, + dialogVisibility = uiState.scrapDetailDialogVisibility, internshipModel = uiState.internshipModel, navigateToAnnouncement = { announcementId -> navigateToAnnouncement(announcementId) - viewModel.updateInternDialogVisibility(false) + viewModel.updateScrapDetailDialogVisibility(false) }, - onDismissInternDialog = { viewModel.updateInternDialogVisibility(false) }, + onDismissInternDialog = { viewModel.updateScrapDetailDialogVisibility(false) }, onClickChangeColor = { viewModel.getScrapMonthList(uiState.currentDate) }, ) CalendarListScrapCancelDialog( - scrapVisibility = uiState.scrapDialogVisibility, + scrapVisibility = uiState.scrapCancelDialogVisibility, internshipAnnouncementId = uiState.internshipAnnouncementId, onDismissCancelDialog = { isCancelled -> viewModel.updateScrapCancelDialogVisibility(false) diff --git a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListViewModel.kt b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListViewModel.kt index 6491ae47a..ffd9f161b 100644 --- a/feature/src/main/java/com/terning/feature/calendar/list/CalendarListViewModel.kt +++ b/feature/src/main/java/com/terning/feature/calendar/list/CalendarListViewModel.kt @@ -21,52 +21,57 @@ import javax.inject.Inject @HiltViewModel class CalendarListViewModel @Inject constructor( private val calendarRepository: CalendarRepository -): ViewModel(){ +) : ViewModel() { private val _uiState = MutableStateFlow(CalendarListUiState()) val uiState = _uiState.asStateFlow() private val _sideEffect: MutableSharedFlow = MutableSharedFlow() val sideEffect = _sideEffect.asSharedFlow() - fun updateCurrentDate(date: LocalDate) { - _uiState.update { currentState -> - currentState.copy( - currentDate = date - ) + fun updateCurrentDate(date: LocalDate) = + viewModelScope.launch { + _uiState.update { currentState -> + currentState.copy( + currentDate = date + ) + } } - } - fun updateScrapCancelDialogVisibility(visibility: Boolean) { - _uiState.update { currentState -> - currentState.copy( - scrapDialogVisibility = visibility - ) + fun updateAnnouncementId(announcementId: Long? = null) = + viewModelScope.launch { + _uiState.update { currentState -> + currentState.copy( + internshipAnnouncementId = announcementId + ) + } } - } - fun updateAnnouncementId(announcementId: Long? = null) { - _uiState.update { currentState -> - currentState.copy( - internshipAnnouncementId = announcementId - ) + fun updateScrapCancelDialogVisibility(visibility: Boolean) = + viewModelScope.launch { + _uiState.update { currentState -> + currentState.copy( + scrapCancelDialogVisibility = visibility + ) + } } - } - fun updateInternDialogVisibility(visibility: Boolean) { - _uiState.update { currentState -> - currentState.copy( - internDialogVisibility = visibility - ) + fun updateScrapDetailDialogVisibility(visibility: Boolean) = + viewModelScope.launch { + _uiState.update { currentState -> + currentState.copy( + scrapDetailDialogVisibility = visibility + ) + } } - } - fun updateInternshipModel(scrapDetailModel: CalendarScrapDetail?) { - _uiState.update { currentState -> - currentState.copy( - internshipModel = scrapDetailModel - ) + fun updateInternshipModel(scrapDetailModel: CalendarScrapDetail?) = + viewModelScope.launch { + _uiState.update { currentState -> + currentState.copy( + internshipModel = scrapDetailModel + ) + } } - } fun getScrapMonthList( date: LocalDate diff --git a/feature/src/main/java/com/terning/feature/calendar/list/model/CalendarListUiState.kt b/feature/src/main/java/com/terning/feature/calendar/list/model/CalendarListUiState.kt index 1e7fb236f..ca214a28f 100644 --- a/feature/src/main/java/com/terning/feature/calendar/list/model/CalendarListUiState.kt +++ b/feature/src/main/java/com/terning/feature/calendar/list/model/CalendarListUiState.kt @@ -7,8 +7,8 @@ import java.time.LocalDate data class CalendarListUiState( val loadState: UiState>> = UiState.Loading, val currentDate: LocalDate = LocalDate.now(), - val scrapDialogVisibility: Boolean = false, - val internDialogVisibility: Boolean = false, + val scrapCancelDialogVisibility: Boolean = false, + val scrapDetailDialogVisibility: Boolean = false, val internshipAnnouncementId: Long? = null, val internshipModel: CalendarScrapDetail? = null ) \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt index 33a911d83..206530448 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekScreen.kt @@ -98,7 +98,7 @@ fun CalendarWeekRoute( }, onClickInternship = { scrapDetail -> with(viewModel) { - updateInternDialogVisibility(true) + updateScrapDetailDialogVisibility(true) updateInternshipModel(scrapDetail) } }, @@ -106,20 +106,20 @@ fun CalendarWeekRoute( CalendarWeekScrapPatchDialog( currentDate = calendarUiState.selectedDate, - dialogVisibility = uiState.internDialogVisibility, + dialogVisibility = uiState.scrapDetailDialogVisibility, internshipModel = uiState.internshipModel, navigateToAnnouncement = { announcementId -> navigateToAnnouncement(announcementId) - viewModel.updateInternDialogVisibility(false) + viewModel.updateScrapDetailDialogVisibility(false) }, - onDismissInternDialog = { viewModel.updateInternDialogVisibility(false) }, + onDismissInternDialog = { viewModel.updateScrapDetailDialogVisibility(false) }, onClickChangeColor = { viewModel.getScrapWeekList(calendarUiState.selectedDate) }, ) CalendarWeekScrapCancelDialog( - scrapVisibility = uiState.scrapDialogVisibility, + scrapVisibility = uiState.scrapCancelDialogVisibility, internshipAnnouncementId = uiState.internshipAnnouncementId, onDismissCancelDialog = { isCancelled -> viewModel.updateScrapCancelDialogVisibility(false) diff --git a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekViewModel.kt b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekViewModel.kt index 52c824dc6..1e4c17d4e 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekViewModel.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/CalendarWeekViewModel.kt @@ -21,38 +21,39 @@ import javax.inject.Inject @HiltViewModel class CalendarWeekViewModel @Inject constructor( private val calendarRepository: CalendarRepository -): ViewModel() { +) : ViewModel() { private val _uiState = MutableStateFlow(CalendarWeekUiState()) val uiState = _uiState.asStateFlow() private val _sideEffect: MutableSharedFlow = MutableSharedFlow() val sideEffect = _sideEffect.asSharedFlow() - fun updateScrapCancelDialogVisibility(visibility: Boolean) { - _uiState.update { currentState -> - currentState.copy( - scrapDialogVisibility = visibility - ) + fun updateInternshipAnnouncementId(internshipAnnouncementId: Long? = null) = + viewModelScope.launch { + _uiState.update { currentState -> + currentState.copy( + internshipAnnouncementId = internshipAnnouncementId + ) + } } - } - fun updateInternshipAnnouncementId(internshipAnnouncementId: Long? = null) { + fun updateScrapDetailDialogVisibility(visibility: Boolean) = viewModelScope.launch { _uiState.update { currentState -> currentState.copy( - internshipAnnouncementId = internshipAnnouncementId + scrapDetailDialogVisibility = visibility ) } } - fun updateInternDialogVisibility(visibility: Boolean) { + fun updateScrapCancelDialogVisibility(visibility: Boolean) = viewModelScope.launch { _uiState.update { currentState -> currentState.copy( - internDialogVisibility = visibility + scrapCancelDialogVisibility = visibility ) } } - fun updateInternshipModel(scrapDetailModel: CalendarScrapDetail?) { + fun updateInternshipModel(scrapDetailModel: CalendarScrapDetail?) = viewModelScope.launch { _uiState.update { currentState -> currentState.copy( internshipModel = scrapDetailModel diff --git a/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt b/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt index 18b586b77..e0326f7e8 100644 --- a/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt +++ b/feature/src/main/java/com/terning/feature/calendar/week/model/CalendarWeekUiState.kt @@ -5,8 +5,8 @@ import com.terning.domain.entity.calendar.CalendarScrapDetail data class CalendarWeekUiState( val loadState: UiState> = UiState.Loading, - val scrapDialogVisibility: Boolean = false, - val internDialogVisibility: Boolean = false, + val scrapCancelDialogVisibility: Boolean = false, + val scrapDetailDialogVisibility: Boolean = false, val internshipAnnouncementId: Long? = null, val internshipModel: CalendarScrapDetail? = null ) \ No newline at end of file From d0c05a3ec8414a757ac8dfb55f94c903e261bb63 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Sat, 14 Sep 2024 03:20:12 +0900 Subject: [PATCH 13/15] =?UTF-8?q?[DEL/#246]=20listState=20=EC=A0=84?= =?UTF-8?q?=EC=9A=A9=20=ED=95=A8=EC=88=98=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/model/CalendarDefault.kt | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarDefault.kt diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarDefault.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarDefault.kt deleted file mode 100644 index 1d2cf981a..000000000 --- a/feature/src/main/java/com/terning/feature/calendar/calendar/model/CalendarDefault.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.terning.feature.calendar.calendar.model - -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.gestures.FlingBehavior -import androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider -import androidx.compose.foundation.gestures.snapping.SnapPosition -import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember - -internal object CalendarDefaults { - /** - * Returns the fling behavior for the given [LazyListState]. - * From Github [https://github.com/kizitonwose/Calendar] - */ - @OptIn(ExperimentalFoundationApi::class) - @Composable - fun flingBehavior(state: LazyListState): FlingBehavior { - val snappingLayout = remember(state) { - val provider = SnapLayoutInfoProvider(state, SnapPosition.Start) - CalendarSnapLayoutInfoProvider(provider) - } - return rememberSnapFlingBehavior(snappingLayout) - } -} - -@ExperimentalFoundationApi -@Suppress("FunctionName") -private fun CalendarSnapLayoutInfoProvider( - snapLayoutInfoProvider: SnapLayoutInfoProvider, -): SnapLayoutInfoProvider = object : SnapLayoutInfoProvider by snapLayoutInfoProvider { - override fun calculateApproachOffset(velocity: Float, decayOffset: Float): Float = 0f -} \ No newline at end of file From 05c6f89906f10f282c1b3e49ff4bb76a52c1f643 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Sat, 14 Sep 2024 19:23:19 +0900 Subject: [PATCH 14/15] =?UTF-8?q?[FIX/#246]=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/terning/feature/calendar/calendar/CalendarRoute.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 640b2ca55..fd8e24bd2 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 @@ -131,7 +131,10 @@ private fun CalendarScreen( contentOne = { CalendarMonthRoute( selectedDate = uiState.selectedDate, - updateSelectedDate = onClickNewDate, + updateSelectedDate = { newDate -> + if(!pagerState.isScrollInProgress) + onClickNewDate(newDate) + }, modifier = Modifier .fillMaxSize() .background(White), From f40f734943f0a19a342e46dba694711d0d1466e1 Mon Sep 17 00:00:00 2001 From: boiledegg Date: Sat, 14 Sep 2024 19:31:57 +0900 Subject: [PATCH 15/15] =?UTF-8?q?[MOD/#246]=20=EA=B8=B0=ED=83=80=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/navigation/CalendarNavigation.kt | 17 +---------------- .../calendar/month/CalendarMonthScreen.kt | 7 +++---- .../calendar/month/CalendarMonthViewModel.kt | 6 ++++-- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/calendar/calendar/navigation/CalendarNavigation.kt b/feature/src/main/java/com/terning/feature/calendar/calendar/navigation/CalendarNavigation.kt index 7aa5db891..61c158402 100644 --- a/feature/src/main/java/com/terning/feature/calendar/calendar/navigation/CalendarNavigation.kt +++ b/feature/src/main/java/com/terning/feature/calendar/calendar/navigation/CalendarNavigation.kt @@ -1,7 +1,5 @@ package com.terning.feature.calendar.calendar.navigation -import androidx.compose.animation.EnterTransition -import androidx.compose.animation.ExitTransition import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.padding import androidx.compose.ui.Modifier @@ -26,20 +24,7 @@ fun NavGraphBuilder.calendarNavGraph( navHostController: NavController, paddingValues: PaddingValues ) { - composable( - exitTransition = { - ExitTransition.None - }, - popEnterTransition = { - EnterTransition.None - }, - enterTransition = { - EnterTransition.None - }, - popExitTransition = { - ExitTransition.None - } - ) { + composable { CalendarRoute( modifier = Modifier.padding(paddingValues), navigateToAnnouncement = navHostController::navigateIntern diff --git a/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt b/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt index 9c530b282..b0bade11e 100644 --- a/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt +++ b/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthScreen.kt @@ -45,10 +45,9 @@ fun CalendarMonthRoute( } LaunchedEffect(key1 = pagerState) { - snapshotFlow { pagerState.settledPage } - .collect { settled-> - val date = getLocalDateByPage(settled) - viewModel.getScrapMonth(date.year, date.monthValue) + snapshotFlow { pagerState.currentPage } + .collect { currentPage-> + viewModel.getScrapMonth(currentPage) } } diff --git a/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthViewModel.kt b/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthViewModel.kt index fbcd6dcb1..c3307f779 100644 --- a/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthViewModel.kt +++ b/feature/src/main/java/com/terning/feature/calendar/month/CalendarMonthViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope import com.terning.core.state.UiState import com.terning.domain.repository.CalendarRepository import com.terning.feature.R +import com.terning.feature.calendar.calendar.model.CalendarModel.Companion.getLocalDateByPage import com.terning.feature.calendar.month.model.CalendarMonthUiState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers @@ -27,9 +28,10 @@ class CalendarMonthViewModel @Inject constructor( val sideEffect = _sideEffect.asSharedFlow() fun getScrapMonth( - year: Int, month: Int + currentPage: Int ) = viewModelScope.launch(Dispatchers.IO) { - calendarRepository.getScrapMonth(year, month) + val date = getLocalDateByPage(currentPage) + calendarRepository.getScrapMonth(date.year, date.monthValue) .fold( onSuccess = { _uiState.update { currentState ->