Fix some crashes

This commit is contained in:
arkon 2022-10-28 21:10:03 -04:00
parent e4a2f35907
commit 5efb31bd71
6 changed files with 13 additions and 11 deletions

View File

@ -21,8 +21,8 @@ class GetNextChapter(
} }
suspend fun await(mangaId: Long, chapterId: Long): Chapter? { suspend fun await(mangaId: Long, chapterId: Long): Chapter? {
val chapter = getChapter.await(chapterId)!! val chapter = getChapter.await(chapterId) ?: return null
val manga = getManga.await(mangaId)!! val manga = getManga.await(mangaId) ?: return null
if (!chapter.read) return chapter if (!chapter.read) return chapter

View File

@ -89,7 +89,7 @@ fun BrowseSourceScreen(
Column(modifier = Modifier.background(MaterialTheme.colorScheme.surface)) { Column(modifier = Modifier.background(MaterialTheme.colorScheme.surface)) {
BrowseSourceToolbar( BrowseSourceToolbar(
state = presenter, state = presenter,
source = presenter.source!!, source = presenter.source,
displayMode = presenter.displayMode, displayMode = presenter.displayMode,
onDisplayModeChange = { presenter.displayMode = it }, onDisplayModeChange = { presenter.displayMode = it },
navigateUp = navigateUp, navigateUp = navigateUp,

View File

@ -33,7 +33,7 @@ import eu.kanade.tachiyomi.source.LocalSource
@Composable @Composable
fun BrowseSourceToolbar( fun BrowseSourceToolbar(
state: BrowseSourceState, state: BrowseSourceState,
source: CatalogueSource, source: CatalogueSource?,
displayMode: LibraryDisplayMode, displayMode: LibraryDisplayMode,
onDisplayModeChange: (LibraryDisplayMode) -> Unit, onDisplayModeChange: (LibraryDisplayMode) -> Unit,
navigateUp: () -> Unit, navigateUp: () -> Unit,
@ -44,7 +44,7 @@ fun BrowseSourceToolbar(
) { ) {
if (state.searchQuery == null) { if (state.searchQuery == null) {
BrowseSourceRegularToolbar( BrowseSourceRegularToolbar(
title = if (state.isUserQuery) state.currentFilter.query else source.name, title = if (state.isUserQuery) state.currentFilter.query else source?.name.orEmpty(),
isLocalSource = source is LocalSource, isLocalSource = source is LocalSource,
displayMode = displayMode, displayMode = displayMode,
onDisplayModeChange = onDisplayModeChange, onDisplayModeChange = onDisplayModeChange,

View File

@ -13,6 +13,7 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.stateIn
import logcat.LogPriority import logcat.LogPriority
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -35,6 +36,7 @@ class ExtensionFilterPresenter(
logcat(LogPriority.ERROR, exception) logcat(LogPriority.ERROR, exception)
_events.send(Event.FailedFetchingLanguages) _events.send(Event.FailedFetchingLanguages)
} }
.stateIn(presenterScope)
.collectLatest(::collectLatestSourceLangMap) .collectLatest(::collectLatestSourceLangMap)
} }
} }

View File

@ -29,10 +29,6 @@ class SourceSearchController(
@Composable @Composable
override fun ComposeContent() { override fun ComposeContent() {
// LocalContext is not a first available to us when we try access it
// Decoupling from BrowseSourceController is needed
val context = applicationContext!!
SourceSearchScreen( SourceSearchScreen(
presenter = presenter, presenter = presenter,
navigateUp = { router.popCurrentController() }, navigateUp = { router.popCurrentController() },
@ -46,8 +42,10 @@ class SourceSearchController(
}, },
onWebViewClick = f@{ onWebViewClick = f@{
val source = presenter.source as? HttpSource ?: return@f val source = presenter.source as? HttpSource ?: return@f
activity?.let { context ->
val intent = WebViewActivity.newIntent(context, source.baseUrl, source.id, source.name) val intent = WebViewActivity.newIntent(context, source.baseUrl, source.id, source.name)
context.startActivity(intent) context.startActivity(intent)
}
}, },
) )

View File

@ -15,6 +15,7 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.stateIn
import logcat.LogPriority import logcat.LogPriority
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -39,6 +40,7 @@ class SourcesFilterPresenter(
logcat(LogPriority.ERROR, exception) logcat(LogPriority.ERROR, exception)
_events.send(Event.FailedFetchingLanguages) _events.send(Event.FailedFetchingLanguages)
} }
.stateIn(presenterScope)
.collectLatest(::collectLatestSourceLangMap) .collectLatest(::collectLatestSourceLangMap)
} }
} }