Skip to content

Commit

Permalink
For mozilla-mobile#4868 - Update content description of tabs button w…
Browse files Browse the repository at this point in the history
…ith number of tabs
  • Loading branch information
ekager authored and boek committed Aug 23, 2019
1 parent 282c2dc commit b07df96
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.mozilla.fenix.components.toolbar

import android.content.Context
import android.util.TypedValue
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -31,14 +32,16 @@ class TabCounterToolbarButton(
setOnClickListener {
showTabs.invoke()
}
contentDescription =
parent.context.getString(R.string.mozac_feature_tabs_toolbar_tabs_button)

val count = sessionManager.sessions.count {
it.private == isPrivate
}

contentDescription = getDescriptionForTabCount(context, count)

addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: View?) {
setCount(sessionManager.sessions.count {
it.private == isPrivate
})
setCount(count)
}

override fun onViewDetachedFromWindow(v: View?) { /* no-op */ }
Expand All @@ -59,9 +62,21 @@ class TabCounterToolbarButton(
override fun bind(view: View) = Unit

private fun updateCount() {
reference.get()?.setCountWithAnimation(sessionManager.sessions.count {
val count = sessionManager.sessions.count {
it.private == isPrivate
})
}

reference.get()?.let {
it.contentDescription = getDescriptionForTabCount(it.context, count)
it.setCountWithAnimation(count)
}
}

private fun getDescriptionForTabCount(context: Context?, count: Int): String? {
return if (count > 1) context?.getString(
R.string.tab_counter_content_description_multi_tab,
count
) else context?.getString(R.string.tab_counter_content_description_one_tab)
}

private val sessionManagerObserver = object : SessionManager.Observer {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -810,4 +810,9 @@
<!-- Open source licenses page title
The first parameter is the app name -->
<string name="open_source_licenses_title">%s | OSS Libraries</string>

<!-- Content description of the tab counter toolbar button when one tab is open -->
<string name="tab_counter_content_description_one_tab">1 tab</string>
<!-- Content description of the tab counter toolbar button when multiple tabs are open. First parameter will be replaced with the number of tabs (always more than one) -->
<string name="tab_counter_content_description_multi_tab">%d tabs</string>
</resources>

0 comments on commit b07df96

Please sign in to comment.