From 6ac17363ed68487b2262308ee9d671ad301f2754 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sat, 1 Oct 2022 16:32:41 +0200 Subject: [PATCH] Tweak behavior on Browse screen (#8121) * Tweak behavior on Browse screen - Fix system back popping controller - Add behavior to system back to cancel search toolbar before clearing current search or popping controller * Review changes --- .../ui/base/controller/ComposeController.kt | 11 ++++++++++ .../source/browse/BrowseSourceController.kt | 22 +++++++++++-------- .../tachiyomi/ui/manga/MangaController.kt | 12 ---------- .../ui/recent/updates/UpdatesController.kt | 12 ---------- 4 files changed, 24 insertions(+), 33 deletions(-) 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 030a870530..3fb57878f6 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 a89f39e1c5..1de01cbab0 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 b19bf884e7..e6b858505a 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 3928eab70a..24784d2805 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 - } - } }