Issue 5736 Improve pop behavior after deleting tabs in settings (#7478)
parent
7d613b72ae
commit
8ed14ac062
|
@ -265,6 +265,11 @@ class SettingsPrivacyTest {
|
|||
// Return to home screen and verify that all tabs, history and collection are gone
|
||||
//
|
||||
// Verify xxx
|
||||
//
|
||||
// New: If coming from tab -> settings -> delete browsing data
|
||||
// then expect to return to home screen
|
||||
// If coming from tab -> home -> settings -> delete browsing data
|
||||
// then expect return to settings (after which you can return to home manually)
|
||||
}
|
||||
|
||||
@Ignore("This is a stub test, ignore for now")
|
||||
|
|
|
@ -153,7 +153,7 @@ class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_da
|
|||
if (popAfter) viewLifecycleOwner.lifecycleScope.launch(
|
||||
Dispatchers.Main
|
||||
) {
|
||||
findNavController().popBackStack(R.id.homeFragment, false)
|
||||
returnToDeletionOrigin()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,6 +239,46 @@ class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_da
|
|||
fragmentView.site_permissions_item
|
||||
)
|
||||
}
|
||||
// If coming from Open Tab -> Settings, pop back to Home
|
||||
// If coming from Home -> Settings, pop back to Settings
|
||||
private fun returnToDeletionOrigin() {
|
||||
// If Delete browsing data fragment isn't in the backstack
|
||||
// then Android may have changed their naming convention
|
||||
// and we want to prevent a crash by defaulting to pop home behavior
|
||||
if (checkIfFragmentInBackStack(R.id.deleteBrowsingDataFragment)) {
|
||||
// If Settings is in the backstack then we can continue with intended behavior
|
||||
if (checkIfFragmentInBackStack(R.id.browserFragment)) findNavController().popBackStack(
|
||||
R.id.homeFragment,
|
||||
false
|
||||
)
|
||||
else findNavController().popBackStack()
|
||||
} else {
|
||||
findNavController().popBackStack(
|
||||
R.id.homeFragment,
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// For some reason, the only way you can tell if you came from
|
||||
// BrowserFrag -> Settings OR BrowserFrag -> HomeFrag -> Settings is to check whether
|
||||
// there is a browser fragment entry in the back stack. If there is, it means you came from BrowserFrag -> Settings
|
||||
// if there isn't, it means you came from HomeFrag -> Settings
|
||||
private fun checkIfFragmentInBackStack(res: Int): Boolean {
|
||||
val backStackEntryCount = parentFragmentManager.backStackEntryCount
|
||||
for (i in 0 until backStackEntryCount) {
|
||||
if (getResIdFromBackstack(parentFragmentManager.getBackStackEntryAt(i).name) == res) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun getResIdFromBackstack(name: String?): Int {
|
||||
val idString = name?.split("-")
|
||||
return idString!![1].toInt()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ENABLED_ALPHA = 1f
|
||||
|
|
Loading…
Reference in New Issue