Generate SSD PDF scan from typed Jerboa
ober
3b587913357b447b4a62934ebe5764f91854c7de
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -4832,6 +4832,7 @@ mainActivityRenderCurrentPageAsync mainActivitySyncSelectedTreeAsync mainActivityLoadPdfAsync + mainActivityOpenPdfAsync mainActivityInstallApproveAreaDialogButton mainActivityInstallAppendDialogButton mainActivityInstallEditDialogButtons @@ -5429,6 +5430,25 @@ (extern (mainActivityRequestDownloadAccessRaw (activity : MainActivity)) : Unit (kotlin-member-call requestDownloadAccess)) + (extern (mainActivityFindDownloadSsdPdfsRaw + (activity : MainActivity)) : (List SsdPdfChoice) + (kotlin-member-call findDownloadSsdPdfs)) + (extern (mainActivityFindSsdPdfsFromTreeRaw + (activity : MainActivity) + (uri : Uri)) : (List SsdPdfChoice) + (kotlin-member-call findSsdPdfsFromTree)) + (extern (mainActivityUniquePdfChoicesRaw + (activity : MainActivity) + (choices : (List SsdPdfChoice))) : (List SsdPdfChoice) + (kotlin-member-call uniquePdfChoices)) + (extern (mainActivityShowPdfChoiceDialogRaw + (activity : MainActivity) + (choices : (List SsdPdfChoice)) + (title : String)) : Unit + (kotlin-member-call showPdfChoiceDialog)) + (extern (mainActivityShowNoSsdPdfsDialogRaw + (activity : MainActivity)) : Unit + (kotlin-member-call showNoSsdPdfsDialog)) (extern (mainActivityApproveAreaRaw (activity : MainActivity) (rect : FloatArray) @@ -7116,6 +7136,41 @@ activity (openFailedStatus (exceptionMessageRaw error))))))))))) + (def (mainActivityOpenPdfAsync + (activity : MainActivity) + (remembered : (Nullable String))) : Unit + (begin + (mainActivitySetStatusRaw + activity + (scanningDownloadsForSsdPdfsStatus)) + (runBackground + (lambda () + (let ((choices (mutable-list-empty SsdPdfChoice))) + (begin + (mutable-list-add-all! + choices + (mainActivityFindDownloadSsdPdfsRaw activity)) + (if (nullableTextPresent remembered) + (mutable-list-add-all! + choices + (mainActivityFindSsdPdfsFromTreeRaw + activity + (uriParse (nullableTextOrEmpty remembered)))) + (begin)) + (let ((unique + (mainActivityUniquePdfChoicesRaw + activity + choices))) + (mainActivityRunOnUiThreadRaw + activity + (lambda () + (if (ssdPdfChoicesAvailable unique) + (mainActivityShowPdfChoiceDialogRaw + activity + unique + "Open SSD PDF") + (mainActivityShowNoSsdPdfsDialogRaw + activity))))))))))) (def (mainActivityInstallApproveAreaDialogButton (activity : MainActivity) (dialog : AlertDialog) @@ -8810,21 +8865,8 @@ " }" "" " private fun openPdf() {" - " setStatus(scanningDownloadsForSsdPdfsStatus())" - " thread {" - " val choices = mutableListOf<SsdPdfChoice>()" - " choices.addAll(findDownloadSsdPdfs())" - " val remembered = getPreferences(MODE_PRIVATE).getString(PREF_SSD_PDF_TREE_URI, null)" - " if (nullableTextPresent(remembered)) choices.addAll(findSsdPdfsFromTree(Uri.parse(nullableTextOrEmpty(remembered))))" - " val unique = uniquePdfChoices(choices)" - " runOnUiThread {" - " if (ssdPdfChoicesAvailable(unique)) {" - " showPdfChoiceDialog(unique, \"Open SSD PDF\")" - " } else {" - " showNoSsdPdfsDialog()" - " }" - " }" - " }" + " val remembered = getPreferences(MODE_PRIVATE).getString(PREF_SSD_PDF_TREE_URI, null)" + " mainActivityOpenPdfAsync(this, remembered)" " }" "" " internal fun openAnyPdf() {" @@ -9511,7 +9553,7 @@ " }" " }" "" - " private fun showPdfChoiceDialog(choices: List<SsdPdfChoice>, title: String) {" + " internal fun showPdfChoiceDialog(choices: List<SsdPdfChoice>, title: String) {" " mainActivitySetPositiveOpenAnyPdf(" " mainActivitySetNeutralChooseSsdPdfFolder(" " mainActivitySetPdfChoiceItems(" @@ -9529,7 +9571,7 @@ " setStatus(ssdPdfFoundStatus(choices))" " }" "" - " private fun showNoSsdPdfsDialog() {" + " internal fun showNoSsdPdfsDialog() {" " val message = noSsdPdfsDialogMessage(hasDirectDownloadAccess())" " mainActivitySetPositiveRequestDownloadAccess(" " mainActivitySetNeutralChooseSsdPdfFolder(" @@ -9546,14 +9588,14 @@ " setStatus(noSsdPdfsFoundStatus())" " }" "" - " private fun findSsdPdfsFromTree(treeUri: Uri): List<SsdPdfChoice> {" + " internal fun findSsdPdfsFromTree(treeUri: Uri): List<SsdPdfChoice> {" " val maybeRoot = DocumentFile.fromTreeUri(this, treeUri)" " if (!documentFilePresent(maybeRoot)) return emptyList()" " val root = checkNotNull(maybeRoot)" " return findSsdPdfs(root)" " }" "" - " private fun findDownloadSsdPdfs(): List<SsdPdfChoice> {" + " internal fun findDownloadSsdPdfs(): List<SsdPdfChoice> {" " val choices = mutableListOf<SsdPdfChoice>()" " choices.addAll(findDownloadSsdPdfsViaMediaStore())" " choices.addAll(findDownloadSsdPdfsViaFiles())" @@ -9643,7 +9685,7 @@ " }" " }" "" - " private fun uniquePdfChoices(choices: List<SsdPdfChoice>): List<SsdPdfChoice> {" + " internal fun uniquePdfChoices(choices: List<SsdPdfChoice>): List<SsdPdfChoice> {" " return ssdPdfUniqueSortedLimitedChoices(choices, MAX_SSD_PDF_CHOICES)" " }" ""