Skip to content

add tab count to bottom nav bar #5992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ class BrowserNavigationBarView @JvmOverloads constructor(
binding.bookmarksButton.isVisible = viewState.bookmarksButtonVisible
binding.fireButton.isVisible = viewState.fireButtonVisible
binding.tabsButton.isVisible = viewState.tabsButtonVisible
binding.tabsButton.count = viewState.tabsCount
binding.tabsButton.hasUnread = viewState.hasUnreadTabs

renderFireButtonPulseAnimation(enabled = viewState.fireButtonHighlighted)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BrowserNavigationBarViewModel @Inject constructor(
state.copy(
isVisible = navigationBarState.isEnabled && !isCustomTab,
tabsCount = tabs.size,
shouldUpdateTabsCount = tabs.size != state.tabsCount && tabs.isNotEmpty(),
hasUnreadTabs = tabs.firstOrNull { !it.viewed } != null,
)
}.flowOn(dispatcherProvider.io()).stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000L), ViewState())

Expand Down Expand Up @@ -160,6 +160,6 @@ class BrowserNavigationBarViewModel @Inject constructor(
val fireButtonHighlighted: Boolean = false,
val tabsButtonVisible: Boolean = true,
val tabsCount: Int = 0,
val shouldUpdateTabsCount: Boolean = false,
val hasUnreadTabs: Boolean = false,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ package com.duckduckgo.app.browser.tabswitcher
import android.content.Context
import android.util.AttributeSet
import com.duckduckgo.app.browser.databinding.ViewExperimentalTabSwitcherButtonBinding
import com.duckduckgo.common.ui.view.gone
import com.duckduckgo.common.ui.view.show
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.mobile.android.R as CommonR

class ExperimentalTabSwitcherButton @JvmOverloads constructor(
context: Context,
Expand All @@ -29,10 +32,30 @@ class ExperimentalTabSwitcherButton @JvmOverloads constructor(

private val binding: ViewExperimentalTabSwitcherButtonBinding by viewBinding()

override var hasUnread: Boolean = false
set(value) {
if (field != value) {
if (value) {
binding.tabsImageView.setImageResource(CommonR.drawable.ic_tab_24_highlighted)
} else {
binding.tabsImageView.setImageResource(CommonR.drawable.ic_tab_24)
}
}
field = value
}

override var count = 0
set(value) {
if (field != value) {
if (value < 100) {
binding.tabCount.text = "$value"
binding.tabCount.show()
binding.tabCountInfinite.gone()
} else {
binding.tabCount.gone()
binding.tabCountInfinite.show()
}
}
field = value
val text = if (count < 100) "$count" else "~"
binding.tabCount.text = text
}
}
15 changes: 2 additions & 13 deletions app/src/main/res/layout/view_browser_navigation_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,10 @@
android:layout_height="match_parent"
android:layout_weight="1" />

<FrameLayout
<com.duckduckgo.app.browser.tabswitcher.ExperimentalTabSwitcherButton
android:id="@+id/tabsButton"
android:layout_width="@dimen/bottomNavIconContainer"
android:layout_height="@dimen/bottomNavIconContainer"
android:background="@drawable/selectable_item_experimental_background">

<ImageView
android:id="@+id/tabsImageView"
android:layout_width="@dimen/bottomNavIcon"
android:layout_height="@dimen/bottomNavIcon"
android:layout_gravity="center"
android:contentDescription="@string/tabsMenuItem"
android:scaleType="center"
android:src="@drawable/ic_tab_24" />
</FrameLayout>
android:layout_height="@dimen/bottomNavIconContainer" />

<Space
android:layout_width="0dp"
Expand Down
59 changes: 47 additions & 12 deletions app/src/main/res/layout/view_experimental_tab_switcher_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,59 @@
~ limitations under the License.
-->

<merge xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:parentTag="android.widget.RelativeLayout">
android:id="@+id/tabsButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/selectable_item_experimental_background"
tools:layout_height="@dimen/bottomNavIconContainer"
tools:layout_width="@dimen/bottomNavIconContainer">

<ImageView
android:id="@+id/tabsImageView"
android:layout_width="@dimen/bottomNavIcon"
android:layout_height="@dimen/bottomNavIcon"
android:layout_gravity="center"
android:contentDescription="@string/tabsMenuItem"
android:scaleType="center"
android:src="@drawable/ic_tab_24" />

<!--
Below TextViews aren't a DaxTextView, special case for the Tabs icon.
They also uses DP instead of SP, because the background icon can't resize to accommodate
different font sizes.
The "∞" character is separated into its own view because the horizontal center-line
of that character is at a different height than numbers' horizontal center-line.
-->

<!-- This TextView doesn't migrate to DaxTextView, special case for the Tabs icon -->
<TextView
tools:ignore="DeprecatedWidgetInXml"
android:id="@+id/tabCount"
android:layout_width="@dimen/bottomNavIcon"
android:layout_height="@dimen/bottomNavIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="11.75dp"
android:layout_marginTop="7.5dp"
android:fontFamily="sans-serif-condensed"
android:gravity="center"
android:textColor="?attr/daxColorPrimaryIcon"
android:textSize="11sp"
android:textSize="9dp"
android:textStyle="bold"
tools:ignore="DeprecatedWidgetInXml,SpUsage"
tools:text="99" />

<TextView
android:id="@+id/tabCountInfinite"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="11.75dp"
android:layout_marginTop="6.5dp"
android:fontFamily="sans-serif-condensed"
android:gravity="center"
android:paddingBottom="3dp"
android:paddingStart="3dp"
android:background="@drawable/ic_tab_24"
tools:text="66" />
android:text="∞"
android:textColor="?attr/daxColorPrimaryIcon"
android:textSize="11dp"
android:textStyle="bold"
android:visibility="gone"
tools:ignore="DeprecatedWidgetInXml,HardcodedText,SpUsage" />

</merge>
</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--TODO this icon needs to be aligned with all the other new icons-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="25dp"
android:height="24dp"
android:viewportWidth="25"
android:viewportHeight="24">
<path
android:pathData="M21.492,8.473C21.906,8.473 22.242,8.808 22.242,9.223V13C22.242,15.761 20.004,18 17.242,18H11.242C8.481,18 6.242,15.761 6.242,13V7C6.242,4.239 8.481,2 11.242,2H15.02C15.434,2 15.77,2.336 15.77,2.75C15.77,3.164 15.434,3.5 15.02,3.5H11.242C9.309,3.5 7.742,5.067 7.742,7V13C7.742,14.933 9.309,16.5 11.242,16.5H17.242C19.175,16.5 20.742,14.933 20.742,13V9.223C20.742,8.808 21.078,8.473 21.492,8.473Z"
android:fillColor="?daxColorPrimaryIcon" />
<path
android:pathData="M4.742,7.569C4.742,6.958 4.119,6.555 3.653,6.951C2.79,7.684 2.242,8.778 2.242,10V15C2.242,18.866 5.376,22 9.242,22H14.242C15.464,22 16.557,21.452 17.291,20.589C17.687,20.123 17.284,19.5 16.673,19.5C16.402,19.5 16.153,19.635 15.955,19.821C15.508,20.242 14.905,20.5 14.242,20.5H9.242C6.205,20.5 3.742,18.037 3.742,15V10C3.742,9.337 4,8.734 4.422,8.286C4.608,8.089 4.742,7.84 4.742,7.569Z"
android:fillColor="?daxColorPrimaryIcon" />
<path
android:pathData="M23.242,4C23.242,5.657 21.899,7 20.242,7C18.585,7 17.242,5.657 17.242,4C17.242,2.343 18.585,1 20.242,1C21.899,1 23.242,2.343 23.242,4Z"
android:fillColor="?daxColorAccentBlue" />
</vector>
Loading