From 8165caecc954c456513019616ccd276935cd95d5 Mon Sep 17 00:00:00 2001 From: Noah Bond Date: Thu, 9 Sep 2021 10:19:15 -0700 Subject: [PATCH] Issue mozilla-mobile#20637 - Fixed bug causing the tabs tray to scroll to the wrong tab when opened --- .../org/mozilla/fenix/tabstray/TrayPagerAdapter.kt | 4 +++- .../fenix/tabstray/browser/NormalBrowserTrayList.kt | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/tabstray/TrayPagerAdapter.kt b/app/src/main/java/org/mozilla/fenix/tabstray/TrayPagerAdapter.kt index de2b00dfe188..fdca8dec620f 100644 --- a/app/src/main/java/org/mozilla/fenix/tabstray/TrayPagerAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/tabstray/TrayPagerAdapter.kt @@ -18,6 +18,8 @@ import org.mozilla.fenix.sync.SyncedTabsAdapter import org.mozilla.fenix.tabstray.browser.BrowserTabsAdapter import org.mozilla.fenix.tabstray.browser.BrowserTrayInteractor import org.mozilla.fenix.tabstray.browser.InactiveTabsAdapter +import org.mozilla.fenix.tabstray.browser.maxActiveTime +import org.mozilla.fenix.tabstray.ext.isNormalTabActive import org.mozilla.fenix.tabstray.syncedtabs.TabClickDelegate import org.mozilla.fenix.tabstray.viewholders.AbstractPageViewHolder import org.mozilla.fenix.tabstray.viewholders.NormalBrowserPageViewHolder @@ -53,7 +55,7 @@ class TrayPagerAdapter( itemView, store, interactor, - browserStore.state.normalTabs.indexOf(selectedTab) + browserStore.state.normalTabs.filter { it.isNormalTabActive(maxActiveTime) }.indexOf(selectedTab) ) } PrivateBrowserPageViewHolder.LAYOUT_ID -> { diff --git a/app/src/main/java/org/mozilla/fenix/tabstray/browser/NormalBrowserTrayList.kt b/app/src/main/java/org/mozilla/fenix/tabstray/browser/NormalBrowserTrayList.kt index 3b4cd2e4ebca..975a3707fde3 100644 --- a/app/src/main/java/org/mozilla/fenix/tabstray/browser/NormalBrowserTrayList.kt +++ b/app/src/main/java/org/mozilla/fenix/tabstray/browser/NormalBrowserTrayList.kt @@ -23,17 +23,17 @@ import java.util.concurrent.TimeUnit */ const val DEFAULT_ACTIVE_DAYS = 4L +/** + * The maximum time from when a tab was created or accessed until it is considered "inactive". + */ +val maxActiveTime = TimeUnit.DAYS.toMillis(DEFAULT_ACTIVE_DAYS) + class NormalBrowserTrayList @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 ) : AbstractBrowserTrayList(context, attrs, defStyleAttr) { - /** - * The maximum time from when a tab was created or accessed until it is considered "inactive". - */ - var maxActiveTime = TimeUnit.DAYS.toMillis(DEFAULT_ACTIVE_DAYS) - private val concatAdapter by lazy { adapter as ConcatAdapter } override val tabsFeature by lazy {