For #11431 - Scroll to restored tab in tab tray
parent
216396d979
commit
38657bbfc6
|
@ -192,6 +192,7 @@ class TabTrayDialogFragment : AppCompatDialogFragment() {
|
||||||
getString(R.string.snackbar_deleted_undo),
|
getString(R.string.snackbar_deleted_undo),
|
||||||
{
|
{
|
||||||
sessionManager.add(snapshot.session, isSelected, engineSessionState = state)
|
sessionManager.add(snapshot.session, isSelected, engineSessionState = state)
|
||||||
|
tabTrayView.scrollToTab(snapshot.session.id)
|
||||||
},
|
},
|
||||||
operation = { },
|
operation = { },
|
||||||
elevation = ELEVATION,
|
elevation = ELEVATION,
|
||||||
|
|
|
@ -126,7 +126,7 @@ class TabTrayView(
|
||||||
}
|
}
|
||||||
if (!hasLoaded) {
|
if (!hasLoaded) {
|
||||||
hasLoaded = true
|
hasLoaded = true
|
||||||
scrollToSelectedTab()
|
scrollToTab(view.context.components.core.store.state.selectedTabId)
|
||||||
if (view.context.settings().accessibilityServicesEnabled) {
|
if (view.context.settings().accessibilityServicesEnabled) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
delay(SELECTION_DELAY.toLong())
|
delay(SELECTION_DELAY.toLong())
|
||||||
|
@ -145,27 +145,30 @@ class TabTrayView(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tabTrayItemMenu = TabTrayItemMenu(view.context, { view.tab_layout.selectedTabPosition == 0 }) {
|
tabTrayItemMenu =
|
||||||
when (it) {
|
TabTrayItemMenu(view.context, { view.tab_layout.selectedTabPosition == 0 }) {
|
||||||
is TabTrayItemMenu.Item.ShareAllTabs -> interactor.onShareTabsClicked(
|
when (it) {
|
||||||
isPrivateModeSelected
|
is TabTrayItemMenu.Item.ShareAllTabs -> interactor.onShareTabsClicked(
|
||||||
)
|
isPrivateModeSelected
|
||||||
is TabTrayItemMenu.Item.SaveToCollection -> interactor.onSaveToCollectionClicked()
|
)
|
||||||
is TabTrayItemMenu.Item.CloseAllTabs -> interactor.onCloseAllTabsClicked(
|
is TabTrayItemMenu.Item.SaveToCollection -> interactor.onSaveToCollectionClicked()
|
||||||
isPrivateModeSelected
|
is TabTrayItemMenu.Item.CloseAllTabs -> interactor.onCloseAllTabsClicked(
|
||||||
)
|
isPrivateModeSelected
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
view.tab_tray_overflow.setOnClickListener {
|
view.tab_tray_overflow.setOnClickListener {
|
||||||
container.context.components.analytics.metrics.track(Event.TabsTrayMenuOpened)
|
container.context.components.analytics.metrics.track(Event.TabsTrayMenuOpened)
|
||||||
menu = tabTrayItemMenu.menuBuilder.build(container.context)
|
menu = tabTrayItemMenu.menuBuilder.build(container.context)
|
||||||
menu?.show(it)
|
menu?.show(it)
|
||||||
?.also { pu ->
|
?.also { pu ->
|
||||||
(pu.contentView as? CardView)?.setCardBackgroundColor(ContextCompat.getColor(
|
(pu.contentView as? CardView)?.setCardBackgroundColor(
|
||||||
view.context,
|
ContextCompat.getColor(
|
||||||
R.color.foundation_normal_theme
|
view.context,
|
||||||
))
|
R.color.foundation_normal_theme
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +214,7 @@ class TabTrayView(
|
||||||
filterTabs.invoke(filter)
|
filterTabs.invoke(filter)
|
||||||
|
|
||||||
updateState(view.context.components.core.store.state)
|
updateState(view.context.components.core.store.state)
|
||||||
scrollToSelectedTab()
|
scrollToTab(view.context.components.core.store.state.selectedTabId)
|
||||||
|
|
||||||
if (isPrivateModeSelected) {
|
if (isPrivateModeSelected) {
|
||||||
container.context.components.analytics.metrics.track(Event.TabsTrayPrivateModeTapped)
|
container.context.components.analytics.metrics.track(Event.TabsTrayPrivateModeTapped)
|
||||||
|
@ -220,8 +223,11 @@ class TabTrayView(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTabReselected(tab: TabLayout.Tab?) { /*noop*/ }
|
override fun onTabReselected(tab: TabLayout.Tab?) { /*noop*/
|
||||||
override fun onTabUnselected(tab: TabLayout.Tab?) { /*noop*/ }
|
}
|
||||||
|
|
||||||
|
override fun onTabUnselected(tab: TabLayout.Tab?) { /*noop*/
|
||||||
|
}
|
||||||
|
|
||||||
fun updateState(state: BrowserState) {
|
fun updateState(state: BrowserState) {
|
||||||
view.let {
|
view.let {
|
||||||
|
@ -266,14 +272,16 @@ class TabTrayView(
|
||||||
private fun toggleFabText(private: Boolean) {
|
private fun toggleFabText(private: Boolean) {
|
||||||
if (private) {
|
if (private) {
|
||||||
fabView.new_tab_button.extend()
|
fabView.new_tab_button.extend()
|
||||||
fabView.new_tab_button.contentDescription = view.context.resources.getString(R.string.add_private_tab)
|
fabView.new_tab_button.contentDescription =
|
||||||
|
view.context.resources.getString(R.string.add_private_tab)
|
||||||
} else {
|
} else {
|
||||||
fabView.new_tab_button.shrink()
|
fabView.new_tab_button.shrink()
|
||||||
fabView.new_tab_button.contentDescription = view.context.resources.getString(R.string.add_tab)
|
fabView.new_tab_button.contentDescription =
|
||||||
|
view.context.resources.getString(R.string.add_tab)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun scrollToSelectedTab() {
|
fun scrollToTab(sessionId: String?) {
|
||||||
(view.tabsTray as? BrowserTabsTray)?.also { tray ->
|
(view.tabsTray as? BrowserTabsTray)?.also { tray ->
|
||||||
val tabs = if (isPrivateModeSelected) {
|
val tabs = if (isPrivateModeSelected) {
|
||||||
view.context.components.core.store.state.privateTabs
|
view.context.components.core.store.state.privateTabs
|
||||||
|
@ -282,7 +290,7 @@ class TabTrayView(
|
||||||
}
|
}
|
||||||
|
|
||||||
val selectedBrowserTabIndex = tabs
|
val selectedBrowserTabIndex = tabs
|
||||||
.indexOfFirst { it.id == view.context.components.core.store.state.selectedTabId }
|
.indexOfFirst { it.id == sessionId }
|
||||||
|
|
||||||
tray.layoutManager?.scrollToPosition(selectedBrowserTabIndex)
|
tray.layoutManager?.scrollToPosition(selectedBrowserTabIndex)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue