Move SSD activity PDF load state to typed Kotlin
ober
47f3dcf5be777765b1d719f32389305c76154485
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -4651,6 +4651,10 @@ mainActivityStartAppendInteraction mainActivityStartSsdAreaInteraction mainActivityShowBitmapAndClearSession + mainActivitySetReopenSsdBrowserOnResume + mainActivitySetPageIndex mainActivitySetPdfIdentity + mainActivitySetLoadedPdfState + mainActivityAdvanceLoadGeneration ssdBrowserResumeReady focusChangeShouldShowDropdown dialogReadyToShowDropdown focusedDialogReadyToShowDropdown permissionResultGranted downloadAccessBeforeRuntimePermissions @@ -4786,6 +4790,34 @@ (activity : MainActivity) (enabled : Bool)) : Unit (kotlin-member-set ssdAreaMode)) + (extern (mainActivityReopenSsdBrowserOnResumeSet + (activity : MainActivity) + (enabled : Bool)) : Unit + (kotlin-member-set reopenSsdBrowserOnResume)) + (extern (mainActivityPdfUriSet + (activity : MainActivity) + (uri : (Nullable Uri))) : Unit + (kotlin-member-set pdfUri)) + (extern (mainActivityPdfNameSet + (activity : MainActivity) + (name : String)) : Unit + (kotlin-member-set pdfName)) + (extern (mainActivityPdfSha1Set + (activity : MainActivity) + (sha1 : String)) : Unit + (kotlin-member-set pdfSha1)) + (extern (mainActivityPageIndexSet + (activity : MainActivity) + (index : Int32)) : Unit + (kotlin-member-set pageIndex)) + (extern (mainActivityPageCountSet + (activity : MainActivity) + (count : Int32)) : Unit + (kotlin-member-set pageCount)) + (extern (mainActivityLoadGenerationSet + (activity : MainActivity) + (generation : Int32)) : Unit + (kotlin-member-set loadGeneration)) (def (normalizeFiringArc (value : String)) : String (string-uppercase (string-trim value))) (def (normalizeLabel (value : String)) : String @@ -5345,6 +5377,37 @@ (mainActivitySetAppendMode activity #f) (mainActivitySetSsdAreaMode activity #t) (reviewViewSetSelectMode view #t #f))) + (def (mainActivitySetReopenSsdBrowserOnResume + (activity : MainActivity) + (enabled : Bool)) : Unit + (mainActivityReopenSsdBrowserOnResumeSet activity enabled)) + (def (mainActivitySetPageIndex (activity : MainActivity) + (index : Int32)) : Unit + (mainActivityPageIndexSet activity index)) + (def (mainActivitySetPdfIdentity (activity : MainActivity) + (uri : Uri) + (name : String)) : Unit + (begin + (mainActivityPdfUriSet activity (nullable-some uri)) + (mainActivityPdfNameSet activity name))) + (def (mainActivitySetLoadedPdfState + (activity : MainActivity) + (sha1 : String) + (count : Int32) + (initialPageIndex : Int32)) : Unit + (begin + (mainActivityPdfSha1Set activity sha1) + (mainActivityPageCountSet activity count) + (mainActivityPageIndexSet + activity + (clampPageIndex initialPageIndex count)))) + (def (mainActivityAdvanceLoadGeneration + (activity : MainActivity) + (current : Int32)) : Int32 + (let ((next (+ current (int32 1)))) + (begin + (mainActivityLoadGenerationSet activity next) + next))) (def (shouldCaptureViewport (includeViewport : Bool)) : Bool includeViewport) (def (viewportForSave (view : SsdReviewView) @@ -6790,18 +6853,18 @@ " private lateinit var reviewView: SsdReviewView" " private lateinit var status: TextView" "" - " private var pdfUri: Uri? = null" - " private var pdfName: String = \"\"" - " private var pdfSha1: String = \"\"" - " private var pageIndex: Int = 0" - " private var pageCount: Int = 0" + " internal var pdfUri: Uri? = null" + " internal var pdfName: String = \"\"" + " internal var pdfSha1: String = \"\"" + " internal var pageIndex: Int = 0" + " internal var pageCount: Int = 0" " internal var currentBitmap: Bitmap? = null" " internal var currentSession: SsdSession? = null" " internal var selectedGroupId: String? = null" " internal var appendMode: Boolean = false" " internal var ssdAreaMode: Boolean = false" - " private var reopenSsdBrowserOnResume: Boolean = false" - " @Volatile private var loadGeneration: Int = 0" + " internal var reopenSsdBrowserOnResume: Boolean = false" + " @Volatile internal var loadGeneration: Int = 0" " private val boxTypeDisplays: List<String> by lazy { boxTypeDisplays(BoxTypes.load(this)) }" " private val firingArcDisplays = listOf(" " \"FA\"," @@ -6843,7 +6906,7 @@ " override fun onResume() {" " super.onResume()" " if (ssdBrowserResumeReady(reopenSsdBrowserOnResume, hasDirectDownloadAccess())) {" - " reopenSsdBrowserOnResume = false" + " mainActivitySetReopenSsdBrowserOnResume(this, false)" " openPdf()" " }" " }" @@ -7083,7 +7146,7 @@ " }" "" " private fun requestDownloadAccess() {" - " reopenSsdBrowserOnResume = true" + " mainActivitySetReopenSsdBrowserOnResume(this, true)" " if (sdkAtLeast(Build.VERSION.SDK_INT, Build.VERSION_CODES.R)) {" " val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION).apply {" " data = Uri.parse(packageUriText(packageName))" @@ -7114,7 +7177,7 @@ "" " private fun changePage(delta: Int) {" " if (pageNavigationBlockedForUri(pdfUri, pageCount)) return" - " pageIndex = shiftPageIndex(pageIndex, pageCount, delta)" + " mainActivitySetPageIndex(this, shiftPageIndex(pageIndex, pageCount, delta))" " persistCurrentPdfState(includeViewport = false)" " renderCurrentPage()" " }" @@ -7166,7 +7229,7 @@ " }" "" " private fun rotatePage() {" - " loadGeneration += 1" + " mainActivityAdvanceLoadGeneration(this, loadGeneration)" " reviewView.rotateClockwise()" " val session = currentSession" " setStatus(rotatedPageStatus(session))" @@ -7186,7 +7249,7 @@ " .setPositiveButton(\"Load\") { _, _ ->" " val page = dialogPageNumberText(input.text.toString(), pageCount)" " if (!nullablePageNumberPresent(page)) return@setPositiveButton" - " pageIndex = nullablePageNumberOrOne(page) - 1" + " mainActivitySetPageIndex(this, nullablePageNumberOrOne(page) - 1)" " renderCurrentPage()" " }" " .show()" @@ -7273,7 +7336,7 @@ " if (!pdfUriLoaded(pdfUri)) return" " val uri = uriOrEmpty(pdfUri)" " val renderPageIndex = pageIndex" - " val renderGeneration = ++loadGeneration" + " val renderGeneration = mainActivityAdvanceLoadGeneration(this, loadGeneration)" " val renderPdfName = pdfName" " val renderPdfSha1 = pdfSha1" " val renderPageCount = pageCount" @@ -7826,7 +7889,7 @@ " ) {" " super.onRequestPermissionsResult(requestCode, permissions, grantResults)" " if (requestIsReadStorage(requestCode, REQ_READ_STORAGE)) {" - " reopenSsdBrowserOnResume = false" + " mainActivitySetReopenSsdBrowserOnResume(this, false)" " openPdf()" " }" " }" @@ -8043,8 +8106,7 @@ " contentResolver.takePersistableUriPermission(uri, flags and Intent.FLAG_GRANT_READ_URI_PERMISSION)" " } catch (_: Exception) {" " }" - " pdfUri = uri" - " pdfName = displayName(uri)" + " mainActivitySetPdfIdentity(this, uri, displayName(uri))" " getPreferences(MODE_PRIVATE)" " .edit()" " .putString(PREF_LAST_PDF_URI, uri.toString())" @@ -8056,9 +8118,7 @@ " val hash = if (inputStreamPresent(pdfInput)) checkNotNull(pdfInput).use { sha1Hex(it) } else \"\"" " val count = pdfPageCount(uri)" " runOnUiThread {" - " pdfSha1 = hash" - " pageCount = count" - " pageIndex = clampPageIndex(initialPageIndex, count)" + " mainActivitySetLoadedPdfState(this, hash, count, initialPageIndex)" " if (shouldPersistLoadedPdfState(restoring)) persistCurrentPdfState(includeViewport = false)" " setStatus(loadedPdfStatus(pdfName, pageCount))" " renderCurrentPage()"