Move SSD PDF label formatting to typed Kotlin
ober
5b8ef4b2e517c452de31ce3554e4f66b7aaef1af
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -1219,6 +1219,7 @@ SsdPdfChoice-label SsdPdfChoice-uri ssdPdfChoiceLabels ssdPdfChoiceUriAt ssdPdfUniqueChoicesByLabel ssdPdfFoundStatus + ssdPdfDownloadLabel ssdPdfDownloadFileLabel ssdPdfTreeLabel ssdPdfUniqueSortedLimitedChoices) (type Int32) (type Uri) @@ -1239,6 +1240,14 @@ (string-append (int32->string (list-size choices)) " SSD PDFs"))) + (def (ssdPdfTreeLabel (prefix : String) (name : String)) : String + (if (string-blank? prefix) + name + (string-append prefix (string-append "/" name)))) + (def (ssdPdfDownloadLabel (relativePath : String) (name : String)) : String + (ssdPdfTreeLabel relativePath name)) + (def (ssdPdfDownloadFileLabel (relativePath : String)) : String + (string-append "Download/" relativePath)) (def (ssdPdfUniqueChoicesByLabel (choices : (List SsdPdfChoice))) : (MutableList SsdPdfChoice) (let ((seen (mutable-set-empty String))) (for/fold ((out (mutable-list-empty SsdPdfChoice))) @@ -5748,7 +5757,7 @@ " if (!isSsdPdfName(name)) continue" " val id = cursor.getLong(idCol)" " val relativePath = cursor.getString(pathCol)?.trim('/') ?: \"\"" - " val label = if (relativePath.isBlank()) name else \"$relativePath/$name\"" + " val label = ssdPdfDownloadLabel(relativePath, name)" " choices.add(SsdPdfChoice(label, ContentUris.withAppendedId(MediaStore.Downloads.EXTERNAL_CONTENT_URI, id)))" " }" " }" @@ -5765,7 +5774,7 @@ " .filter { it.isFile && isSsdPdfName(it.name) }" " .take(MAX_SSD_PDF_CHOICES)" " .forEach { file ->" - " val label = \"Download/${file.relativeToOrSelf(dir).path}\"" + " val label = ssdPdfDownloadFileLabel(file.relativeToOrSelf(dir).path)" " choices.add(SsdPdfChoice(label, Uri.fromFile(file)))" " }" " } catch (_: Exception) {" @@ -5791,7 +5800,7 @@ " .forEach { child ->" " if (choices.size >= MAX_SSD_PDF_CHOICES) return" " val name = child.name ?: return@forEach" - " val label = if (prefix.isBlank()) name else \"$prefix/$name\"" + " val label = ssdPdfTreeLabel(prefix, name)" " if (child.isDirectory) {" " collectSsdPdfs(child, label, choices, depth + 1)" " } else if ("