Skip to content

Commit a604649

Browse files
authored
Swiping tabs: Save tab pager state (#6019)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1207418217763355/task/1210186654423822?focus=true ### Description This PR just calls `TabPagerAdapter.saveState()` and `restoreState()` whenever the activity is saved and restored. ### Steps to test this PR - [ ] Enable Don't keep activities - [ ] Start the app, add a few tabs - [ ] Move between the browser and tab switcher a few times - [ ] Verify everything looks as expected
1 parent 711eb6f commit a604649

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ open class BrowserActivity : DuckDuckGoActivity() {
297297

298298
setContentView(binding.root)
299299

300-
initializeTabs()
300+
initializeTabs(savedInstanceState)
301301

302302
// LiveData observers are restarted on each showWebContent() call; we want to subscribe to
303303
// flows only once, so a separate initialization is necessary
@@ -315,6 +315,14 @@ open class BrowserActivity : DuckDuckGoActivity() {
315315
configureOnBackPressedListener()
316316
}
317317

318+
override fun onSaveInstanceState(outState: Bundle) {
319+
super.onSaveInstanceState(outState)
320+
321+
if (swipingTabsFeature.isEnabled) {
322+
outState.putParcelable(KEY_TAB_PAGER_STATE, tabPagerAdapter.saveState())
323+
}
324+
}
325+
318326
private fun configureFlowCollectors() {
319327
if (swipingTabsFeature.isEnabled) {
320328
lifecycleScope.launch {
@@ -813,6 +821,7 @@ open class BrowserActivity : DuckDuckGoActivity() {
813821
private const val OPEN_DUCK_CHAT = "OPEN_DUCK_CHAT_EXTRA"
814822

815823
private const val MAX_ACTIVE_TABS = 40
824+
private const val KEY_TAB_PAGER_STATE = "tabPagerState"
816825
}
817826

818827
inner class BrowserStateRenderer {
@@ -856,7 +865,7 @@ open class BrowserActivity : DuckDuckGoActivity() {
856865
}
857866
}
858867

859-
private fun initializeTabs() {
868+
private fun initializeTabs(savedInstanceState: Bundle?) {
860869
if (swipingTabsFeature.isEnabled) {
861870
tabManager.registerCallbacks(
862871
onTabsUpdated = ::onTabsUpdated,
@@ -865,6 +874,10 @@ open class BrowserActivity : DuckDuckGoActivity() {
865874
tabPager.adapter = tabPagerAdapter
866875
tabPager.registerOnPageChangeCallback(onTabPageChangeListener)
867876
tabPager.setPageTransformer(MarginPageTransformer(resources.getDimension(com.duckduckgo.mobile.android.R.dimen.keyline_1).toPx().toInt()))
877+
878+
savedInstanceState?.getBundle(KEY_TAB_PAGER_STATE)?.let {
879+
tabPagerAdapter.restoreState(it)
880+
}
868881
}
869882

870883
binding.fragmentContainer.isVisible = !swipingTabsFeature.isEnabled

0 commit comments

Comments
 (0)