For #4868 - Update content description of tabs button with number of tabs
parent
282c2dc182
commit
b07df9698a
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.components.toolbar
|
package org.mozilla.fenix.components.toolbar
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -31,14 +32,16 @@ class TabCounterToolbarButton(
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
showTabs.invoke()
|
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 {
|
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
||||||
override fun onViewAttachedToWindow(v: View?) {
|
override fun onViewAttachedToWindow(v: View?) {
|
||||||
setCount(sessionManager.sessions.count {
|
setCount(count)
|
||||||
it.private == isPrivate
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewDetachedFromWindow(v: View?) { /* no-op */ }
|
override fun onViewDetachedFromWindow(v: View?) { /* no-op */ }
|
||||||
|
@ -59,9 +62,21 @@ class TabCounterToolbarButton(
|
||||||
override fun bind(view: View) = Unit
|
override fun bind(view: View) = Unit
|
||||||
|
|
||||||
private fun updateCount() {
|
private fun updateCount() {
|
||||||
reference.get()?.setCountWithAnimation(sessionManager.sessions.count {
|
val count = sessionManager.sessions.count {
|
||||||
it.private == isPrivate
|
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 {
|
private val sessionManagerObserver = object : SessionManager.Observer {
|
||||||
|
|
|
@ -810,4 +810,9 @@
|
||||||
<!-- Open source licenses page title
|
<!-- Open source licenses page title
|
||||||
The first parameter is the app name -->
|
The first parameter is the app name -->
|
||||||
<string name="open_source_licenses_title">%s | OSS Libraries</string>
|
<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>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue