From 411dbf98460be504e587e5e6339319ee0cd5de90 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 3 Mar 2024 01:28:10 +0300 Subject: [PATCH 1/2] Remove unused params from `TrafficBarChartItem` --- .../refresh/lists/sections/BlockListItem.kt | 3 --- .../traffic/TrafficBarChartViewHolder.kt | 12 ---------- .../sections/traffic/TrafficOverviewMapper.kt | 14 ++--------- .../traffic/TrafficOverviewUseCase.kt | 24 +------------------ 4 files changed, 3 insertions(+), 50 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt index cab6f03e2e9b..411e560dbcf5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/BlockListItem.kt @@ -270,9 +270,6 @@ sealed class BlockListItem(val type: Type) { data class TrafficBarChartItem( val entries: List, - val overlappingEntries: List? = null, - val selectedItem: String? = null, - val onBarSelected: ((period: String?) -> Unit)? = null, val onBarChartDrawn: ((visibleBarCount: Int) -> Unit)? = null, val entryContentDescriptions: List ) : BlockListItem(TRAFFIC_BAR_CHART) { 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 52aa478f590b..dba54748d539 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 @@ -42,18 +42,6 @@ class TrafficBarChartViewHolder(parent: ViewGroup) : BlockListItemViewHolder( val barCount = chart.draw(item) if (hasData(item.entries)) { chart.post { - val accessibilityEvent = object : BarChartAccessibilityHelper.BarChartAccessibilityEvent { - override fun onHighlight( - entry: BarEntry, - index: Int - ) { - val value = entry.data as? String - value?.let { - item.onBarSelected?.invoke(it) - } - } - } - val cutContentDescriptions = takeEntriesWithinGraphWidth(barCount, item.entryContentDescriptions) accessibilityHelper = BarChartAccessibilityHelper( chart, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficOverviewMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficOverviewMapper.kt index b9f3e192c267..2e2cd3d5a4a8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficOverviewMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficOverviewMapper.kt @@ -82,10 +82,8 @@ class TrafficOverviewMapper @Inject constructor( fun buildChart( dates: List, statsGranularity: StatsGranularity, - onBarSelected: (String?) -> Unit, onBarChartDrawn: (visibleBarCount: Int) -> Unit, - selectedType: Int, - selectedItemPeriod: String + selectedType: Int ): List { val chartItems = dates.map { val value = when (SelectedType.valueOf(selectedType)) { @@ -116,15 +114,7 @@ class TrafficOverviewMapper @Inject constructor( chartItems ) - result.add( - BlockListItem.TrafficBarChartItem( - chartItems, - selectedItem = selectedItemPeriod, - onBarSelected = onBarSelected, - onBarChartDrawn = onBarChartDrawn, - entryContentDescriptions = contentDescriptions - ) - ) + result.add(BlockListItem.TrafficBarChartItem(chartItems, onBarChartDrawn, contentDescriptions)) return result } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficOverviewUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficOverviewUseCase.kt index d57dda1e8ce2..663f9752322a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficOverviewUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/traffic/TrafficOverviewUseCase.kt @@ -19,7 +19,6 @@ import org.wordpress.android.ui.stats.refresh.lists.widget.WidgetUpdater import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.ui.stats.refresh.utils.StatsUtils -import org.wordpress.android.ui.stats.refresh.utils.trackGranular import org.wordpress.android.ui.stats.refresh.utils.trackWithGranularity import org.wordpress.android.util.AppLog import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper @@ -269,14 +268,7 @@ class TrafficOverviewUseCase( selectedItem: VisitsAndViewsModel.PeriodData ) { items.addAll( - trafficOverviewMapper.buildChart( - dates, - lowerGranularity, - this::onBarSelected, - this::onBarChartDrawn, - uiState.selectedPosition, - selectedItem.period - ) + trafficOverviewMapper.buildChart(dates, lowerGranularity, this::onBarChartDrawn, uiState.selectedPosition) ) items.add( trafficOverviewMapper.buildColumns( @@ -287,20 +279,6 @@ class TrafficOverviewUseCase( ) } - private fun onBarSelected(period: String?) { - analyticsTracker.trackGranular( - AnalyticsTracker.Stat.STATS_OVERVIEW_BAR_CHART_TAPPED, - lowerGranularity - ) - if (period != null && period != "empty") { - val selectedDate = statsDateFormatter.parseStatsDate(lowerGranularity, period) - selectedDateProvider.selectDate( - selectedDate, - lowerGranularity - ) - } - } - @Suppress("MagicNumber") private fun onColumnSelected(position: Int) { val event = when (position) { From 668dd979254f4b9156fb878449a667b781c406c5 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 3 Mar 2024 01:28:30 +0300 Subject: [PATCH 2/2] 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)