fun TotalStepsScreen()

in health-platform-v1/HealthPlatformSample/app/src/main/java/com/example/healthplatformsample/presentation/ui/TotalStepsScreen/TotalStepsScreen.kt [34:63]


fun TotalStepsScreen(
    healthPlatformManager: HealthPlatformManager,
    onError: (Context, Throwable?) -> Unit,
    viewModel: TotalStepsViewModel = viewModel(
        factory = TotalStepsViewModelFactory(
            healthPlatformManager = healthPlatformManager
        )
    )
) {
    val totalSteps by viewModel.totalSteps
    val state = viewModel.uiState
    val context = LocalContext.current
    // Remember the last error ID, such that it is possible to avoid re-launching the error
    // notification for the same error when the screen is recomposed, or configuration changes etc.
    val errorId = rememberSaveable { mutableStateOf(UUID.randomUUID()) }

    // The [MainModel.UiState] provides details of whether the last action was a success or resulted
    // in an error. Where an error occurred, for example in reading and writing to Health Platform,
    // the user is notified, and where the error is one that can be recovered from, an attempt to
    // do so is made.
    LaunchedEffect(state) {
        if (state is TotalStepsViewModel.UiState.Error && errorId.value != state.uuid) {
            onError(context, state.exception)
            errorId.value = state.uuid
        }
    }

    val modifier = Modifier.padding(4.dp)
    TotalStepsEntry(totalSteps, modifier = modifier)
}