Move SSD URI checks to typed Kotlin
ober
3d1821101e05f1782f3dbafc4ea2edd495960694
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -4357,7 +4357,7 @@ selectionIgnoredLoadingStatus shouldShowFiringArc shouldFocusFiringArc canvasLabelPresent canvasLabelMissing groupIdSelected - shouldCaptureViewport pdfUriLoaded sessionMissing + shouldCaptureViewport pdfUriLoaded uriOrEmpty sessionMissing viewportStatePresent viewportStateOrEmpty hasReplacementLabel missingReplacementLabel hasResolvedLabel ssdBrowserResumeReady focusChangeShouldShowDropdown @@ -4848,8 +4848,14 @@ (equal? groupId (nullable-get selectedGroupId)))) (def (shouldCaptureViewport (includeViewport : Bool)) : Bool includeViewport) + (extern (uriParse (text : String)) : Uri + (kotlin-call Uri parse)) (def (pdfUriLoaded (uri : (Nullable Uri))) : Bool (not (nullable-null? uri))) + (def (uriOrEmpty (uri : (Nullable Uri))) : Uri + (if (nullable-null? uri) + (uriParse "") + (nullable-get uri))) (def (sessionMissing (session : (Nullable SsdSession))) : Bool (nullable-null? session)) (def (viewportStatePresent (viewport : (Nullable ViewportState))) : Bool @@ -6657,7 +6663,8 @@ " }" "" " private fun renderCurrentPage() {" - " val uri = pdfUri ?: return" + " if (!pdfUriLoaded(pdfUri)) return" + " val uri = uriOrEmpty(pdfUri)" " val renderPageIndex = pageIndex" " val renderGeneration = ++loadGeneration" " val renderPdfName = pdfName" @@ -6707,7 +6714,8 @@ " expectedPageCount: Int = pageCount" " ) {" " val bitmap = currentBitmap ?: return" - " val uri = expectedUri ?: return" + " if (!pdfUriLoaded(expectedUri)) return" + " val uri = uriOrEmpty(expectedUri)" " setStatus(detectStartStatus(forceDetect))" " thread {" " try {" @@ -6928,7 +6936,8 @@ " }" "" " private fun showAppendDialog(rect: FloatArray, detectedIds: List<String>) {" - " val session = currentSession ?: return" + " if (sessionMissing(currentSession)) return" + " val session = ssdSessionOrEmpty(currentSession)" " val group = ssdSessionFindGroupById(session, selectedGroupId)" " if (ssdGroupMissing(group)) {" " appendMode = false" @@ -7485,10 +7494,11 @@ "" " private fun restoreLastPdf(): Boolean {" " val prefs = getPreferences(MODE_PRIVATE)" - " val raw = prefs.getString(PREF_LAST_PDF_URI, null) ?: return false" + " val raw = prefs.getString(PREF_LAST_PDF_URI, null)" + " if (!nullableTextPresent(raw)) return false" " val page = prefs.getInt(PREF_LAST_PAGE_INDEX, 0)" " return try {" - " loadPdf(Uri.parse(raw), Intent.FLAG_GRANT_READ_URI_PERMISSION, page, restoring = true)" + " loadPdf(Uri.parse(nullableTextOrEmpty(raw)), Intent.FLAG_GRANT_READ_URI_PERMISSION, page, restoring = true)" " true" " } catch (_: Exception) {" " false" @@ -7496,7 +7506,8 @@ " }" "" " private fun persistCurrentPdfState(includeViewport: Boolean) {" - " val uri = pdfUri ?: return" + " if (!pdfUriLoaded(pdfUri)) return" + " val uri = uriOrEmpty(pdfUri)" " val edit = getPreferences(MODE_PRIVATE).edit()" " .putString(PREF_LAST_PDF_URI, uri.toString())" " .putString(PREF_LAST_PDF_NAME, pdfName)"