fix: handle invalid index in centerItem and return null for out-of-range subtitle indices
This commit is contained in:
+1
-1
@@ -4,5 +4,5 @@ class GetCurrentSubtitleIndexUseCase {
|
||||
operator fun invoke(
|
||||
subtitle: Subtitle,
|
||||
progressMs: Long,
|
||||
): Int = subtitle.lines.indexOfLast { it.startMs <= progressMs }
|
||||
): Int? = subtitle.lines.indexOfLast { it.startMs <= progressMs }.takeIf { it >= 0 }
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ class GetCurrentSubtitleIndexUseCaseTest {
|
||||
|
||||
@Test
|
||||
fun returns_minus_one_before_the_first_cue() {
|
||||
assertEquals(-1, getCurrentSubtitleIndex(subtitle, progressMs = -1))
|
||||
assertEquals(null, getCurrentSubtitleIndex(subtitle, progressMs = -1))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,6 +39,6 @@ class GetCurrentSubtitleIndexUseCaseTest {
|
||||
|
||||
@Test
|
||||
fun returns_minus_one_for_an_empty_subtitle() {
|
||||
assertEquals(-1, getCurrentSubtitleIndex(Subtitle(emptyList()), progressMs = 1_000))
|
||||
assertEquals(null, getCurrentSubtitleIndex(Subtitle(emptyList()), progressMs = 1_000))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user