From 7d764d7f4758eca87961efee8a658a5d20dbe7d0 Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Wed, 16 Oct 2024 23:29:26 +0200 Subject: [PATCH] Update selected ViewHolder after notifying --- .../layoutmanager/PivotSelector.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotSelector.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotSelector.kt index 7b1c823c..deec0392 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotSelector.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/layoutmanager/PivotSelector.kt @@ -213,6 +213,11 @@ internal class PivotSelector( } fun onLayoutCompleted() { + if (isSelectionUpdatePending) { + isSelectionUpdatePending = false + dispatchViewHolderSelected() + dispatchViewHolderSelectedAndAligned() + } /** * Always update the selected ViewHolder on every layout update */ @@ -223,11 +228,6 @@ internal class PivotSelector( } } } - if (isSelectionUpdatePending) { - isSelectionUpdatePending = false - dispatchViewHolderSelected() - dispatchViewHolderSelectedAndAligned() - } } fun getCurrentSubPositions(): Int { @@ -350,15 +350,13 @@ internal class PivotSelector( listener.onViewHolderDeselected(recyclerView, viewHolder) } } - if (viewHolder is DpadViewHolder) { - selectedViewHolder = viewHolder viewHolder.onViewHolderSelected() - } else { - selectedViewHolder = null } } + selectedViewHolder = viewHolder + if (viewHolder != null) { selectionListeners.forEach { listener -> listener.onViewHolderSelected(