Skip to content

Commit

Permalink
For mozilla-mobile#15324 - Show tab settings and recently closed item…
Browse files Browse the repository at this point in the history
…s in menu when no tabs
  • Loading branch information
ekager committed Sep 29, 2020
1 parent e49cd9c commit 01e802f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ class TabbedBrowsingTest {
}.openTabTray {
verifyNoTabsOpened()
verifyNewTabButton()
verifyTabTrayOverflowMenu(false)
verifyTabTrayOverflowMenu(true)
}.toggleToPrivateTabs {
verifyNoTabsOpened()
verifyNewTabButton()
verifyTabTrayOverflowMenu(false)
verifyTabTrayOverflowMenu(true)
}
}

Expand Down
20 changes: 12 additions & 8 deletions app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class TabTrayView(
private var tabsTouchHelper: TabsTouchHelper
private val collectionsButtonAdapter = SaveToCollectionsButtonAdapter(interactor, isPrivate)

private val syncedTabsController = SyncedTabsController(lifecycleOwner, view, store, concatAdapter)
private val syncedTabsController =
SyncedTabsController(lifecycleOwner, view, store, concatAdapter)
private val syncedTabsFeature = ViewBoundFeatureWrapper<SyncedTabsFeature>()

private var hasLoaded = false
Expand Down Expand Up @@ -211,7 +212,10 @@ class TabTrayView(
}

tabTrayItemMenu =
TabTrayItemMenu(view.context, { view.tab_layout.selectedTabPosition == 0 }) {
TabTrayItemMenu(
view.context,
{ tabs.isNotEmpty() && view.tab_layout.selectedTabPosition == 0 },
{ tabs.isNotEmpty() }) {
when (it) {
is TabTrayItemMenu.Item.ShareAllTabs -> interactor.onShareTabsClicked(
isPrivateModeSelected
Expand Down Expand Up @@ -431,7 +435,6 @@ class TabTrayView(
} else {
View.VISIBLE
}
view.tab_tray_overflow.isVisible = !hasNoTabs

counter_text.text = updateTabCounter(browserState.normalTabs.size)
updateTabCounterContentDescription(browserState.normalTabs.size)
Expand Down Expand Up @@ -592,9 +595,9 @@ class TabTrayView(
// We add the offset, because the layoutManager is initialized with `reverseLayout`.
// We also add 1 to display the tab item above the selected browser tab.
val recyclerViewIndex = selectedBrowserTabIndex +
collectionsButtonAdapter.itemCount +
syncedTabsController.adapter.itemCount +
1
collectionsButtonAdapter.itemCount +
syncedTabsController.adapter.itemCount +
1

layoutManager?.scrollToPosition(recyclerViewIndex)
}
Expand All @@ -614,6 +617,7 @@ class TabTrayView(
class TabTrayItemMenu(
private val context: Context,
private val shouldShowSaveToCollection: () -> Boolean,
private val hasOpenTabs: () -> Boolean,
private val onItemTapped: (Item) -> Unit = {}
) {

Expand Down Expand Up @@ -643,7 +647,7 @@ class TabTrayItemMenu(
) {
context.components.analytics.metrics.track(Event.TabsTrayShareAllTabsPressed)
onItemTapped.invoke(Item.ShareAllTabs)
},
}.apply { visible = hasOpenTabs },

SimpleBrowserMenuItem(
context.getString(R.string.tab_tray_menu_tab_settings),
Expand All @@ -665,7 +669,7 @@ class TabTrayItemMenu(
) {
context.components.analytics.metrics.track(Event.TabsTrayCloseAllTabsPressed)
onItemTapped.invoke(Item.CloseAllTabs)
}
}.apply { visible = hasOpenTabs }
)
}
}

0 comments on commit 01e802f

Please sign in to comment.