From 668dd979254f4b9156fb878449a667b781c406c5 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 3 Mar 2024 01:28:30 +0300 Subject: [PATCH] Make chart bars not clickable on the TRAFFIC tab for accessibility --- .../lists/sections/traffic/TrafficBarChartViewHolder.kt | 6 +----- .../ui/stats/refresh/utils/BarChartAccessibilityHelper.kt | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficBarChartViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficBarChartViewHolder.kt index dba54748d539..32af13106cbd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficBarChartViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficBarChartViewHolder.kt @@ -43,11 +43,7 @@ class TrafficBarChartViewHolder(parent: ViewGroup) : BlockListItemViewHolder( if (hasData(item.entries)) { chart.post { val cutContentDescriptions = takeEntriesWithinGraphWidth(barCount, item.entryContentDescriptions) - accessibilityHelper = BarChartAccessibilityHelper( - chart, - contentDescriptions = cutContentDescriptions, - accessibilityEvent = accessibilityEvent - ) + accessibilityHelper = BarChartAccessibilityHelper(chart, cutContentDescriptions) ViewCompat.setAccessibilityDelegate(chart, accessibilityHelper) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/BarChartAccessibilityHelper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/BarChartAccessibilityHelper.kt index 5e558312ac11..9d05355fdd11 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/BarChartAccessibilityHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/utils/BarChartAccessibilityHelper.kt @@ -12,7 +12,7 @@ import com.github.mikephil.charting.interfaces.datasets.IBarDataSet class BarChartAccessibilityHelper( private val barChart: BarChart, private val contentDescriptions: List, - private val accessibilityEvent: BarChartAccessibilityEvent + private val accessibilityEvent: BarChartAccessibilityEvent? = null ) : ExploreByTouchHelper(barChart) { private val dataSet: IBarDataSet = barChart.data.dataSets.first() @@ -51,7 +51,7 @@ class BarChartAccessibilityHelper( when (action) { AccessibilityNodeInfoCompat.ACTION_CLICK -> { val entry = dataSet.getEntryForIndex(virtualViewId) - accessibilityEvent.onHighlight(entry, virtualViewId) + accessibilityEvent?.onHighlight(entry, virtualViewId) return true } } @@ -74,7 +74,7 @@ class BarChartAccessibilityHelper( } } - node.addAction(AccessibilityActionCompat.ACTION_CLICK) + accessibilityEvent?.let { node.addAction(AccessibilityActionCompat.ACTION_CLICK) } val entryRectF = barChart.getBarBounds(dataSet.getEntryForIndex(virtualViewId)) val entryRect = Rect() entryRectF.round(entryRect)