diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt index 030a87053..3fb57878f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ComposeController.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.base.controller import android.os.Bundle import android.view.LayoutInflater import android.view.View +import androidx.activity.OnBackPressedDispatcherOwner import androidx.compose.runtime.Composable import eu.kanade.tachiyomi.databinding.ComposeControllerBinding import eu.kanade.tachiyomi.util.view.setComposeContent @@ -24,6 +25,16 @@ abstract class FullComposeController

>(bundle: Bundle? = null) : } } } + + override fun handleBack(): Boolean { + val dispatcher = (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher ?: return false + return if (dispatcher.hasEnabledCallbacks()) { + dispatcher.onBackPressed() + true + } else { + false + } + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index a89f39e1c..1de01cbab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.browse.source.browse import android.os.Bundle +import androidx.activity.compose.BackHandler import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.rememberCoroutineScope @@ -52,13 +53,7 @@ open class BrowseSourceController(bundle: Bundle) : BrowseSourceScreen( presenter = presenter, - navigateUp = { - if (presenter.isUserQuery) { - presenter.search() - } else { - router.popCurrentController() - } - }, + navigateUp = ::navigateUp, openFilterSheet = { filterSheet?.show() }, onMangaClick = { router.pushController(MangaController(it.id, true)) }, onMangaLongClick = { manga -> @@ -114,11 +109,21 @@ open class BrowseSourceController(bundle: Bundle) : null -> {} } + BackHandler(onBack = ::navigateUp) + LaunchedEffect(presenter.filters) { initFilterSheet() } } + private fun navigateUp() { + when { + presenter.searchQuery != null -> presenter.searchQuery = null + presenter.isUserQuery -> presenter.search() + else -> router.popCurrentController() + } + } + open fun initFilterSheet() { if (presenter.filters.isEmpty()) { return @@ -144,8 +149,7 @@ open class BrowseSourceController(bundle: Bundle) : * @param newQuery the new query. */ fun searchWithQuery(newQuery: String) { - presenter.searchQuery = newQuery - presenter.search() + presenter.search(newQuery) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index b19bf884e..e6b858505 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -5,7 +5,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.activity.OnBackPressedDispatcherOwner import androidx.appcompat.app.AppCompatActivity import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.SnackbarResult @@ -196,17 +195,6 @@ class MangaController : FullComposeController { } } - // Let Compose view handle this - override fun handleBack(): Boolean { - val dispatcher = (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher ?: return false - return if (dispatcher.hasEnabledCallbacks()) { - dispatcher.onBackPressed() - true - } else { - false - } - } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View { settingsSheet = ChaptersSettingsSheet(router, presenter) trackSheet = TrackSheet(this, (activity as MainActivity).supportFragmentManager) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index 3928eab70..24784d280 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.recent.updates -import androidx.activity.OnBackPressedDispatcherOwner import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import eu.kanade.presentation.updates.UpdateScreen @@ -36,15 +35,4 @@ class UpdatesController : } } } - - // Let Compose view handle this - override fun handleBack(): Boolean { - val dispatcher = (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher ?: return false - return if (dispatcher.hasEnabledCallbacks()) { - dispatcher.onBackPressed() - true - } else { - false - } - } }