Move SSD truth store calls to typed Kotlin
ober
36fc11d5d8d72e63b16c0045f7ab94693985d76a
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -4589,6 +4589,8 @@ (typed-kotlin-file "com/sfb/ssdreview/UiTextHelpers.kt" (kotlin-imports (java io File) + (java io InputStream) + (java io OutputStream) (android graphics Bitmap) (android content Intent) (android database Cursor) @@ -4696,6 +4698,13 @@ truthStoreAppendGroupAppended truthStoreAppendGroupEdited truthStoreAppendGroupDeleted + truthStoreStorageSummary + truthStoreSaveSnapshot + truthStorePullRemoteDumpCount + truthStorePushRemoteDumpCount + truthStoreExportZipArchive + truthStoreImportZipArchive + truthStoreSyncTreeCounts ssdBrowserResumeReady focusChangeShouldShowDropdown dialogReadyToShowDropdown focusedDialogReadyToShowDropdown permissionResultGranted downloadAccessBeforeRuntimePermissions @@ -4746,6 +4755,8 @@ (type Bitmap) (type Char) (type File) + (type InputStream) + (type OutputStream) (type Cursor) (type Intent) (type Uri) @@ -4805,6 +4816,28 @@ (session : SsdSession) (details : JSONObject)) : Unit (kotlin-member-call appendEvent)) + (extern (truthStoreStorageSummaryRaw (store : TruthStore)) : String + (kotlin-member-call storageSummary)) + (extern (truthStoreSaveTruthSnapshot + (store : TruthStore) + (truth : JSONObject)) : File + (kotlin-member-call saveTruthSnapshot)) + (extern (truthStorePullRemoteDumpRaw (store : TruthStore)) : Int32 + (kotlin-member-call pullRemoteDump)) + (extern (truthStorePushRemoteDumpRaw (store : TruthStore)) : Int32 + (kotlin-member-call pushRemoteDump)) + (extern (truthStoreExportZipRaw + (store : TruthStore) + (output : OutputStream)) : Unit + (kotlin-member-call exportZip)) + (extern (truthStoreImportZipRaw + (store : TruthStore) + (input : InputStream)) : Int32 + (kotlin-member-call importZip)) + (extern (truthStoreSyncTreeRaw + (store : TruthStore) + (treeUri : Uri)) : (Pair Int32 Int32) + (kotlin-member-call syncTree)) (extern (reviewViewCaptureViewport (view : SsdReviewView)) : (Nullable ViewportState) (kotlin-member-call captureViewport)) (extern (reviewViewRestoreViewportRaw @@ -5760,6 +5793,30 @@ (store : TruthStore) (session : SsdSession)) : Unit (truthStoreAppendEvent store "group_deleted" session)) + (def (truthStoreStorageSummary (store : TruthStore)) : String + (truthStoreStorageSummaryRaw store)) + (def (truthStoreSaveSnapshot + (store : TruthStore) + (truth : JSONObject)) : Unit + (begin + (truthStoreSaveTruthSnapshot store truth) + (begin))) + (def (truthStorePullRemoteDumpCount (store : TruthStore)) : Int32 + (truthStorePullRemoteDumpRaw store)) + (def (truthStorePushRemoteDumpCount (store : TruthStore)) : Int32 + (truthStorePushRemoteDumpRaw store)) + (def (truthStoreExportZipArchive + (store : TruthStore) + (output : OutputStream)) : Unit + (truthStoreExportZipRaw store output)) + (def (truthStoreImportZipArchive + (store : TruthStore) + (input : InputStream)) : Int32 + (truthStoreImportZipRaw store input)) + (def (truthStoreSyncTreeCounts + (store : TruthStore) + (treeUri : Uri)) : (Pair Int32 Int32) + (truthStoreSyncTreeRaw store treeUri)) (def (shouldCaptureViewport (includeViewport : Bool)) : Bool includeViewport) (def (viewportForSave (view : SsdReviewView) @@ -7254,12 +7311,12 @@ " logClientEvent(\"ssd-app-start\")" " mainActivitySetTruthStore(this, TruthStore(this))" " setContentView(buildUi())" - " setStatus(startupStatus(truthStore.storageSummary()))" + " setStatus(startupStatus(truthStoreStorageSummary(truthStore)))" " restoreLastPdf()" " truthStore.seedBundledTruthAsync { imported ->" " if (positiveCount(imported)) {" " runOnUiThread {" - " setStatus(truthSeedMergedStatus(imported, truthStore.storageSummary()))" + " setStatus(truthSeedMergedStatus(imported, truthStoreStorageSummary(truthStore)))" " if (pdfUriLoaded(pdfUri)) renderCurrentPage()" " }" " }" @@ -7969,7 +8026,7 @@ " setStatus(savingStatus)" " thread(name = \"sfb-truth-save\") {" " try {" - " truthStore.saveTruthSnapshot(truth)" + " truthStoreSaveSnapshot(truthStore, truth)" " runOnUiThread {" " restoreViewportAfterLayout(viewport)" " setStatus(savedStatus)" @@ -8101,7 +8158,7 @@ " saveSessionAsync(" " session," " saveTruthSavingStatus()," - " saveTruthSavedStatus(truthStore.storageSummary())" + " saveTruthSavedStatus(truthStoreStorageSummary(truthStore))" " )" " }" "" @@ -8155,10 +8212,10 @@ " setStatus(pullTruthStatus())" " thread {" " try {" - " val imported = truthStore.pullRemoteDump()" + " val imported = truthStorePullRemoteDumpCount(truthStore)" " runOnUiThread {" " Toast.makeText(this, \"Truth pull complete\", Toast.LENGTH_SHORT).show()" - " setStatus(pulledTruthStatus(imported, truthStore.storageSummary()))" + " setStatus(pulledTruthStatus(imported, truthStoreStorageSummary(truthStore)))" " if (pdfUriLoaded(pdfUri)) renderCurrentPage()" " }" " } catch (error: Exception) {" @@ -8173,10 +8230,10 @@ " setStatus(pushTruthStatus())" " thread {" " try {" - " val imported = truthStore.pushRemoteDump()" + " val imported = truthStorePushRemoteDumpCount(truthStore)" " runOnUiThread {" " Toast.makeText(this, \"Truth push complete\", Toast.LENGTH_SHORT).show()" - " setStatus(pushedTruthStatus(imported, truthStore.storageSummary()))" + " setStatus(pushedTruthStatus(imported, truthStoreStorageSummary(truthStore)))" " }" " } catch (error: Exception) {" " runOnUiThread {" @@ -8200,7 +8257,7 @@ " val output = contentResolver.openOutputStream(uri)" " if (outputStreamPresent(output)) {" " checkNotNull(output).use {" - " truthStore.exportZip(it)" + " truthStoreExportZipArchive(truthStore, it)" " setStatus(exportedTruthZipStatus())" " }" " }" @@ -8208,8 +8265,8 @@ " val input = contentResolver.openInputStream(uri)" " if (inputStreamPresent(input)) {" " checkNotNull(input).use {" - " val count = truthStore.importZip(it)" - " setStatus(importedTruthZipStatus(count, truthStore.storageSummary()))" + " val count = truthStoreImportZipArchive(truthStore, it)" + " setStatus(importedTruthZipStatus(count, truthStoreStorageSummary(truthStore)))" " }" " }" " } else if (requestIsSyncTree(requestCode, REQ_SYNC_TREE)) {" @@ -8425,10 +8482,10 @@ " setStatus(syncTruthFolderStatus())" " thread {" " try {" - " val (imported, exported) = truthStore.syncTree(uri)" + " val (imported, exported) = truthStoreSyncTreeCounts(truthStore, uri)" " runOnUiThread {" " Toast.makeText(this, \"Truth sync complete\", Toast.LENGTH_SHORT).show()" - " setStatus(syncedTruthFolderStatus(imported, exported, truthStore.storageSummary()))" + " setStatus(syncedTruthFolderStatus(imported, exported, truthStoreStorageSummary(truthStore)))" " }" " } catch (error: Exception) {" " runOnUiThread { setStatus(folderSyncFailedStatus(error.message)) }"