[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 <crueter@eden-emu.dev>
Reviewed-by: DraVee <dravee@eden-emu.dev>
Co-authored-by: Mike22 <misakupka@gmail.com>
Co-committed-by: Mike22 <misakupka@gmail.com>
This commit is contained in:
Mike22 2025-12-31 21:40:56 +01:00 committed by crueter
parent 14951348bf
commit 7234875a53
No known key found for this signature in database
GPG Key ID: 425ACD2D4830EBC6
1 changed files with 13 additions and 10 deletions

View File

@ -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()
}
}