2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/16477: Migrate updateAccessibilityCollectionItemInfo to extension.

This commit is contained in:
mcarare 2020-11-12 16:34:55 +02:00 committed by Mihai Adrian Carare
parent 33e8a2b22b
commit 2302a589da
3 changed files with 31 additions and 28 deletions

View File

@ -66,6 +66,35 @@ fun View.addChildToAccessibilityNodeInfo(child: View) {
}
}
/**
* Updates the a11y collection item info for an item in a list.
*/
fun View.updateAccessibilityCollectionItemInfo(
rowIndex: Int,
columnIndex: Int,
isSelected: Boolean,
rowSpan: Int = 1,
columnSpan: Int = 1
) {
this.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View?,
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.collectionItemInfo =
AccessibilityNodeInfo.CollectionItemInfo.obtain(
rowIndex,
rowSpan,
columnIndex,
columnSpan,
false,
isSelected
)
}
}
}
/**
* Fills a [Rect] with data about a view's location in the screen.
*

View File

@ -22,6 +22,7 @@ import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.updateAccessibilityCollectionItemInfo
class FenixTabsAdapter(
private val context: Context,
@ -88,8 +89,7 @@ class FenixTabsAdapter(
columnIndex = itemIndex % columnsCount
}
(holder as TabTrayViewHolder).updateAccessibilityCollectionItemInfo(
holder.itemView,
holder.itemView.updateAccessibilityCollectionItemInfo(
rowIndex,
columnIndex,
selectedItems.contains(holder.tab)

View File

@ -5,7 +5,6 @@
package org.mozilla.fenix.tabtray
import android.view.View
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
@ -219,31 +218,6 @@ class TabTrayViewHolder(
imageLoader.loadIntoView(thumbnailView, ImageLoadRequest(id, thumbnailSize))
}
internal fun updateAccessibilityCollectionItemInfo(
item: View,
rowIndex: Int,
columnIndex: Int,
isSelected: Boolean
) {
item.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View?,
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.collectionItemInfo =
AccessibilityNodeInfo.CollectionItemInfo.obtain(
rowIndex,
1,
columnIndex,
1,
false,
isSelected
)
}
}
}
companion object {
private const val PLAY_PAUSE_BUTTON_EXTRA_DPS = 24
private const val GRID_ITEM_CLOSE_BUTTON_EXTRA_DPS = 24