Repository: Automattic/pocket-casts-android
File: modules/features/transcripts/src/main/kotlin/au/com/shiftyjelly/pocketcasts/transcripts/ui/TranscriptLines.kt (Kotlin)

Code before:
        style = entry.textStyle(),
        color = theme.text,
        modifier = modifier,
    )
}

private fun TranscriptEntry.text() = when (this) {
    is TranscriptEntry.Text -> value
    is TranscriptEntry.Speaker -> name
}

private fun TranscriptEntry.textStyle() = when (this) {
    is TranscriptEntry.Text -> SimpleTextStyle
    is TranscriptEntry.Speaker -> SpeakerTextStyle
}

private fun TranscriptEntry.padding() = when (this) {
    is TranscriptEntry.Text -> SimplePadding
    is TranscriptEntry.Speaker -> SpeakerPadding
}

private fun isValidHighlightRange(start: Int, end: Int, maxLength: Int): Boolean {
    if (start > end) {
        return false
    }
    if (start < 0 || end < 0) {
        return false
    }
    if (start > maxLength || end > maxLength) {
        return false
    }

    return true
}

private val SimpleTextStyle = TextStyle(
    fontSize = 16.sp,
    fontWeight = FontWeight.Medium,
    fontFamily = TranscriptTheme.RobotoSerifFontFamily,
)
private val SpeakerTextStyle = SimpleTextStyle.copy(
    fontSize = 12.sp,
)

private val SimplePadding = PaddingValues(start = 32.dp, end = 32.dp, bottom = 16.dp)
private val SpeakerPadding = PaddingValues(start = 32.dp, end = 32.dp, bottom = 8.dp, top = 16.dp)

@Preview
@Composable
private fun TranscriptLinesPreview(
    @PreviewParameter(ThemePreviewParameterProvider::class) theme: ThemeType,

Review comment (suggestion):
⛏️ i think it's already granted that `end` cannot be `<0` at this point.

instead of doing these many checks maybe you could use rephrase the body to a single expression:

`return start < end && start >= 0 && (start .. end).contains(maxLength)`

Code after:
                }
                addStyle(style, startIndex, endIndex)
            }
        },
        style = entry.textStyle(),
        color = theme.text,
        modifier = modifier,
    )
}

private fun TranscriptEntry.text() = when (this) {
    is TranscriptEntry.Text -> value
    is TranscriptEntry.Speaker -> name
}

private fun TranscriptEntry.textStyle() = when (this) {
    is TranscriptEntry.Text -> SimpleTextStyle
    is TranscriptEntry.Speaker -> SpeakerTextStyle
}

private fun TranscriptEntry.padding() = when (this) {
    is TranscriptEntry.Text -> SimplePadding
    is TranscriptEntry.Speaker -> SpeakerPadding
}

private fun isValidHighlightRange(start: Int, end: Int, maxLength: Int): Boolean {
    return start < end && start >= 0 && end <= maxLength
}

private val SimpleTextStyle = TextStyle(
    fontSize = 16.sp,
    fontWeight = FontWeight.Medium,
    fontFamily = TranscriptTheme.RobotoSerifFontFamily,
)
private val SpeakerTextStyle = SimpleTextStyle.copy(
    fontSize = 12.sp,
)

private val SimplePadding = PaddingValues(start = 32.dp, end = 32.dp, bottom = 16.dp)
private val SpeakerPadding = PaddingValues(start = 32.dp, end = 32.dp, bottom = 8.dp, top = 16.dp)

@Preview
@Composable
private fun TranscriptLinesPreview(
    @PreviewParameter(ThemePreviewParameterProvider::class) theme: ThemeType,
) {
    AppThemeWithBackground(theme) {
        Column {
            TranscriptLines(
                entries = TranscriptEntry.PreviewList,
                searchState = remember { SearchStatePreview },