From 7234875a5386344ff5317fb1719b84c160acc5ea Mon Sep 17 00:00:00 2001 From: Mike22 Date: Wed, 31 Dec 2025 21:40:56 +0100 Subject: [PATCH] [android, ui] Fix sticky focus behavior (#3242) This fixes an issue where game cards can stack focus highlights by touching and sliding in Grid/List views. Running and exiting the game by touch leaves a sticky focus that is not cleared. It is again possible to stack focus highlights that way. The first commit fixes the bug, the second refactors and simplifies the state management in GradientBorderCardView. WIP for now, until I thoroughly test it. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3242 Reviewed-by: crueter Reviewed-by: DraVee Co-authored-by: Mike22 Co-committed-by: Mike22 --- .../yuzu_emu/views/GradientBorderCardView.kt | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/GradientBorderCardView.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/GradientBorderCardView.kt index 8f730fc490..8121cfb6fa 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/GradientBorderCardView.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/GradientBorderCardView.kt @@ -35,6 +35,14 @@ class GradientBorderCardView @JvmOverloads constructor( updateThemeState() } + private fun updateBorderState() { + val shouldShow = isPressed || isFocused || isSelected + if (showGradientBorder != shouldShow) { + showGradientBorder = shouldShow + invalidate() + } + } + private fun updateThemeState() { val prefs = PreferenceManager.getDefaultSharedPreferences(context) val themeIndex = try { @@ -43,6 +51,7 @@ class GradientBorderCardView @JvmOverloads constructor( 0 // Default to Eden theme if error } isEdenTheme = themeIndex == 0 + invalidate() } override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { @@ -93,27 +102,22 @@ class GradientBorderCardView @JvmOverloads constructor( override fun onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect) - showGradientBorder = gainFocus - invalidate() + updateBorderState() } override fun setSelected(selected: Boolean) { super.setSelected(selected) - showGradientBorder = selected - invalidate() + updateBorderState() } override fun setPressed(pressed: Boolean) { super.setPressed(pressed) - if (pressed) { - showGradientBorder = true - invalidate() - } + updateBorderState() } override fun onDraw(canvas: Canvas) { super.onDraw(canvas) - if (showGradientBorder && !isPressed) { + if (showGradientBorder) { canvas.drawPath(borderPath, borderPaint) } } @@ -121,6 +125,5 @@ class GradientBorderCardView @JvmOverloads constructor( override fun onAttachedToWindow() { super.onAttachedToWindow() updateThemeState() - requestLayout() } }