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

[fenix] For https://github.com/mozilla-mobile/fenix/issues/18009: Correctly report items in adapter for a11y services.

This commit is contained in:
mcarare 2021-02-26 16:05:41 +02:00 committed by Mihai Adrian Carare
parent c37145d49d
commit 95a660a203
3 changed files with 40 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import mozilla.components.feature.top.sites.TopSite
import org.mozilla.fenix.R
import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor
import org.mozilla.fenix.home.sessioncontrol.viewholders.topsites.TopSitesAdapter
import org.mozilla.fenix.utils.AccessibilityGridLayoutManager
class TopSiteViewHolder(
view: View,
@ -20,8 +21,12 @@ class TopSiteViewHolder(
private val topSitesAdapter = TopSitesAdapter(interactor)
init {
val gridLayoutManager =
AccessibilityGridLayoutManager(view.context, SPAN_COUNT)
view.top_sites_list.apply {
adapter = topSitesAdapter
layoutManager = gridLayoutManager
}
}
@ -31,5 +36,6 @@ class TopSiteViewHolder(
companion object {
const val LAYOUT_ID = R.layout.component_top_sites
const val SPAN_COUNT = 4
}
}

View File

@ -0,0 +1,32 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.utils
import android.content.Context
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
/**
* A GridLayoutManager that can be used to override methods in Android implementation
* to improve ayy1 or fix a11y issues.
*/
class AccessibilityGridLayoutManager(
context: Context,
spanCount: Int
) : GridLayoutManager(
context,
spanCount
) {
override fun getColumnCountForAccessibility(
recycler: RecyclerView.Recycler,
state: RecyclerView.State
): Int {
return if (itemCount < spanCount) {
itemCount
} else {
super.getColumnCountForAccessibility(recycler, state)
}
}
}

View File

@ -24,7 +24,7 @@ to keep layout_width="match_parent"-->
android:clipToPadding="false"
android:overScrollMode="never"
android:nestedScrollingEnabled="false"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="4"
tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:spanCount="4"
tools:listitem="@layout/top_site_item" />
</LinearLayout>