2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/14540: Fix updating list and item info for a11y services.

This commit is contained in:
mcarare 2020-09-01 15:44:34 +03:00 committed by ekager
parent 12707f2b74
commit fd8dbfe8dc
3 changed files with 34 additions and 15 deletions

View File

@ -67,7 +67,11 @@ class FenixTabsAdapter(
override fun onBindViewHolder(holder: TabViewHolder, position: Int) {
super.onBindViewHolder(holder, position)
val newIndex = tabCount - position - 1
(holder as TabTrayViewHolder).updateAccessibilityRowIndex(holder.itemView, newIndex)
(holder as TabTrayViewHolder).updateAccessibilityRowInfo(
holder.itemView,
newIndex,
selectedItems.contains(holder.tab)
)
holder.tab?.let { tab ->
showCheckedIfSelected(tab, holder.itemView)

View File

@ -9,6 +9,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import android.view.accessibility.AccessibilityNodeInfo.CollectionInfo
import androidx.annotation.IdRes
import androidx.cardview.widget.CardView
import androidx.constraintlayout.widget.ConstraintLayout
@ -186,7 +188,7 @@ class TabTrayView(
concatAdapter.addAdapter(0, syncedTabsController.adapter)
if (hasAccessibilityEnabled) {
tabsAdapter.notifyDataSetChanged()
tabsAdapter.notifyItemRangeChanged(0, tabs.size)
}
if (!hasLoaded) {
hasLoaded = true
@ -491,6 +493,22 @@ class TabTrayView(
} else {
view.context?.getString(R.string.open_tab_tray_plural, count.toString())
}
view.tabsTray.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View?,
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.let {
info.collectionInfo = CollectionInfo.obtain(
tabsAdapter.tabCount,
1,
false
)
}
}
}
}
private fun updateTabCounter(count: Int): String {

View File

@ -187,25 +187,22 @@ class TabTrayViewHolder(
imageLoader.loadIntoView(thumbnailView, ImageLoadRequest(id, thumbnailSize))
}
internal fun updateAccessibilityRowIndex(item: View, newIndex: Int) {
internal fun updateAccessibilityRowInfo(item: View, newIndex: Int, isSelected: Boolean) {
item.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View?,
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.let {
info.collectionItemInfo = info.collectionItemInfo?.let { initialInfo ->
AccessibilityNodeInfo.CollectionItemInfo.obtain(
newIndex,
initialInfo.rowSpan,
initialInfo.columnIndex,
initialInfo.columnSpan,
false,
initialInfo.isSelected
)
}
}
info?.collectionItemInfo =
AccessibilityNodeInfo.CollectionItemInfo.obtain(
newIndex,
1,
1,
1,
false,
isSelected
)
}
}
}