Fix crashes

master
Koitharu 1 year ago
parent 19446db192
commit 9fcff1eac7
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

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

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

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

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

Loading…
Cancel
Save