Generate SSD download file scan from typed Jerboa

ober

bdb05852f43f8b3285ba2ea7319e860cda860745

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 6b3f36e..b7271ea 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -4745,6 +4745,7 @@
                       (java lang Runnable)
                       (java lang Thread)
                       (java util UUID)
+                      (kotlin io FileTreeWalk)
                       (android app AlertDialog)
                       (android app AlertDialog Builder)
                       (android content ContentUris)
@@ -4854,6 +4855,7 @@
                 reviewViewMakeScaleGestureDetector
                 forEachDocumentFile
                 collectSsdPdfChoicesFromMediaCursor
+                collectSsdPdfChoicesFromDownloadFiles
                 mainActivityInstallReviewViewCallbacks
                 mainActivitySelectGroupId
                 mainActivitySelectRequestedGroup
@@ -4986,6 +4988,7 @@
         (type Editable)
         (type EditText)
         (type File)
+        (type FileTreeWalk)
         (type InputStream)
         (type OutputStream)
         (type LayoutParams)
@@ -5026,6 +5029,20 @@
           (kotlin-member-get name))
         (extern (fileMkdirsRaw (file : File)) : Bool
           (kotlin-member-call mkdirs))
+        (extern (fileWalkTopDownRaw (file : File)) : FileTreeWalk
+          (kotlin-member-call walkTopDown))
+        (extern (fileTreeWalkMaxDepthRaw (walk : FileTreeWalk)
+                                         (maxDepth : Int32)) : FileTreeWalk
+          (kotlin-member-call maxDepth))
+        (extern (fileTreeWalkToListRaw (walk : FileTreeWalk)) : (List File)
+          (kotlin-member-call toList))
+        (extern (fileRelativeToOrSelfRaw (file : File)
+                                         (base : File)) : File
+          (kotlin-member-call relativeToOrSelf))
+        (extern (filePathRaw (file : File)) : String
+          (kotlin-member-get path))
+        (extern (uriFromFileRaw (file : File)) : Uri
+          (kotlin-call Uri fromFile))
         (extern (documentFileIsDirectoryRaw (file : DocumentFile)) : Bool
           (kotlin-member-get isDirectory))
         (extern (documentFileIsFile (file : DocumentFile)) : Bool
@@ -5888,6 +5905,31 @@
                   (begin))
                 ignored))
             (begin)))
+        (def (collectSsdPdfChoicesFromDownloadFiles
+               (dir : File)
+               (choices : (MutableList SsdPdfChoice))
+               (maxDepth : Int32)
+               (limit : Int32)) : Unit
+          (let ((files
+                  (fileTreeWalkToListRaw
+                    (fileTreeWalkMaxDepthRaw
+                      (fileWalkTopDownRaw dir)
+                      maxDepth))))
+            (begin
+              (for/fold ((ignored (int32 0)))
+                        ((i (in-range (int32 0) (list-size files))))
+                (let ((file (list-ref files i)))
+                  (begin
+                    (if (shouldIncludeSsdPdfFile file (list-size choices) limit)
+                      (mutable-list-add!
+                        choices
+                        (make-SsdPdfChoice
+                          (ssdPdfDownloadFileLabel
+                            (filePathRaw (fileRelativeToOrSelfRaw file dir)))
+                          (uriFromFileRaw file)))
+                      (begin))
+                    ignored)))
+              (begin))))
         (def (trimmedNonBlankLines (text : String)) : (MutableList String)
           (let ((lines (stringLines text)))
             (for/fold ((out (mutable-list-empty String)))
@@ -10404,14 +10446,12 @@
        "        if (fileIsNotDirectory(dir)) return emptyList()"
        "        val choices = mutableListOf<SsdPdfChoice>()"
        "        try {"
-       "            dir.walkTopDown()"
-       "                .maxDepth(MAX_SSD_PDF_SCAN_DEPTH)"
-       "                .forEach { file ->"
-       "                    if (shouldIncludeSsdPdfFile(file, choices.size, MAX_SSD_PDF_CHOICES)) {"
-       "                        val label = ssdPdfDownloadFileLabel(file.relativeToOrSelf(dir).path)"
-       "                        choices.add(SsdPdfChoice(label, Uri.fromFile(file)))"
-       "                    }"
-       "                }"
+       "            collectSsdPdfChoicesFromDownloadFiles("
+       "                dir,"
+       "                choices,"
+       "                MAX_SSD_PDF_SCAN_DEPTH,"
+       "                MAX_SSD_PDF_CHOICES"
+       "            )"
        "        } catch (_: Exception) {"
        "        }"
        "        return choices"