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
This commit is contained in:
Andreas 2022-10-01 16:32:41 +02:00 committed by GitHub
parent 58c47c4c50
commit 6ac17363ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 33 deletions

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.base.controller
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import androidx.activity.OnBackPressedDispatcherOwner
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import eu.kanade.tachiyomi.databinding.ComposeControllerBinding import eu.kanade.tachiyomi.databinding.ComposeControllerBinding
import eu.kanade.tachiyomi.util.view.setComposeContent import eu.kanade.tachiyomi.util.view.setComposeContent
@ -24,6 +25,16 @@ abstract class FullComposeController<P : Presenter<*>>(bundle: Bundle? = null) :
} }
} }
} }
override fun handleBack(): Boolean {
val dispatcher = (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher ?: return false
return if (dispatcher.hasEnabledCallbacks()) {
dispatcher.onBackPressed()
true
} else {
false
}
}
} }
/** /**

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.browse.source.browse package eu.kanade.tachiyomi.ui.browse.source.browse
import android.os.Bundle import android.os.Bundle
import androidx.activity.compose.BackHandler
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
@ -52,13 +53,7 @@ open class BrowseSourceController(bundle: Bundle) :
BrowseSourceScreen( BrowseSourceScreen(
presenter = presenter, presenter = presenter,
navigateUp = { navigateUp = ::navigateUp,
if (presenter.isUserQuery) {
presenter.search()
} else {
router.popCurrentController()
}
},
openFilterSheet = { filterSheet?.show() }, openFilterSheet = { filterSheet?.show() },
onMangaClick = { router.pushController(MangaController(it.id, true)) }, onMangaClick = { router.pushController(MangaController(it.id, true)) },
onMangaLongClick = { manga -> onMangaLongClick = { manga ->
@ -114,11 +109,21 @@ open class BrowseSourceController(bundle: Bundle) :
null -> {} null -> {}
} }
BackHandler(onBack = ::navigateUp)
LaunchedEffect(presenter.filters) { LaunchedEffect(presenter.filters) {
initFilterSheet() initFilterSheet()
} }
} }
private fun navigateUp() {
when {
presenter.searchQuery != null -> presenter.searchQuery = null
presenter.isUserQuery -> presenter.search()
else -> router.popCurrentController()
}
}
open fun initFilterSheet() { open fun initFilterSheet() {
if (presenter.filters.isEmpty()) { if (presenter.filters.isEmpty()) {
return return
@ -144,8 +149,7 @@ open class BrowseSourceController(bundle: Bundle) :
* @param newQuery the new query. * @param newQuery the new query.
*/ */
fun searchWithQuery(newQuery: String) { fun searchWithQuery(newQuery: String) {
presenter.searchQuery = newQuery presenter.search(newQuery)
presenter.search()
} }
/** /**

View File

@ -5,7 +5,6 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.activity.OnBackPressedDispatcherOwner
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult import androidx.compose.material3.SnackbarResult
@ -196,17 +195,6 @@ class MangaController : FullComposeController<MangaPresenter> {
} }
} }
// 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 { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View {
settingsSheet = ChaptersSettingsSheet(router, presenter) settingsSheet = ChaptersSettingsSheet(router, presenter)
trackSheet = TrackSheet(this, (activity as MainActivity).supportFragmentManager) trackSheet = TrackSheet(this, (activity as MainActivity).supportFragmentManager)

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.ui.recent.updates package eu.kanade.tachiyomi.ui.recent.updates
import androidx.activity.OnBackPressedDispatcherOwner
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import eu.kanade.presentation.updates.UpdateScreen 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
}
}
} }