From 0da83e36aa07c4bf7b4b1c4ed0e2863dde542edb Mon Sep 17 00:00:00 2001 From: lisonge Date: Tue, 24 Sep 2024 13:29:20 +0800 Subject: [PATCH] perf: a11yEventCallbacks --- app/src/main/kotlin/li/songe/gkd/service/A11yService.kt | 1 + .../main/kotlin/li/songe/gkd/util/LifecycleCallbacks.kt | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/li/songe/gkd/service/A11yService.kt b/app/src/main/kotlin/li/songe/gkd/service/A11yService.kt index 7862845..8370a1b 100644 --- a/app/src/main/kotlin/li/songe/gkd/service/A11yService.kt +++ b/app/src/main/kotlin/li/songe/gkd/service/A11yService.kt @@ -76,6 +76,7 @@ class A11yService : AccessibilityService(), OnCreate, OnA11yConnected, OnA11yEve onA11yConnected() } + override val a11yEventCallbacks = mutableListOf<(AccessibilityEvent) -> Unit>() override fun onAccessibilityEvent(event: AccessibilityEvent?) { if (event == null || !event.isUseful()) return onA11yEvent(event) diff --git a/app/src/main/kotlin/li/songe/gkd/util/LifecycleCallbacks.kt b/app/src/main/kotlin/li/songe/gkd/util/LifecycleCallbacks.kt index ac70d02..59e59f1 100644 --- a/app/src/main/kotlin/li/songe/gkd/util/LifecycleCallbacks.kt +++ b/app/src/main/kotlin/li/songe/gkd/util/LifecycleCallbacks.kt @@ -43,12 +43,15 @@ interface OnDestroy : CanOnCallback { } interface OnA11yEvent : CanOnCallback { + val a11yEventCallbacks: MutableList<(AccessibilityEvent) -> Unit> + get() = getCallbacks(6) + fun onA11yEvent(f: (AccessibilityEvent) -> Unit) { - getCallbacks<(AccessibilityEvent) -> Unit>(6).add(f) + a11yEventCallbacks.add(f) } fun onA11yEvent(event: AccessibilityEvent) { - getCallbacks<(AccessibilityEvent) -> Unit>(6).forEach { it(event) } + a11yEventCallbacks.forEach { it(event) } } }