2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] Issue 5736 Improve pop behavior after deleting tabs in settings (https://github.com/mozilla-mobile/fenix/pull/7478)

This commit is contained in:
kglazko 2020-01-08 10:27:14 -08:00 committed by GitHub
parent 54176609f8
commit 99d08c5677
2 changed files with 46 additions and 1 deletions

View File

@ -265,6 +265,11 @@ class SettingsPrivacyTest {
// Return to home screen and verify that all tabs, history and collection are gone // Return to home screen and verify that all tabs, history and collection are gone
// //
// Verify xxx // 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") @Ignore("This is a stub test, ignore for now")

View File

@ -153,7 +153,7 @@ class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_da
if (popAfter) viewLifecycleOwner.lifecycleScope.launch( if (popAfter) viewLifecycleOwner.lifecycleScope.launch(
Dispatchers.Main 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 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 { companion object {
private const val ENABLED_ALPHA = 1f private const val ENABLED_ALPHA = 1f