Repository: Automattic/pocket-casts-android
File: modules/features/endofyear/src/main/java/au/com/shiftyjelly/pocketcasts/endofyear/ui/StoriesPage.kt (Kotlin)

Code before:
            is Story.YearVsYear -> YearVsYearStory(
                story = story,
                measurements = measurements,
                controller = controller,
                onShareStory = { file -> onShareStory(story, file) },
            )
            is Story.CompletionRate -> CompletionRateStory(
                story = story,
                measurements = measurements,
                controller = controller,
                onShareStory = { file -> onShareStory(story, file) },
            )
            is Story.Ending -> EndingStory(
                story = story,
                measurements = measurements,
                onRestartPlayback = onRestartPlayback,
            )
        }
    }
}

@Composable
internal fun BoxScope.TopControls(
    pagerState: PagerState,
    progress: Float,
    colors: List<Color>,
    measurements: EndOfYearMeasurements,
    onClose: () -> Unit,
    controller: StoryCaptureController,
) {
    val density = LocalDensity.current
    // Calculate the height so that we can remove it from the share images
    val statusBarHeightPx = measurements.statusBarInsets.getTop(density)
    val extraPaddingPx = with(density) { 24.dp.roundToPx() }

    Column(
        horizontalAlignment = Alignment.End,
        modifier = Modifier
            .align(Alignment.TopCenter)
            .fillMaxWidth()
            .windowInsetsPadding(measurements.statusBarInsets)
            .padding(start = 16.dp, end = 16.dp)
            .onGloballyPositioned { controller.topControlsHeightPx = it.size.height + statusBarHeightPx - extraPaddingPx },
    ) {
        PagerProgressingIndicator(
            state = pagerState,
            progress = progress,
            activeColor = colors[pagerState.currentPage],
        )
        Spacer(
            modifier = Modifier.height(10.dp),

Review comment (suggestion):
Instead of passing in list of colors could pass in a single colors and hoist the `colors[page]` logic to the top? It would be also good to change it to `colors.getOrNull(index)`. It avoids duplication and potentially risky `colors[index]` where index is not available

Code after:
            is Story.YearVsYear -> YearVsYearStory(
                story = story,
                measurements = measurements,
                controller = controller,
                onShareStory = { file -> onShareStory(story, file) },
            )
            is Story.CompletionRate -> CompletionRateStory(
                story = story,
                measurements = measurements,
                controller = controller,
                onShareStory = { file -> onShareStory(story, file) },
            )
            is Story.Ending -> EndingStory(
                story = story,
                measurements = measurements,
                onRestartPlayback = onRestartPlayback,
            )
        }
    }
}

@Composable
internal fun BoxScope.TopControls(
    pagerState: PagerState,
    progress: Float,
    color: Color,
    measurements: EndOfYearMeasurements,
    onClose: () -> Unit,
    controller: StoryCaptureController,
) {
    val density = LocalDensity.current
    // Calculate the height so that we can remove it from the share images
    val statusBarHeightPx = measurements.statusBarInsets.getTop(density)
    val extraPaddingPx = with(density) { 24.dp.roundToPx() }

    Column(
        horizontalAlignment = Alignment.End,
        modifier = Modifier
            .align(Alignment.TopCenter)
            .fillMaxWidth()
            .windowInsetsPadding(measurements.statusBarInsets)
            .padding(start = 16.dp, end = 16.dp)
            .onGloballyPositioned { controller.topControlsHeightPx = it.size.height + statusBarHeightPx - extraPaddingPx },
    ) {
        PagerProgressingIndicator(
            state = pagerState,
            progress = progress,
            activeColor = color,
        )
        Spacer(
            modifier = Modifier.height(10.dp),