Skip to content

Commit

Permalink
Merge pull request #423 from hiraike32/feature/navigate-session-detai…
Browse files Browse the repository at this point in the history
…l-to-favorite-list

Navigate from session detail to favorite list by snackbar action
  • Loading branch information
takahirom authored Aug 15, 2024
2 parents d9de76d + 58d6b74 commit 54107f0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.annotation.RequiresApi
import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.animation.ExperimentalSharedTransitionApi
import androidx.compose.animation.SharedTransitionLayout
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
Expand Down Expand Up @@ -120,6 +121,7 @@ private fun KaigiNavHost(
onLinkClick = externalNavController::navigate,
onCalendarRegistrationClick = externalNavController::navigateToCalendarRegistration,
onShareClick = externalNavController::onShareClick,
onFavoriteListClick = { navController.navigate(favoritesScreenRoute) },
)

contributorsScreens(
Expand All @@ -141,6 +143,11 @@ private fun KaigiNavHost(
onNavigationIconClick = navController::popBackStack,
onSponsorsItemClick = externalNavController::navigate,
)

favoritesScreens(
onTimetableItemClick = navController::navigateToTimetableItemDetailScreen,
contentPadding = PaddingValues(),
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private fun KaigiNavHost(
onShareClick = {
navController.navigate(contributorsScreenRoute)
},
onFavoriteListClick = {} // { navController.navigate(favoritesScreenRoute) }
)

// For KMP, we are not using navigation abstraction for contributors screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TimetableItemDetailScreenRobot @Inject constructor(
onLinkClick = { },
onCalendarRegistrationClick = { },
onShareClick = { },
onFavoriteListClick = { },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import io.github.droidkaigi.confsched.model.TimetableItemId
import io.github.droidkaigi.confsched.model.TimetableSessionType.NORMAL
import io.github.droidkaigi.confsched.model.localSessionsRepository
import io.github.droidkaigi.confsched.sessions.TimetableItemDetailEvent.Bookmark
import io.github.droidkaigi.confsched.sessions.TimetableItemDetailEvent.FavoriteListNavigated
import io.github.droidkaigi.confsched.sessions.TimetableItemDetailEvent.SelectDescriptionLanguage
import io.github.droidkaigi.confsched.sessions.TimetableItemDetailEvent.ViewBookmarkListRequestCompleted
import io.github.droidkaigi.confsched.sessions.TimetableItemDetailScreenUiState.Loaded
import io.github.droidkaigi.confsched.sessions.TimetableItemDetailScreenUiState.Loading
import io.github.droidkaigi.confsched.ui.UserMessageResult.ActionPerformed
import io.github.droidkaigi.confsched.ui.providePresenterDefaults
import io.github.droidkaigi.confsched.ui.rememberNavigationArgument
import kotlinx.coroutines.flow.SharedFlow
Expand All @@ -29,7 +30,7 @@ import org.jetbrains.compose.resources.stringResource
sealed interface TimetableItemDetailEvent {
data class Bookmark(val timetableItem: TimetableItem) : TimetableItemDetailEvent
data class SelectDescriptionLanguage(val language: Lang) : TimetableItemDetailEvent
data object ViewBookmarkListRequestCompleted : TimetableItemDetailEvent
data object FavoriteListNavigated : TimetableItemDetailEvent
}

@Composable
Expand All @@ -47,6 +48,7 @@ fun timetableItemDetailPresenter(
.timetableItemWithBookmark(timetableItemId),
)
var selectedDescriptionLanguage by remember { mutableStateOf<Lang?>(null) }
var shouldGoToFavoriteList by remember { mutableStateOf(false) }
val bookmarkedSuccessfullyString = stringResource(SessionsRes.string.bookmarked_successfully)
val viewBookmarkListString = stringResource(SessionsRes.string.view_bookmark_list)

Expand All @@ -60,20 +62,24 @@ fun timetableItemDetailPresenter(
sessionsRepository.toggleBookmark(timetableItem.id)
val oldBookmarked = timetableItemWithBookmark.second
if (!oldBookmarked) {
userMessageStateHolder.showMessage(
val result = userMessageStateHolder.showMessage(
message = bookmarkedSuccessfullyString,
actionLabel = viewBookmarkListString,
duration = Short,
)
if (result == ActionPerformed) {
shouldGoToFavoriteList = true
}
}
}

is ViewBookmarkListRequestCompleted -> {
}

is SelectDescriptionLanguage -> {
selectedDescriptionLanguage = event.language
}

is FavoriteListNavigated -> {
shouldGoToFavoriteList = false
}
}
}
}
Expand All @@ -95,5 +101,6 @@ fun timetableItemDetailPresenter(
roomThemeKey = timetableItem.room.getThemeKey(),
timetableItemId = timetableItemId,
userMessageStateHolder = userMessageStateHolder,
shouldGoToFavoriteList = shouldGoToFavoriteList,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -61,6 +62,7 @@ fun NavGraphBuilder.sessionScreens(
onLinkClick: (url: String) -> Unit,
onCalendarRegistrationClick: (TimetableItem) -> Unit,
onShareClick: (TimetableItem) -> Unit,
onFavoriteListClick: () -> Unit,
) {
composable<TimetableItemDetailDestination> {
CompositionLocalProvider(
Expand All @@ -71,6 +73,7 @@ fun NavGraphBuilder.sessionScreens(
onLinkClick = onLinkClick,
onCalendarRegistrationClick = onCalendarRegistrationClick,
onShareClick = onShareClick,
onFavoriteListClick = onFavoriteListClick,
)
}
}
Expand All @@ -88,6 +91,7 @@ fun TimetableItemDetailScreen(
onLinkClick: (url: String) -> Unit,
onCalendarRegistrationClick: (TimetableItem) -> Unit,
onShareClick: (TimetableItem) -> Unit,
onFavoriteListClick: () -> Unit,
eventEmitter: EventEmitter<TimetableItemDetailEvent> = rememberEventEmitter(),
uiState: TimetableItemDetailScreenUiState = timetableItemDetailPresenter(
events = eventEmitter,
Expand All @@ -99,6 +103,13 @@ fun TimetableItemDetailScreen(
userMessageStateHolder = uiState.userMessageStateHolder,
)

LaunchedEffect(uiState is Loaded && uiState.shouldGoToFavoriteList) {
if (uiState is Loaded && uiState.shouldGoToFavoriteList) {
eventEmitter.tryEmit(TimetableItemDetailEvent.FavoriteListNavigated)
onFavoriteListClick()
}
}

TimetableItemDetailScreen(
uiState = uiState,
onNavigationIconClick = onNavigationIconClick,
Expand Down Expand Up @@ -128,6 +139,7 @@ sealed interface TimetableItemDetailScreenUiState {
val isLangSelectable: Boolean,
val currentLang: Lang?,
val roomThemeKey: String,
val shouldGoToFavoriteList: Boolean,
override val timetableItemId: TimetableItemId,
override val userMessageStateHolder: UserMessageStateHolder,
) : TimetableItemDetailScreenUiState
Expand Down Expand Up @@ -272,6 +284,7 @@ fun TimetableItemDetailScreenPreview() {
roomThemeKey = "iguana",
timetableItemId = fakeSession.id,
userMessageStateHolder = UserMessageStateHolderImpl(),
shouldGoToFavoriteList = false,
),
onNavigationIconClick = {},
onBookmarkClick = {
Expand All @@ -287,4 +300,5 @@ fun TimetableItemDetailScreenPreview() {
}
}

internal fun timetableDetailSharedContentStateKey(timetableItemId: TimetableItemId) = "timetable-item-${timetableItemId.value}"
internal fun timetableDetailSharedContentStateKey(timetableItemId: TimetableItemId) =
"timetable-item-${timetableItemId.value}"

0 comments on commit 54107f0

Please sign in to comment.