2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] Bug 1807727 - Dismiss SearchDialogFragment on editing cancelled

This commit is contained in:
Alexandru2909 2023-01-03 10:45:26 +02:00 committed by mergify[bot]
parent a9840d1abb
commit 03493f4eaf
3 changed files with 28 additions and 13 deletions

View File

@ -72,6 +72,7 @@ class SearchDialogController(
private val clearToolbarFocus: () -> Unit,
private val focusToolbar: () -> Unit,
private val clearToolbar: () -> Unit,
private val dismissDialogAndGoBack: () -> Unit,
) : SearchController {
override fun handleUrlCommitted(url: String, fromHomeScreen: Boolean) {
@ -135,6 +136,7 @@ class SearchDialogController(
override fun handleEditingCancelled() {
clearToolbarFocus()
dismissDialogAndGoBack()
}
override fun handleTextChanged(text: String) {

View File

@ -212,6 +212,7 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
clearToolbar = {
inlineAutocompleteEditText.setText("")
},
dismissDialogAndGoBack = ::dismissDialogAndGoBack,
),
)
@ -636,24 +637,29 @@ class SearchDialogFragment : AppCompatDialogFragment(), UserInteractionHandler {
true
}
else -> {
// In case we're displaying search results, we wouldn't have navigated to home, and
// so we don't need to navigate "back to" browser fragment.
// See mirror of this logic in BrowserToolbarController#handleToolbarClick.
if (store.state.searchTerms.isBlank()) {
val args by navArgs<SearchDialogFragmentArgs>()
args.sessionId?.let {
findNavController().navigate(
SearchDialogFragmentDirections.actionGlobalBrowser(null),
)
}
}
view?.hideKeyboard()
dismissAllowingStateLoss()
dismissDialogAndGoBack()
true
}
}
}
private fun dismissDialogAndGoBack() {
// In case we're displaying search results, we wouldn't have navigated to home, and
// so we don't need to navigate "back to" browser fragment.
// See mirror of this logic in BrowserToolbarController#handleToolbarClick.
if (store.state.searchTerms.isBlank()) {
val args by navArgs<SearchDialogFragmentArgs>()
args.sessionId?.let {
findNavController().navigate(
SearchDialogFragmentDirections.actionGlobalBrowser(null),
)
}
}
view?.hideKeyboard()
dismissAllowingStateLoss()
}
private fun historyStorageProvider(): HistoryStorage? {
return if (requireContext().settings().shouldShowHistorySuggestions) {
requireComponents.core.historyStorage

View File

@ -223,13 +223,18 @@ class SearchDialogControllerTest {
@Test
fun handleEditingCancelled() = runTest {
var clearToolbarFocusInvoked = false
var dismissAndGoBack = false
createController(
clearToolbarFocus = {
clearToolbarFocusInvoked = true
},
dismissDialogAndGoBack = {
dismissAndGoBack = true
},
).handleEditingCancelled()
assertTrue(clearToolbarFocusInvoked)
assertTrue(dismissAndGoBack)
}
@Test
@ -552,6 +557,7 @@ class SearchDialogControllerTest {
focusToolbar: () -> Unit = { },
clearToolbar: () -> Unit = { },
dismissDialog: () -> Unit = { },
dismissDialogAndGoBack: () -> Unit = { },
): SearchDialogController {
return SearchDialogController(
activity = activity,
@ -564,6 +570,7 @@ class SearchDialogControllerTest {
clearToolbarFocus = clearToolbarFocus,
focusToolbar = focusToolbar,
clearToolbar = clearToolbar,
dismissDialogAndGoBack = dismissDialogAndGoBack,
)
}
}