Skip to content

Commit

Permalink
fix app crash when tried to download the empty book or podcast
Browse files Browse the repository at this point in the history
  • Loading branch information
GrakovNe committed Dec 23, 2024
1 parent f7dc616 commit 948933e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ android {
applicationId = "org.grakovne.lissen"
minSdk = 28
targetSdk = 35
versionCode = 59
versionName = "1.1.28"
versionCode = 60
versionName = "1.1.29"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ class ContentCachingService @Inject constructor(

return when (option) {
AllItemsDownloadOption -> book.chapters
CurrentItemDownloadOption -> listOf(book.chapters[chapterIndex])
CurrentItemDownloadOption -> listOfNotNull(book.chapters.getOrNull(chapterIndex))
is NumberItemDownloadOption -> book.chapters.subList(
fromIndex = chapterIndex,
toIndex = (chapterIndex + option.itemsNumber).coerceAtMost(book.chapters.size),
chapterIndex.coerceAtLeast(0),
(chapterIndex + option.itemsNumber).coerceIn(chapterIndex..book.chapters.size),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ class MediaRepository @Inject constructor(
private fun seekTo(position: Double) {
val book = playingBook.value ?: return

if (book.chapters.isEmpty()) {
Log.d(TAG, "Tried to seek on the empty book")
return
}

val overallDuration = book
.chapters
.sumOf { it.duration }
Expand Down

0 comments on commit 948933e

Please sign in to comment.