Generate SSD PDF browser from typed Jerboa

ober

0afdf400f171898611277baf817c922f2430ac06

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 72d3710..b15e067 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -4833,6 +4833,7 @@
                 mainActivitySyncSelectedTreeAsync
                 mainActivityLoadPdfAsync
                 mainActivityOpenPdfAsync
+                mainActivityShowSsdPdfBrowserAsync
                 mainActivityInstallApproveAreaDialogButton
                 mainActivityInstallAppendDialogButton
                 mainActivityInstallEditDialogButtons
@@ -4992,6 +4993,20 @@
                   (items : (Array String))
                   (listener : (-> DialogInterface Int32 Unit))) : Builder
           (kotlin-member-call setItems))
+        (extern (alertDialogBuilderForActivityRaw
+                  (activity : MainActivity)) : Builder
+          (kotlin-call AlertDialog Builder))
+        (extern (alertDialogBuilderSetTitleRaw
+                  (builder : Builder)
+                  (title : String)) : Builder
+          (kotlin-member-call setTitle))
+        (extern (alertDialogBuilderSetMessageRaw
+                  (builder : Builder)
+                  (message : String)) : Builder
+          (kotlin-member-call setMessage))
+        (extern (alertDialogBuilderShowRaw
+                  (builder : Builder)) : AlertDialog
+          (kotlin-member-call show))
         (extern (alertDialogGetButtonRaw
                   (dialog : AlertDialog)
                   (which : Int32)) : Button
@@ -7171,6 +7186,66 @@
                               "Open SSD PDF")
                             (mainActivityShowNoSsdPdfsDialogRaw
                               activity)))))))))))
+        (def (alertDialogBuilderSetCancelAction
+               (builder : Builder)) : Builder
+          (alertDialogBuilderSetNegativeAction
+            builder
+            "Cancel"
+            (lambda ()
+              (begin))))
+        (def (showNoSsdPdfsInFolderDialog
+               (activity : MainActivity)) : Unit
+          (begin
+            (alertDialogBuilderShowRaw
+              (mainActivitySetPositiveChooseSsdPdfFolder
+                (alertDialogBuilderSetCancelAction
+                  (alertDialogBuilderSetMessageRaw
+                    (alertDialogBuilderSetTitleRaw
+                      (alertDialogBuilderForActivityRaw activity)
+                      (noSsdPdfsTitle))
+                    (noSsdPdfsInFolderMessage)))
+                activity))
+            (begin)))
+        (def (mainActivityShowSsdPdfBrowserAsync
+               (activity : MainActivity)
+               (treeUri : Uri)) : Unit
+          (begin
+            (mainActivitySetStatusRaw activity (scanningSsdPdfsStatus))
+            (runBackground
+              (lambda ()
+                (try
+                  (let ((choices
+                          (mainActivityFindSsdPdfsFromTreeRaw
+                            activity
+                            treeUri)))
+                    (mainActivityRunOnUiThreadRaw
+                      activity
+                      (lambda ()
+                        (if (ssdPdfChoicesEmpty choices)
+                          (begin
+                            (showNoSsdPdfsInFolderDialog activity)
+                            (mainActivitySetStatusRaw
+                              activity
+                              (noSsdPdfsChooseFolderStatus)))
+                          (begin
+                            (mainActivityShowPdfChoiceDialogRaw
+                              activity
+                              choices
+                              (openSsdPdfTitle))
+                            (mainActivitySetStatusRaw
+                              activity
+                              (ssdPdfFoundStatus choices)))))))
+                  (catch (error : Exception)
+                    (mainActivityRunOnUiThreadRaw
+                      activity
+                      (lambda ()
+                        (begin
+                          (mainActivitySetStatusRaw
+                            activity
+                            (ssdBrowserFailedStatus
+                              (exceptionMessageRaw error)))
+                          (mainActivityChooseSsdPdfFolderRaw
+                            activity))))))))))
         (def (mainActivityInstallApproveAreaDialogButton
                (activity : MainActivity)
                (dialog : AlertDialog)
@@ -9525,32 +9600,7 @@
        "    }"
        ""
        "    private fun showSsdPdfBrowser(treeUri: Uri) {"
-       "        setStatus(scanningSsdPdfsStatus())"
-       "        thread {"
-       "            try {"
-       "                val choices = findSsdPdfsFromTree(treeUri)"
-       "                runOnUiThread {"
-       "                    if (ssdPdfChoicesEmpty(choices)) {"
-       "                        mainActivitySetPositiveChooseSsdPdfFolder("
-       "                            AlertDialog.Builder(this)"
-       "                                .setTitle(noSsdPdfsTitle())"
-       "                                .setMessage(noSsdPdfsInFolderMessage())"
-       "                                .setNegativeButton(\"Cancel\", null),"
-       "                            this"
-       "                        ).show()"
-       "                        setStatus(noSsdPdfsChooseFolderStatus())"
-       "                        return@runOnUiThread"
-       "                    }"
-       "                    showPdfChoiceDialog(choices, openSsdPdfTitle())"
-       "                    setStatus(ssdPdfFoundStatus(choices))"
-       "                }"
-       "            } catch (error: Exception) {"
-       "                runOnUiThread {"
-       "                    setStatus(ssdBrowserFailedStatus(error.message))"
-       "                    chooseSsdPdfFolder()"
-       "                }"
-       "            }"
-       "        }"
+       "        mainActivityShowSsdPdfBrowserAsync(this, treeUri)"
        "    }"
        ""
        "    internal fun showPdfChoiceDialog(choices: List<SsdPdfChoice>, title: String) {"