1
0
Fork 0

For 11428 - Focus on home screen address bar when tab tray new tab is tapped (#11429)

master
David Walsh 2020-06-12 17:55:07 -05:00 committed by GitHub
parent 063cf457ba
commit 8b24cdec42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 6 deletions

View File

@ -147,7 +147,7 @@ class DefaultBrowserToolbarController(
if (sessionManager.sessionsOfType(it.private).count() == 1) {
// The tab tray always returns to normal mode so do that here too
(activity as HomeActivity).browsingModeManager.mode = BrowsingMode.Normal
navController.navigate(BrowserFragmentDirections.actionGlobalHome(it.id))
navController.navigate(BrowserFragmentDirections.actionGlobalHome(sessionToDelete = it.id))
} else {
onCloseTab.invoke(it)
activity.components.useCases.tabsUseCases.removeTab.invoke(it)

View File

@ -15,6 +15,7 @@ import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.accessibility.AccessibilityEvent
import android.widget.Button
import android.widget.LinearLayout
import android.widget.PopupWindow
@ -107,12 +108,12 @@ import kotlin.math.min
@SuppressWarnings("TooManyFunctions", "LargeClass")
class HomeFragment : Fragment() {
private val args by navArgs<HomeFragmentArgs>()
private val homeViewModel: HomeScreenViewModel by viewModels {
ViewModelProvider.AndroidViewModelFactory(requireActivity().application)
}
private val args by navArgs<HomeFragmentArgs>()
private val snackbarAnchorView: View?
get() {
return if (requireContext().settings().shouldUseBottomToolbar) {
@ -359,6 +360,15 @@ class HomeFragment : Fragment() {
SearchWidgetCFR(view.context) { view.toolbar_wrapper }.displayIfNecessary()
}
}
if (view.context.settings().accessibilityServicesEnabled && args.focusOnAddressBar) {
// We cannot put this in the fragment_home.xml file as it breaks tests
view.toolbar_wrapper.isFocusableInTouchMode = true
viewLifecycleOwner.lifecycleScope.launch {
view.toolbar_wrapper?.requestFocus()
view.toolbar_wrapper?.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
}
}
}
override fun onDestroyView() {

View File

@ -196,7 +196,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
override fun onNewTabTapped(private: Boolean) {
(activity as HomeActivity).browsingModeManager.mode = BrowsingMode.fromBoolean(private)
findNavController().popBackStack(R.id.homeFragment, false)
findNavController().navigate(TabTrayDialogFragmentDirections.actionGlobalHome(focusOnAddressBar = true))
dismissAllowingStateLoss()
}
@ -311,7 +311,9 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
.setText(requireContext().getString(R.string.create_collection_tabs_saved))
.setAction(requireContext().getString(R.string.create_collection_view)) {
dismissAllowingStateLoss()
findNavController().navigate(TabTrayDialogFragmentDirections.actionGlobalHome())
findNavController().navigate(
TabTrayDialogFragmentDirections.actionGlobalHome(focusOnAddressBar = false)
)
}
snackbar.view.elevation = ELEVATION

View File

@ -66,6 +66,11 @@
app:destination="@id/browserFragment"
app:exitAnim="@anim/zoom_in_fade"
app:popEnterAnim="@anim/zoom_out_fade" />
<argument
android:name="focusOnAddressBar"
android:defaultValue="false"
app:argType="boolean" />
<argument
android:name="session_to_delete"
app:argType="string"

View File

@ -569,7 +569,7 @@ class DefaultBrowserToolbarControllerTest {
every { activity.browsingModeManager } returns browsingModeManager
controller.handleTabCounterItemInteraction(item)
verify { navController.navigate(BrowserFragmentDirections.actionGlobalHome("1")) }
verify { navController.navigate(BrowserFragmentDirections.actionGlobalHome(sessionToDelete = "1")) }
assertEquals(BrowsingMode.Normal, browsingModeManager.mode)
}