Fix crashes
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
package org.koitharu.kotatsu.history.domain
|
package org.koitharu.kotatsu.history.domain
|
||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.launch
|
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.core.util.ext.processLifecycleScope
|
||||||
import org.koitharu.kotatsu.history.data.HistoryRepository
|
import org.koitharu.kotatsu.history.data.HistoryRepository
|
||||||
import org.koitharu.kotatsu.parsers.model.Manga
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
import org.koitharu.kotatsu.parsers.util.runCatchingCancellable
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderState
|
import org.koitharu.kotatsu.reader.ui.ReaderState
|
||||||
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class HistoryUpdateUseCase @Inject constructor(
|
class HistoryUpdateUseCase @Inject constructor(
|
||||||
@@ -30,7 +32,9 @@ class HistoryUpdateUseCase @Inject constructor(
|
|||||||
percent: Float
|
percent: Float
|
||||||
) = processLifecycleScope.launch(Dispatchers.Default) {
|
) = processLifecycleScope.launch(Dispatchers.Default) {
|
||||||
runCatchingCancellable {
|
runCatchingCancellable {
|
||||||
invoke(manga, readerState, percent)
|
withContext(NonCancellable) {
|
||||||
|
invoke(manga, readerState, percent)
|
||||||
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
it.printStackTraceDebug()
|
it.printStackTraceDebug()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class MainNavigationDelegate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onNavigationItemSelected(@IdRes itemId: Int): Boolean {
|
private fun onNavigationItemSelected(@IdRes itemId: Int): Boolean {
|
||||||
setPrimaryFragment(
|
return setPrimaryFragment(
|
||||||
when (itemId) {
|
when (itemId) {
|
||||||
R.id.nav_shelf -> ShelfFragment.newInstance()
|
R.id.nav_shelf -> ShelfFragment.newInstance()
|
||||||
R.id.nav_explore -> ExploreFragment.newInstance()
|
R.id.nav_explore -> ExploreFragment.newInstance()
|
||||||
@@ -106,7 +106,6 @@ class MainNavigationDelegate(
|
|||||||
else -> return false
|
else -> return false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getItemId(fragment: Fragment) = when (fragment) {
|
private fun getItemId(fragment: Fragment) = when (fragment) {
|
||||||
@@ -117,13 +116,17 @@ class MainNavigationDelegate(
|
|||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setPrimaryFragment(fragment: Fragment) {
|
private fun setPrimaryFragment(fragment: Fragment): Boolean {
|
||||||
|
if (fragmentManager.isStateSaved) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
fragmentManager.beginTransaction()
|
fragmentManager.beginTransaction()
|
||||||
.setReorderingAllowed(true)
|
.setReorderingAllowed(true)
|
||||||
.replace(R.id.container, fragment, TAG_PRIMARY)
|
.replace(R.id.container, fragment, TAG_PRIMARY)
|
||||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
|
||||||
.commit()
|
.commit()
|
||||||
onFragmentChanged(fragment, fromUser = true)
|
onFragmentChanged(fragment, fromUser = true)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onFragmentChanged(fragment: Fragment, fromUser: Boolean) {
|
private fun onFragmentChanged(fragment: Fragment, fromUser: Boolean) {
|
||||||
|
|||||||
Reference in New Issue
Block a user