For #16477: Update a11y info to collection item for both grid and list.

upstream-sync
mcarare 4 years ago committed by Mihai Adrian Carare
parent 92b93081e5
commit b52f069573

@ -8,13 +8,15 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.View
import androidx.core.view.isVisible
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.checkbox_item.view.*
import kotlinx.android.synthetic.main.tab_tray_item.view.*
import mozilla.components.browser.tabstray.TabViewHolder
import mozilla.components.browser.tabstray.TabsAdapter
import mozilla.components.concept.base.images.ImageLoader
import mozilla.components.concept.tabstray.Tab
import mozilla.components.concept.tabstray.Tabs
import mozilla.components.concept.base.images.ImageLoader
import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
@ -36,6 +38,7 @@ class FenixTabsAdapter(
)
}
) {
private lateinit var tabsList: RecyclerView
var tabTrayInteractor: TabTrayInteractor? = null
private val mode: TabTrayDialogFragmentState.Mode?
@ -67,10 +70,28 @@ class FenixTabsAdapter(
override fun onBindViewHolder(holder: TabViewHolder, position: Int) {
super.onBindViewHolder(holder, position)
val newIndex = tabCount - position - 1
(holder as TabTrayViewHolder).updateAccessibilityRowInfo(
val isListTabView = context.settings().listTabView
val itemIndex: Int
val rowIndex: Int
val columnIndex: Int
if (isListTabView) {
itemIndex = tabCount - position - 1
rowIndex = itemIndex
columnIndex = 1
} else {
val columnsCount = (tabsList.layoutManager as GridLayoutManager).spanCount
itemIndex = position
rowIndex = itemIndex / columnsCount
columnIndex = itemIndex % columnsCount
}
(holder as TabTrayViewHolder).updateAccessibilityCollectionItemInfo(
holder.itemView,
newIndex,
rowIndex,
columnIndex,
selectedItems.contains(holder.tab)
)
@ -107,6 +128,11 @@ class FenixTabsAdapter(
}
}
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
tabsList = recyclerView
}
private fun showCheckedIfSelected(tab: Tab, view: View) {
val shouldBeChecked =
mode is TabTrayDialogFragmentState.Mode.MultiSelect && selectedItems.contains(tab)

@ -56,6 +56,7 @@ import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.MultiselectModeC
import org.mozilla.fenix.tabtray.TabTrayDialogFragmentState.Mode
import java.text.NumberFormat
import kotlin.math.max
import kotlin.math.roundToInt
import mozilla.components.browser.storage.sync.Tab as SyncTab
/**
@ -582,7 +583,7 @@ class TabTrayView(
}
counter_text.text = updateTabCounter(browserState.normalTabs.size)
updateTabCounterContentDescription(browserState.normalTabs.size)
updateTabTrayViewAccessibility(browserState.normalTabs.size)
adjustNewTabButtonsForNormalMode()
}
@ -665,7 +666,7 @@ class TabTrayView(
}
}
private fun updateTabCounterContentDescription(count: Int) {
private fun updateTabTrayViewAccessibility(count: Int) {
view.tab_layout.getTabAt(0)?.contentDescription = if (count == 1) {
view.context?.getString(R.string.open_tab_tray_single)
} else {
@ -678,13 +679,16 @@ class TabTrayView(
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.let {
info.collectionInfo = CollectionInfo.obtain(
tabsAdapter.tabCount,
1,
false
)
}
val isListTabView = view.context.settings().listTabView
val columnCount = if (isListTabView) 1 else getNumberOfGridColumns(view.context)
val rowCount = count.toDouble().div(columnCount).roundToInt()
info?.collectionInfo = CollectionInfo.obtain(
rowCount,
columnCount,
false
)
}
}
}

@ -219,7 +219,12 @@ class TabTrayViewHolder(
imageLoader.loadIntoView(thumbnailView, ImageLoadRequest(id, thumbnailSize))
}
internal fun updateAccessibilityRowInfo(item: View, newIndex: Int, isSelected: Boolean) {
internal fun updateAccessibilityCollectionItemInfo(
item: View,
rowIndex: Int,
columnIndex: Int,
isSelected: Boolean
) {
item.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View?,
@ -228,9 +233,9 @@ class TabTrayViewHolder(
super.onInitializeAccessibilityNodeInfo(host, info)
info?.collectionItemInfo =
AccessibilityNodeInfo.CollectionItemInfo.obtain(
newIndex,
1,
rowIndex,
1,
columnIndex,
1,
false,
isSelected

Loading…
Cancel
Save