Move SSD MediaStore PDF selection to typed Kotlin

ober

016316b44dc26b230eaaa4674b09f6cd0e555e28

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 2062fc6..06ee3a9 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -3872,7 +3872,8 @@
         (export normalizeFiringArc normalizeLabel shouldReplaceGuessLabel
                 shouldReplaceBoxTypeLabel resolvedBoxTypeLabel
                 boxTypeFallbackName boxTypeLabelMatches defaultBoxTypeLabel
-                isGenericGuessLabel isSsdPdfName shouldIncludeSsdPdfFile
+                isGenericGuessLabel isSsdPdfName
+                shouldIncludeSsdPdfChoiceName shouldIncludeSsdPdfFile
                 sourceBaseName canonicalSourceName isUsefulGuessLabel isErrorStatus
                 formatActivityDuration groupDisplayLabel appendModeStatus
                 selectedGroupStatus sessionCountsStatus rotatedPageStatus
@@ -4027,12 +4028,19 @@
           (let ((lower (string-lowercase name)))
             (and (string-ends-with? lower ".pdf")
                  (string-contains? lower "ssd"))))
+        (def (shouldIncludeSsdPdfChoiceName (name : String)
+                                            (currentChoices : Int32)
+                                            (limit : Int32)) : Bool
+          (and (< currentChoices limit)
+               (isSsdPdfName name)))
         (def (shouldIncludeSsdPdfFile (file : File)
                                       (currentChoices : Int32)
                                       (limit : Int32)) : Bool
-          (and (< currentChoices limit)
-               (and (fileIsFile file)
-                    (isSsdPdfName (fileName file)))))
+          (and (fileIsFile file)
+               (shouldIncludeSsdPdfChoiceName
+                 (fileName file)
+                 currentChoices
+                 limit)))
         (def (sourceBaseName (value : String)) : String
           (string-lowercase
             (string-replace-regex
@@ -6590,9 +6598,9 @@
        "            val idCol = cursor.getColumnIndexOrThrow(MediaStore.Downloads._ID)"
        "            val nameCol = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME)"
        "            val pathCol = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.RELATIVE_PATH)"
-       "            while (cursor.moveToNext() && choices.size < MAX_SSD_PDF_CHOICES) {"
+       "            while (cursor.moveToNext()) {"
        "                val name = cursor.getString(nameCol) ?: continue"
-       "                if (!isSsdPdfName(name)) continue"
+       "                if (!shouldIncludeSsdPdfChoiceName(name, choices.size, MAX_SSD_PDF_CHOICES)) continue"
        "                val id = cursor.getLong(idCol)"
        "                val relativePath = cursor.getString(pathCol)?.trim('/') ?: \"\""
        "                val label = ssdPdfDownloadLabel(relativePath, name)"