From 34d219ba8ffdb8980bcb1b8c291de3be5a811c38 Mon Sep 17 00:00:00 2001 From: Hitoshi KAMADA Date: Fri, 23 Aug 2024 16:53:19 +0900 Subject: [PATCH 1/3] Implement list animation on TimetableTime and timetable items of FavoriteList. --- .../droidkaigi/confsched/favorites/section/FavoriteList.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt index 6ddfb32e5..b072e2fd7 100644 --- a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt +++ b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt @@ -1,5 +1,6 @@ package io.github.droidkaigi.confsched.favorites.section +import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -47,7 +48,7 @@ import kotlinx.collections.immutable.PersistentMap import kotlinx.collections.immutable.persistentMapOf import org.jetbrains.compose.ui.tooling.preview.Preview -@OptIn(ExperimentalMaterial3WindowSizeClassApi::class) +@OptIn(ExperimentalMaterial3WindowSizeClassApi::class, ExperimentalFoundationApi::class) @Composable fun FavoriteList( timetableItemMap: PersistentMap>, @@ -99,7 +100,8 @@ fun FavoriteList( modifier = Modifier .onGloballyPositioned { rowHeight = it.size.height - }, + } + .animateItemPlacement(), ) { TimetableTime( modifier = Modifier From a8048015ee722eb9687824957c701efa762df466 Mon Sep 17 00:00:00 2001 From: Hitoshi KAMADA Date: Thu, 29 Aug 2024 09:21:42 +0900 Subject: [PATCH 2/3] Implement list animation on TimetableItemCard. --- .../confsched/favorites/FavoritesScreen.kt | 2 + .../favorites/FavoritesScreenPresenter.kt | 6 +- .../favorites/section/FavoriteList.kt | 92 +++++++++++-------- .../favorites/section/FavoriteSheet.kt | 4 + 4 files changed, 64 insertions(+), 40 deletions(-) diff --git a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreen.kt b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreen.kt index 97b384a5a..219cd20ec 100644 --- a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreen.kt +++ b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreen.kt @@ -36,6 +36,7 @@ import io.github.droidkaigi.confsched.favorites.section.FavoriteSheet import io.github.droidkaigi.confsched.favorites.section.FavoritesSheetUiState import io.github.droidkaigi.confsched.favorites.section.FavoritesSheetUiState.FavoriteListUiState.TimeSlot import io.github.droidkaigi.confsched.model.DroidKaigi2024Day +import io.github.droidkaigi.confsched.model.Timetable import io.github.droidkaigi.confsched.model.TimetableItem import io.github.droidkaigi.confsched.model.TimetableItem.Session import io.github.droidkaigi.confsched.model.fake @@ -184,6 +185,7 @@ fun FavoritesScreenPreview() { Session.fake(), ), ), + timetable = Timetable.fake() ), userMessageStateHolder = UserMessageStateHolderImpl(), ), diff --git a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreenPresenter.kt b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreenPresenter.kt index f06ddbac0..aacf91509 100644 --- a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreenPresenter.kt +++ b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreenPresenter.kt @@ -42,9 +42,7 @@ fun favoritesScreenPresenter( sessionsRepository: SessionsRepository = localSessionsRepository(), ): FavoritesScreenUiState = providePresenterDefaults { userMessageStateHolder -> val favoriteSessions by rememberUpdatedState( - sessionsRepository - .timetable() - .filtered(Filters(filterFavorite = true)), + sessionsRepository.timetable() ) var allFilterSelected by remember { mutableStateOf(true) } var currentDayFilters by remember { mutableStateOf(emptySet()) } @@ -102,7 +100,6 @@ private fun favoritesSheet( favoriteSessions .filtered( Filters( - filterFavorite = true, days = selectedDayFilters.toList(), ), ) @@ -125,6 +122,7 @@ private fun favoritesSheet( currentDayFilter = selectedDayFilters.toPersistentList(), allFilterSelected = allFilterSelected, timetableItemMap = filteredSessions, + timetable = favoriteSessions ) } } diff --git a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt index b072e2fd7..bee5aadb1 100644 --- a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt +++ b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt @@ -1,5 +1,8 @@ package io.github.droidkaigi.confsched.favorites.section +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement @@ -41,6 +44,7 @@ import io.github.droidkaigi.confsched.droidkaigiui.component.TimetableItemTag import io.github.droidkaigi.confsched.droidkaigiui.component.TimetableTime import io.github.droidkaigi.confsched.droidkaigiui.icon import io.github.droidkaigi.confsched.favorites.section.FavoritesSheetUiState.FavoriteListUiState.TimeSlot +import io.github.droidkaigi.confsched.model.Timetable import io.github.droidkaigi.confsched.model.TimetableItem import io.github.droidkaigi.confsched.model.TimetableItem.Session import io.github.droidkaigi.confsched.model.fake @@ -52,6 +56,7 @@ import org.jetbrains.compose.ui.tooling.preview.Preview @Composable fun FavoriteList( timetableItemMap: PersistentMap>, + timetable: Timetable, onBookmarkClick: (TimetableItem) -> Unit, onTimetableItemClick: (TimetableItem) -> Unit, modifier: Modifier = Modifier, @@ -103,15 +108,19 @@ fun FavoriteList( } .animateItemPlacement(), ) { - TimetableTime( - modifier = Modifier - .onGloballyPositioned { - timeTextHeight = it.size.height - } - .offset { IntOffset(0, timeTextOffset) }, - startTime = time.startTimeString, - endTime = time.endTimeString, - ) + val bookmarkedTimetableItems = timetableItems.filter { timetable.bookmarks.contains(it.id) } + + if (bookmarkedTimetableItems.isNotEmpty()) { + TimetableTime( + modifier = Modifier + .onGloballyPositioned { + timeTextHeight = it.size.height + } + .offset { IntOffset(0, timeTextOffset) }, + startTime = time.startTimeString, + endTime = time.endTimeString, + ) + } Spacer(modifier = Modifier.width(16.dp)) Column(verticalArrangement = Arrangement.spacedBy(12.dp)) { timetableItems.windowed(columnNum, columnNum, true).forEach { windowedItems -> @@ -120,35 +129,45 @@ fun FavoriteList( horizontalArrangement = Arrangement.spacedBy(12.dp), ) { windowedItems.onEach { timetableItem -> - TimetableItemCard( - modifier = Modifier - .weight(1F) - .fillMaxHeight(), - isBookmarked = true, - tags = { - TimetableItemTag( - tagText = timetableItem.room.name.currentLangTitle, - icon = timetableItem.room.icon, - tagColor = LocalRoomTheme.current.primaryColor, - modifier = Modifier.background(LocalRoomTheme.current.containerColor), - ) - timetableItem.language.labels.forEach { label -> + val isBookmarked = + timetable.bookmarks.contains(timetableItem.id) + AnimatedVisibility( + visible = isBookmarked, + enter = fadeIn(), + exit = fadeOut() + ) { + TimetableItemCard( + modifier = Modifier + .weight(1F) + .fillMaxHeight(), + isBookmarked = true, + tags = { TimetableItemTag( - tagText = label, - tagColor = MaterialTheme.colorScheme.outline, + tagText = timetableItem.room.name.currentLangTitle, + icon = timetableItem.room.icon, + tagColor = LocalRoomTheme.current.primaryColor, + modifier = Modifier.background( + LocalRoomTheme.current.containerColor + ), ) - } - timetableItem.day?.let { - TimetableItemTag( - tagText = "9/${it.dayOfMonth}", - tagColor = MaterialTheme.colorScheme.outline, - ) - } - }, - timetableItem = timetableItem, - onTimetableItemClick = onTimetableItemClick, - onBookmarkClick = { item, _ -> onBookmarkClick(item) }, - ) + timetableItem.language.labels.forEach { label -> + TimetableItemTag( + tagText = label, + tagColor = MaterialTheme.colorScheme.outline, + ) + } + timetableItem.day?.let { + TimetableItemTag( + tagText = "9/${it.dayOfMonth}", + tagColor = MaterialTheme.colorScheme.outline, + ) + } + }, + timetableItem = timetableItem, + onTimetableItemClick = onTimetableItemClick, + onBookmarkClick = { item, _ -> onBookmarkClick(item) }, + ) + } } if (windowedItems.size < columnNum) { repeat(columnNum - windowedItems.size) { @@ -177,6 +196,7 @@ fun FavoriteListPreview() { Session.fake(), ), ), + timetable = Timetable.fake(), onBookmarkClick = {}, onTimetableItemClick = {}, ) diff --git a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteSheet.kt b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteSheet.kt index d7e302de4..0f18c66d4 100644 --- a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteSheet.kt +++ b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteSheet.kt @@ -38,6 +38,7 @@ import io.github.droidkaigi.confsched.favorites.section.FavoritesSheetUiState.Fa import io.github.droidkaigi.confsched.model.DroidKaigi2024Day import io.github.droidkaigi.confsched.model.DroidKaigi2024Day.ConferenceDay1 import io.github.droidkaigi.confsched.model.DroidKaigi2024Day.ConferenceDay2 +import io.github.droidkaigi.confsched.model.Timetable import io.github.droidkaigi.confsched.model.TimetableItem import io.github.droidkaigi.confsched.model.TimetableItem.Session import io.github.droidkaigi.confsched.model.fake @@ -64,6 +65,7 @@ sealed interface FavoritesSheetUiState { override val currentDayFilter: PersistentList, override val allFilterSelected: Boolean, val timetableItemMap: PersistentMap>, + val timetable: Timetable, ) : FavoritesSheetUiState { data class TimeSlot( val startTimeString: String, @@ -122,6 +124,7 @@ fun FavoriteSheet( is FavoritesSheetUiState.FavoriteListUiState -> { FavoriteList( timetableItemMap = uiState.timetableItemMap, + timetable = uiState.timetable, onBookmarkClick = onBookmarkClick, onTimetableItemClick = onTimetableItemClick, contentPadding = contentPadding, @@ -192,6 +195,7 @@ fun FavoriteSheetPreview() { Session.fake(), ), ), + timetable = Timetable.fake() ), filterBackgroundColor = MaterialTheme.colorScheme.surface, onAllFilterChipClick = {}, From 78ba9624169358b34aabdd596c211c74cd754d37 Mon Sep 17 00:00:00 2001 From: Hitoshi KAMADA Date: Fri, 30 Aug 2024 09:32:53 +0900 Subject: [PATCH 3/3] Correct the formatting errors. --- .../github/droidkaigi/confsched/favorites/FavoritesScreen.kt | 2 +- .../confsched/favorites/FavoritesScreenPresenter.kt | 4 ++-- .../droidkaigi/confsched/favorites/section/FavoriteList.kt | 4 ++-- .../droidkaigi/confsched/favorites/section/FavoriteSheet.kt | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreen.kt b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreen.kt index 219cd20ec..4d5ce153b 100644 --- a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreen.kt +++ b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreen.kt @@ -185,7 +185,7 @@ fun FavoritesScreenPreview() { Session.fake(), ), ), - timetable = Timetable.fake() + timetable = Timetable.fake(), ), userMessageStateHolder = UserMessageStateHolderImpl(), ), diff --git a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreenPresenter.kt b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreenPresenter.kt index aacf91509..e27c7cbcb 100644 --- a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreenPresenter.kt +++ b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/FavoritesScreenPresenter.kt @@ -42,7 +42,7 @@ fun favoritesScreenPresenter( sessionsRepository: SessionsRepository = localSessionsRepository(), ): FavoritesScreenUiState = providePresenterDefaults { userMessageStateHolder -> val favoriteSessions by rememberUpdatedState( - sessionsRepository.timetable() + sessionsRepository.timetable(), ) var allFilterSelected by remember { mutableStateOf(true) } var currentDayFilters by remember { mutableStateOf(emptySet()) } @@ -122,7 +122,7 @@ private fun favoritesSheet( currentDayFilter = selectedDayFilters.toPersistentList(), allFilterSelected = allFilterSelected, timetableItemMap = filteredSessions, - timetable = favoriteSessions + timetable = favoriteSessions, ) } } diff --git a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt index bee5aadb1..045cbf9c8 100644 --- a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt +++ b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteList.kt @@ -134,7 +134,7 @@ fun FavoriteList( AnimatedVisibility( visible = isBookmarked, enter = fadeIn(), - exit = fadeOut() + exit = fadeOut(), ) { TimetableItemCard( modifier = Modifier @@ -147,7 +147,7 @@ fun FavoriteList( icon = timetableItem.room.icon, tagColor = LocalRoomTheme.current.primaryColor, modifier = Modifier.background( - LocalRoomTheme.current.containerColor + LocalRoomTheme.current.containerColor, ), ) timetableItem.language.labels.forEach { label -> diff --git a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteSheet.kt b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteSheet.kt index 0f18c66d4..a0b32ee2a 100644 --- a/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteSheet.kt +++ b/feature/favorites/src/commonMain/kotlin/io/github/droidkaigi/confsched/favorites/section/FavoriteSheet.kt @@ -195,7 +195,7 @@ fun FavoriteSheetPreview() { Session.fake(), ), ), - timetable = Timetable.fake() + timetable = Timetable.fake(), ), filterBackgroundColor = MaterialTheme.colorScheme.surface, onAllFilterChipClick = {},