Move SSD UI inversions to typed Kotlin

ober

44bab11581189f4651abe899e8ad2005cef4e314

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 44a8e16..d87eebf 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -1658,7 +1658,8 @@
                 TruthIndexEntry-sourceName TruthIndexEntry-canonicalSourceName
                 TruthIndexEntry-page TruthIndexEntry-dpi TruthIndexEntry-groupCount
                 TruthIndexEntry-truthTime betterTruthIndex
-                fileExists fileIsDirectory fileIsRegular fileIsNotRegular
+                fileExists fileIsDirectory fileIsNotDirectory
+                fileIsRegular fileIsNotRegular
                 fileIsSymbolicLink
                 fileSizeBytes
                 pathIsSymbolicLink pathNotSymbolicLink pathParentMatches
@@ -1756,6 +1757,8 @@
           (fileExistsRaw file))
         (def (fileIsDirectory (file : File)) : Bool
           (and (fileExists file) (fileIsDirectoryRaw file)))
+        (def (fileIsNotDirectory (file : File)) : Bool
+          (not (fileIsDirectory file)))
         (def (fileIsRegular (file : File)) : Bool
           (and (fileExists file) (fileIsFile file)))
         (def (fileIsNotRegular (file : File)) : Bool
@@ -4214,6 +4217,7 @@
                 shouldIncludeSsdPdfChoiceName shouldIncludeSsdPdfFile
                 shouldStopSsdPdfTreeScan documentFileIsDirectory
                 documentFileIsRegular ssdPdfDocumentIsDirectory
+                ssdPdfDocumentNotDirectory
                 shouldIncludeSsdPdfDocument
                 trimmedNonBlankLines trimmedNonBlankPathParts
                 sourceBaseName canonicalSourceName isUsefulGuessLabel isErrorStatus
@@ -4256,7 +4260,7 @@
                 permissionResultGranted downloadAccessBeforeRuntimePermissions
                 downloadAccessFromPermission activityResultRejected
                 pageNavigationBlocked pageNavigationBlockedForUri
-                selectModeDisabled ssdAreaModeInactive
+                nextSelectMode selectModeDisabled ssdAreaModeInactive
                 shouldPersistLoadedPdfState viewportScalePreferencePresent
                 viewportScalePreferenceMissing
                 lastPdfUriMismatch lastViewportPageMismatch
@@ -4424,6 +4428,8 @@
           (documentFileIsFile file))
         (def (ssdPdfDocumentIsDirectory (file : DocumentFile)) : Bool
           (documentFileIsDirectory file))
+        (def (ssdPdfDocumentNotDirectory (file : DocumentFile)) : Bool
+          (not (ssdPdfDocumentIsDirectory file)))
         (def (shouldIncludeSsdPdfDocument (file : DocumentFile)
                                           (name : String)
                                           (currentChoices : Int32)
@@ -4755,6 +4761,8 @@
         (def (pageNavigationBlockedForUri (uri : (Nullable Uri))
                                           (pageCount : Int32)) : Bool
           (pageNavigationBlocked (pdfUriLoaded uri) pageCount))
+        (def (nextSelectMode (enabled : Bool)) : Bool
+          (not enabled))
         (def (selectModeDisabled (enabled : Bool)) : Bool
           (not enabled))
         (def (ssdAreaModeInactive (enabled : Bool)) : Bool
@@ -6355,7 +6363,7 @@
        "    }"
        ""
        "    private fun toggleSelect() {"
-       "        setSelectMode(!reviewView.selectMode)"
+       "        setSelectMode(nextSelectMode(reviewView.selectMode))"
        "    }"
        ""
 	       "    private fun setSelectMode(enabled: Boolean) {"
@@ -7213,7 +7221,7 @@
        ""
        "    private fun findDownloadSsdPdfsViaFiles(): List<SsdPdfChoice> {"
        "        val dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)"
-       "        if (!fileIsDirectory(dir)) return emptyList()"
+       "        if (fileIsNotDirectory(dir)) return emptyList()"
        "        val choices = mutableListOf<SsdPdfChoice>()"
        "        try {"
        "            dir.walkTopDown()"
@@ -7243,7 +7251,7 @@
        "    ) {"
        "        if (shouldStopSsdPdfTreeScan(depth, choices.size, MAX_SSD_PDF_CHOICES, MAX_SSD_PDF_SCAN_DEPTH)) return"
        "        dir.listFiles()"
-       "            .sortedWith(compareBy<DocumentFile>({ !ssdPdfDocumentIsDirectory(it) }, { nullableLowercaseOrEmpty(it.name) }))"
+       "            .sortedWith(compareBy<DocumentFile>({ ssdPdfDocumentNotDirectory(it) }, { nullableLowercaseOrEmpty(it.name) }))"
        "            .forEach { child ->"
        "                if (shouldStopSsdPdfTreeScan(depth, choices.size, MAX_SSD_PDF_CHOICES, MAX_SSD_PDF_SCAN_DEPTH)) return"
        "                val name = child.name ?: return@forEach"