Last active
July 18, 2025 12:09
-
-
Save ifucolo/9df4ad833cdddcab5e3aef08d45d3ff4 to your computer and use it in GitHub Desktop.
ChapletFlowActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ChapletFlowActivity : ComponentActivity() { | |
| private val viewModel: ChapletFlowViewModel by viewModel() | |
| companion object { | |
| const val EXTRA_CHAPLET_NAME = "extra_terco_object_key" | |
| fun newIntent(context: Context, chapletName: String): Intent { | |
| return Intent(context, ChapletFlowActivity::class.java).apply { | |
| putExtra(EXTRA_CHAPLET_NAME, chapletName) | |
| } | |
| } | |
| } | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| val chapletName = intent?.getStringExtra(EXTRA_CHAPLET_NAME) | |
| ?: run { | |
| toast(getString(R.string.error_loading)) | |
| finish() | |
| return | |
| } | |
| viewModel.initializeFlow(chapletId) | |
| setContent { | |
| SanctusAppTheme { | |
| SetupNavigation() | |
| } | |
| } | |
| } | |
| @Composable | |
| private fun SetupNavigation() { | |
| val backStack = viewModel.backStack | |
| BackHandler(enabled = backStack.size > 1) { | |
| viewModel.popBackStack() | |
| } | |
| NavDisplay( | |
| backStack = backStack, | |
| onBack = { | |
| if (!viewModel.popBackStack()) { | |
| finish() | |
| } | |
| }, | |
| entryDecorators = listOf( | |
| rememberSceneSetupNavEntryDecorator(), | |
| rememberSavedStateNavEntryDecorator(), | |
| rememberViewModelStoreNavEntryDecorator() | |
| ), | |
| entryProvider = entryProvider { | |
| entry<ChapletStartStep> { | |
| ChapletStartStepScreen( | |
| onPrayStart = { | |
| viewModel.onPrayStart() | |
| } | |
| ) | |
| } | |
| entry<ChapletPray> { | |
| ChapletPrayScreen( | |
| chapletName = it.chapletName, | |
| onClose = { | |
| finish() | |
| }, | |
| onFinish = { | |
| viewModel.onPrayFinish() | |
| } | |
| ) | |
| } | |
| entry<ChapletDone> { | |
| ChapletFeedbackScreen( | |
| onFinish = { | |
| finish() | |
| } | |
| ) | |
| } | |
| }, | |
| transitionSpec = { | |
| slideInHorizontally(initialOffsetX = { it }) togetherWith | |
| slideOutHorizontally(targetOffsetX = { -it }) | |
| }, | |
| popTransitionSpec = { | |
| slideInHorizontally(initialOffsetX = { -it }) togetherWith | |
| slideOutHorizontally(targetOffsetX = { it }) | |
| }, | |
| predictivePopTransitionSpec = { | |
| slideInHorizontally(initialOffsetX = { -it }) togetherWith | |
| slideOutHorizontally(targetOffsetX = { it }) | |
| } | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment