Fix crashes

This commit is contained in:
Koitharu
2024-11-16 10:19:42 +02:00
parent 19446db192
commit 9fcff1eac7
4 changed files with 9 additions and 5 deletions

View File

@@ -107,13 +107,14 @@ abstract class CoroutineIntentService : BaseService() {
synchronized(this) {
if (cancelReceiver == null && !isStopped) {
val job = coroutineContext[Job] ?: return
cancelReceiver = CancelReceiver(job).also { receiver ->
CancelReceiver(job).let { receiver ->
ContextCompat.registerReceiver(
applicationContext,
receiver,
createIntentFilter(this@CoroutineIntentService, startId),
ContextCompat.RECEIVER_NOT_EXPORTED,
)
cancelReceiver = receiver
}
}
}

View File

@@ -18,7 +18,9 @@ abstract class LifecycleAwareViewHolder(
private var isCurrent = false
init {
parentLifecycleOwner.lifecycle.addObserver(ParentLifecycleObserver())
itemView.post {
parentLifecycleOwner.lifecycle.addObserver(ParentLifecycleObserver())
}
}
fun setIsCurrent(value: Boolean) {

View File

@@ -7,6 +7,7 @@ import kotlinx.coroutines.sync.withLock
import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.details.data.MangaDetails
import org.koitharu.kotatsu.parsers.model.MangaChapter
import org.koitharu.kotatsu.parsers.model.MangaPage
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
import javax.inject.Inject
@@ -71,8 +72,8 @@ class ChaptersLoader @Inject constructor(
return chapterId in chapterPages
}
fun getPages(chapterId: Long): List<ReaderPage> {
return chapterPages.subList(chapterId)
fun getPages(chapterId: Long): List<MangaPage> = synchronized(chapterPages) {
return chapterPages.subList(chapterId).map { it.toMangaPage() }
}
fun getPagesCount(chapterId: Long): Int {

View File

@@ -247,7 +247,7 @@ class ReaderViewModel @Inject constructor(
fun getCurrentChapterPages(): List<MangaPage>? {
val chapterId = readingState.value?.chapterId ?: return null
return chaptersLoader.getPages(chapterId).map { it.toMangaPage() }
return chaptersLoader.getPages(chapterId)
}
fun saveCurrentPage(