From fd8dbfe8dcc1a990537e5875f3f6eab7fb8f780b Mon Sep 17 00:00:00 2001 From: mcarare Date: Tue, 1 Sep 2020 15:44:34 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/14540: Fix updating list and item info for a11y services. --- .../mozilla/fenix/tabtray/FenixTabsAdapter.kt | 6 ++++- .../org/mozilla/fenix/tabtray/TabTrayView.kt | 20 +++++++++++++++- .../fenix/tabtray/TabTrayViewHolder.kt | 23 ++++++++----------- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/FenixTabsAdapter.kt b/app/src/main/java/org/mozilla/fenix/tabtray/FenixTabsAdapter.kt index 6706640191..f425173f93 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/FenixTabsAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/FenixTabsAdapter.kt @@ -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) diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt index d2717e5135..3a237e22af 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayView.kt @@ -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 { diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt index 04c43b0cbe..851c539847 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt @@ -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 + ) } } }