Skip to content

Commit

Permalink
refactor/253 공연 관련 화면 마이그레이션
Browse files Browse the repository at this point in the history
  • Loading branch information
mangbaam committed Dec 31, 2024
1 parent 11a3224 commit eb2e04c
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,16 @@ fun MainNavigation(
reservationDetailScreen()
refundScreen()

navigation<MainRoute.ShowDetail>(
navigation<ShowRoute.ShowRoot>(
startDestination = ShowRoute.Detail,
deepLinks = listOf(
navDeepLink {
uriPattern = "https://preview.boolti.in/show/{$showId}"
uriPattern = "https://preview.boolti.in/show/{showId}"
action = Intent.ACTION_VIEW
},
),
) {
showDetailScreen(
navigateTo = navController::navigateTo,
getSharedViewModel = { entry -> entry.sharedViewModel() }
)
showImagesScreen(
Expand Down Expand Up @@ -195,5 +194,3 @@ inline fun <reified T : ViewModel> NavBackStackEntry.sharedViewModel(
}
return hiltViewModel(parentEntry)
}

private fun NavController.navigateTo(route: String) = navigate(route)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@ package com.nexters.boolti.presentation.screen
sealed class MainDestination(val route: String) {
data object ShowRegistration : MainDestination(route = "webView")
}

/**
* arguments
*/
const val showId = "showId"
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ fun NavGraphBuilder.giftCompleteScreen() {
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.navigation.compose.composable
import com.nexters.boolti.presentation.screen.LocalNavController
import com.nexters.boolti.presentation.screen.MainDestination
import com.nexters.boolti.presentation.screen.navigation.MainRoute
import com.nexters.boolti.presentation.screen.navigation.ShowRoute
import com.nexters.boolti.presentation.screen.navigation.TicketRoute

fun NavGraphBuilder.homeScreen(
Expand All @@ -15,7 +16,7 @@ fun NavGraphBuilder.homeScreen(
val navController = LocalNavController.current
HomeScreen(
modifier = modifier,
navigateToShowDetail = { navController.navigate(MainRoute.ShowDetail(showId = it)) },
navigateToShowDetail = { navController.navigate(ShowRoute.ShowRoot(showId = it)) },
navigateToTicketDetail = { navController.navigate(TicketRoute.TicketRoot(ticketId = it)) },
navigateToQrScan = { navController.navigate(MainRoute.HostedShows) },
navigateToAccountSetting = { navController.navigate(MainRoute.AccountSetting) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ sealed interface MainRoute {
@Serializable
data object Home : MainRoute

@Serializable
data class ShowDetail(
val showId: String,
) : MainRoute

@Serializable
data class Ticketing(
val showId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@ package com.nexters.boolti.presentation.screen.navigation

import kotlinx.serialization.Serializable

// todo : 리팩토링 예정
sealed interface ShowRoute {
@Serializable
data object Detail
}
data class ShowRoot(
val showId: String,
) : ShowRoute

@Serializable
data object Detail : ShowRoute

@Serializable
data class Images(
val index: Int,
) : ShowRoute

@Serializable
data object Content : ShowRoute

@Serializable
data class Report(
val showId: String?,
) : ShowRoute
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.navigation.toRoute
import com.nexters.boolti.presentation.extension.navigateToHome
import com.nexters.boolti.presentation.screen.LocalNavController
import com.nexters.boolti.presentation.screen.navigation.MainRoute
import com.nexters.boolti.presentation.screen.navigation.ShowRoute

fun NavGraphBuilder.paymentCompleteScreen() {
composable<MainRoute.PaymentComplete> { entry ->
Expand All @@ -17,8 +18,8 @@ fun NavGraphBuilder.paymentCompleteScreen() {
PaymentCompleteScreen(
onClickHome = navController::navigateToHome,
onClickClose = {
navController.popBackStack<MainRoute.ShowDetail>(inclusive = true)
navController.navigate(MainRoute.ShowDetail(showId = showId))
navController.popBackStack<ShowRoute.ShowRoot>(inclusive = true)
navController.navigate(ShowRoute.ShowRoot(showId = showId))
},
navigateToReservation = { reservation ->
navController.navigate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.nexters.boolti.presentation.screen.LocalNavController
import com.nexters.boolti.presentation.screen.navigation.MainRoute
import com.nexters.boolti.presentation.screen.navigation.ShowRoute

fun NavGraphBuilder.performedShowsScreen(
modifier: Modifier = Modifier,
Expand All @@ -14,7 +15,7 @@ fun NavGraphBuilder.performedShowsScreen(
PerformedShowsScreen(
modifier = modifier,
onClickShow = { show ->
navController.navigate(MainRoute.ShowDetail(showId = show.id))
navController.navigate(ShowRoute.ShowRoot(showId = show.id))
},
onClickBack = navController::popBackStack,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.navigation.compose.composable
import com.nexters.boolti.presentation.screen.LocalNavController
import com.nexters.boolti.presentation.screen.navigation.MainRoute
import com.nexters.boolti.presentation.screen.navigation.ProfileRoute
import com.nexters.boolti.presentation.screen.navigation.ShowRoute

fun NavGraphBuilder.profileScreen(
modifier: Modifier = Modifier,
Expand All @@ -22,7 +23,7 @@ fun NavGraphBuilder.profileScreen(
navController.navigate(MainRoute.PerformedShows(userCode))
},
navigateToProfileEdit = { navController.navigate(ProfileRoute.ProfileEdit) },
navigateToShow = { showId -> navController.navigate(MainRoute.ShowDetail(showId = showId)) },
navigateToShow = { showId -> navController.navigate(ShowRoute.ShowRoot(showId = showId)) },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.nexters.boolti.presentation.extension.navigateToHome
import com.nexters.boolti.presentation.screen.LocalNavController
import com.nexters.boolti.presentation.screen.navigation.ShowRoute

fun NavGraphBuilder.reportScreen(
modifier: Modifier = Modifier,
) {
composable(
route = "report/{showId}",
) {
composable<ShowRoute.Report> {
val navController = LocalNavController.current
ReportScreen(
onBackPressed = navController::popBackStack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ package com.nexters.boolti.presentation.screen.report

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.toRoute
import com.nexters.boolti.presentation.screen.navigation.ShowRoute
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import javax.inject.Inject

@HiltViewModel
class ReportViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
) : ViewModel() {
private val showId: String = checkNotNull(savedStateHandle["showId"]) {
private val showId: String = checkNotNull(savedStateHandle.toRoute<ShowRoute.Report>().showId) {
"showId가 전달되어야 합니다."
}

Expand All @@ -27,4 +25,4 @@ class ReportViewModel @Inject constructor(
fun updateReason(newReason: String) {
_uiState.update { it.copy(reason = newReason) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.nexters.boolti.presentation.screen.LocalNavController
import com.nexters.boolti.presentation.screen.navigation.ShowRoute

fun NavGraphBuilder.showDetailContentScreen(
getSharedViewModel: @Composable (NavBackStackEntry) -> ShowDetailViewModel,
modifier: Modifier = Modifier,
) {
composable(
route = "content",
) { entry ->
composable<ShowRoute.Content> { entry ->
val navController = LocalNavController.current
val showViewModel: ShowDetailViewModel = getSharedViewModel(entry)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.nexters.boolti.presentation.screen.navigation.MainRoute
import com.nexters.boolti.presentation.screen.navigation.ShowRoute

fun NavGraphBuilder.showDetailScreen(
navigateTo: (String) -> Unit,
getSharedViewModel: @Composable (NavBackStackEntry) -> ShowDetailViewModel,
modifier: Modifier = Modifier,
) {
Expand All @@ -23,7 +22,7 @@ fun NavGraphBuilder.showDetailScreen(
modifier = modifier,
onBack = navController::popBackStack,
onClickHome = navController::navigateToHome,
onClickContent = { navigateTo("content") },
onClickContent = { navController.navigate(ShowRoute.Content) },
onTicketSelected = { showId, ticketId, ticketCount, isInviteTicket ->
navController.navigate(
MainRoute.Ticketing(
Expand All @@ -45,10 +44,10 @@ fun NavGraphBuilder.showDetailScreen(
},
viewModel = showViewModel,
navigateToLogin = { navController.navigate(MainRoute.Login) },
navigateToImages = { index -> navigateTo("images/$index") },
navigateToImages = { index -> navController.navigate(ShowRoute.Images(index)) },
navigateToReport = {
val showId = entry.arguments?.getString("showId")
navigateTo("report/$showId")
navController.navigate(ShowRoute.Report(showId))
},
navigateToProfile = { userCode ->
navController.navigate(MainRoute.Profile(userCode = userCode))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.nexters.boolti.presentation.screen.showdetail
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.toRoute
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import com.nexters.boolti.domain.repository.AuthRepository
import com.nexters.boolti.domain.repository.ShowRepository
import com.nexters.boolti.presentation.screen.navigation.ShowRoute
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
Expand All @@ -27,7 +29,7 @@ class ShowDetailViewModel @Inject constructor(
private val showRepository: ShowRepository,
authRepository: AuthRepository,
) : ViewModel() {
val showId: String = checkNotNull(savedStateHandle["showId"])
val showId: String = checkNotNull(savedStateHandle.toRoute<ShowRoute.ShowRoot>().showId)

private val _uiState = MutableStateFlow(ShowDetailUiState())
val uiState: StateFlow<ShowDetailUiState> = _uiState.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ package com.nexters.boolti.presentation.screen.showdetail
import androidx.compose.runtime.Composable
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import androidx.navigation.toRoute
import com.nexters.boolti.presentation.screen.LocalNavController
import com.nexters.boolti.presentation.screen.navigation.ShowRoute

fun NavGraphBuilder.showImagesScreen(
getSharedViewModel: @Composable (NavBackStackEntry) -> ShowDetailViewModel,
) {
composable(
route = "images/{index}",
arguments = listOf(navArgument("index") { type = NavType.IntType }),
) { entry ->
composable<ShowRoute.Images> { entry ->
val navController = LocalNavController.current
val showViewModel: ShowDetailViewModel = getSharedViewModel(entry)
val index = entry.arguments!!.getInt("index")
val index = entry.toRoute<ShowRoute.Images>().index

ShowImagesScreen(
index = index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import com.nexters.boolti.presentation.extension.toDp
import com.nexters.boolti.presentation.extension.toPx
import com.nexters.boolti.presentation.screen.LocalNavController
import com.nexters.boolti.presentation.screen.LocalSnackbarController
import com.nexters.boolti.presentation.screen.navigation.MainRoute
import com.nexters.boolti.presentation.screen.navigation.ShowRoute
import com.nexters.boolti.presentation.screen.navigation.TicketRoute
import com.nexters.boolti.presentation.screen.qr.QrCoverView
import com.nexters.boolti.presentation.theme.BooltiTheme
Expand Down Expand Up @@ -124,7 +124,7 @@ fun NavGraphBuilder.ticketDetailScreen(
modifier = modifier,
onBackClicked = navController::popBackStack,
onClickQr = { navController.navigate(TicketRoute.Qr) },
navigateToShowDetail = { navController.navigate(MainRoute.ShowDetail(showId = it)) },
navigateToShowDetail = { navController.navigate(ShowRoute.ShowRoot(showId = it)) },
viewModel = getSharedViewModel(entry),
)
}
Expand Down

0 comments on commit eb2e04c

Please sign in to comment.