diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/CoroutineIntentService.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/CoroutineIntentService.kt index 1c555b82e..cdd48998f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/CoroutineIntentService.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/CoroutineIntentService.kt @@ -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 } } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/lifecycle/LifecycleAwareViewHolder.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/lifecycle/LifecycleAwareViewHolder.kt index b0543f462..ccc9f6126 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/lifecycle/LifecycleAwareViewHolder.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/list/lifecycle/LifecycleAwareViewHolder.kt @@ -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) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/domain/ChaptersLoader.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/domain/ChaptersLoader.kt index 9463b6b87..961fea8f8 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/domain/ChaptersLoader.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/domain/ChaptersLoader.kt @@ -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 { - return chapterPages.subList(chapterId) + fun getPages(chapterId: Long): List = synchronized(chapterPages) { + return chapterPages.subList(chapterId).map { it.toMangaPage() } } fun getPagesCount(chapterId: Long): Int { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt index 8697dbfac..f7649b4b7 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt @@ -247,7 +247,7 @@ class ReaderViewModel @Inject constructor( fun getCurrentChapterPages(): List? { val chapterId = readingState.value?.chapterId ?: return null - return chaptersLoader.getPages(chapterId).map { it.toMangaPage() } + return chaptersLoader.getPages(chapterId) } fun saveCurrentPage(