From 2dcd3dc743e32a9a181fcb23e62c4b98552184ff Mon Sep 17 00:00:00 2001
From: Victor Andreasson <victor.andreasson@fripost.org>
Date: Sun, 25 Aug 2024 21:53:19 +0200
Subject: [PATCH] Don't instantiate external access action handlers upon app
 launch

Since external access typically happens either infrequently or in an
automated fashion, any small delay this instantiation creates should be
tolerable.

The reason for this change is that it allows us to run local JVM tests.
Before this change, the app could not run without a real Android device
and its Context.
---
 .../com/orgzly/android/external/ExternalAccessReceiver.kt  | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/app/src/main/java/com/orgzly/android/external/ExternalAccessReceiver.kt b/app/src/main/java/com/orgzly/android/external/ExternalAccessReceiver.kt
index 97b8ec116..300f3d41b 100644
--- a/app/src/main/java/com/orgzly/android/external/ExternalAccessReceiver.kt
+++ b/app/src/main/java/com/orgzly/android/external/ExternalAccessReceiver.kt
@@ -8,15 +8,14 @@ import com.orgzly.android.external.actionhandlers.*
 import com.orgzly.android.external.types.Response
 
 class ExternalAccessReceiver : BroadcastReceiver() {
-    val actionHandlers = listOf(
+    override fun onReceive(context: Context?, intent: Intent?) {
+        val actionHandlers = listOf(
             GetOrgInfo(),
             RunSearch(),
             EditNotes(),
             EditSavedSearches(),
             ManageWidgets()
-    )
-
-    override fun onReceive(context: Context?, intent: Intent?) {
+        )
         val response = actionHandlers.asSequence()
                 .mapNotNull { it.handle(intent!!, context!!) }
                 .firstOrNull()