diff --git a/app/src/main/java/exh/ui/smartsearch/SmartSearchController.kt b/app/src/main/java/exh/ui/smartsearch/SmartSearchController.kt index 338b429d1..686c43b56 100644 --- a/app/src/main/java/exh/ui/smartsearch/SmartSearchController.kt +++ b/app/src/main/java/exh/ui/smartsearch/SmartSearchController.kt @@ -11,9 +11,7 @@ import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.source.SourceController import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.manga.MangaController -import eu.kanade.tachiyomi.util.lang.withUIContext import eu.kanade.tachiyomi.util.system.toast -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.plus @@ -36,8 +34,6 @@ class SmartSearchController(bundle: Bundle? = null) : NucleusController if (results is SmartSearchPresenter.SearchResults.Found) { val transaction = MangaController(results.manga, true, smartSearchConfig).withFadeTransaction() - withUIContext { - router.replaceTopController(transaction) - } + router.replaceTopController(transaction) } else { - withUIContext { - if (results is SmartSearchPresenter.SearchResults.NotFound) { - applicationContext?.toast("Couldn't find the manga in the source!") - } else { - applicationContext?.toast("Error performing automatic search!") - } - } - - val transaction = BrowseSourceController(source, smartSearchConfig.origTitle, smartSearchConfig).withFadeTransaction() - withUIContext { - router.replaceTopController(transaction) + if (results is SmartSearchPresenter.SearchResults.NotFound) { + applicationContext?.toast("Couldn't find the manga in the source!") + } else { + applicationContext?.toast("Error performing automatic search!") } + val transaction = BrowseSourceController( + source, + smartSearchConfig.origTitle, + smartSearchConfig + ).withFadeTransaction() + router.replaceTopController(transaction) } } - .launchIn(viewScope + Dispatchers.IO) + .launchIn(viewScope) } companion object { diff --git a/app/src/main/java/exh/ui/smartsearch/SmartSearchPresenter.kt b/app/src/main/java/exh/ui/smartsearch/SmartSearchPresenter.kt index b91af4c1a..da9ca351b 100644 --- a/app/src/main/java/exh/ui/smartsearch/SmartSearchPresenter.kt +++ b/app/src/main/java/exh/ui/smartsearch/SmartSearchPresenter.kt @@ -4,24 +4,25 @@ import android.os.Bundle import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.ui.browse.source.SourceController +import eu.kanade.tachiyomi.util.lang.launchIO import exh.smartsearch.SmartSearchEngine import exh.ui.base.CoroutinePresenter import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.launch +import kotlinx.coroutines.flow.asSharedFlow class SmartSearchPresenter(private val source: CatalogueSource, private val config: SourceController.SmartSearchConfig) : CoroutinePresenter() { - val smartSearchFlow = MutableSharedFlow() + private val _smartSearchFlow = MutableSharedFlow() + val smartSearchFlow = _smartSearchFlow.asSharedFlow() private val smartSearchEngine = SmartSearchEngine() override fun onCreate(savedState: Bundle?) { super.onCreate(savedState) - launch(Dispatchers.IO) { + launchIO { val result = try { val resultManga = smartSearchEngine.smartSearch(source, config.origTitle) if (resultManga != null) { @@ -38,7 +39,7 @@ class SmartSearchPresenter(private val source: CatalogueSource, private val conf } } - smartSearchFlow.emit(result) + _smartSearchFlow.emit(result) } } diff --git a/app/src/main/res/layout/eh_smart_search.xml b/app/src/main/res/layout/eh_smart_search.xml index b08b8f251..971b06a9e 100644 --- a/app/src/main/res/layout/eh_smart_search.xml +++ b/app/src/main/res/layout/eh_smart_search.xml @@ -1,54 +1,27 @@ - + android:layout_height="match_parent" + android:layout_gravity="center" + android:background="?attr/colorSurface" + android:gravity="center" + android:orientation="vertical"> - + - - - - - - - - - - - - - - - + +