diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/HistoryUpdateUseCase.kt b/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/HistoryUpdateUseCase.kt index 452d0368f..4f307a54f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/HistoryUpdateUseCase.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/history/domain/HistoryUpdateUseCase.kt @@ -1,13 +1,15 @@ package org.koitharu.kotatsu.history.domain import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.core.util.ext.processLifecycleScope import org.koitharu.kotatsu.history.data.HistoryRepository import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.util.runCatchingCancellable import org.koitharu.kotatsu.reader.ui.ReaderState -import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import javax.inject.Inject class HistoryUpdateUseCase @Inject constructor( @@ -30,7 +32,9 @@ class HistoryUpdateUseCase @Inject constructor( percent: Float ) = processLifecycleScope.launch(Dispatchers.Default) { runCatchingCancellable { - invoke(manga, readerState, percent) + withContext(NonCancellable) { + invoke(manga, readerState, percent) + } }.onFailure { it.printStackTraceDebug() } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/main/ui/MainNavigationDelegate.kt b/app/src/main/kotlin/org/koitharu/kotatsu/main/ui/MainNavigationDelegate.kt index adfec639a..f30082e18 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/main/ui/MainNavigationDelegate.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/main/ui/MainNavigationDelegate.kt @@ -97,7 +97,7 @@ class MainNavigationDelegate( } private fun onNavigationItemSelected(@IdRes itemId: Int): Boolean { - setPrimaryFragment( + return setPrimaryFragment( when (itemId) { R.id.nav_shelf -> ShelfFragment.newInstance() R.id.nav_explore -> ExploreFragment.newInstance() @@ -106,7 +106,6 @@ class MainNavigationDelegate( else -> return false }, ) - return true } private fun getItemId(fragment: Fragment) = when (fragment) { @@ -117,13 +116,17 @@ class MainNavigationDelegate( else -> 0 } - private fun setPrimaryFragment(fragment: Fragment) { + private fun setPrimaryFragment(fragment: Fragment): Boolean { + if (fragmentManager.isStateSaved) { + return false + } fragmentManager.beginTransaction() .setReorderingAllowed(true) .replace(R.id.container, fragment, TAG_PRIMARY) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) .commit() onFragmentChanged(fragment, fromUser = true) + return true } private fun onFragmentChanged(fragment: Fragment, fromUser: Boolean) {