Skip to content

Commit 1a776cf

Browse files
david-allisonBrayanDSO
authored andcommitted
fix(deck-options): display 'optimize' progress in UI
`latestProgress` should not be a blocking call So this now appears in the Svelte page Issue 18006 Fixes 17862
1 parent 51dfba6 commit 1a776cf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/pages/PostRequestHandler.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.annotation.VisibleForTesting
2222
import androidx.fragment.app.FragmentActivity
2323
import androidx.lifecycle.lifecycleScope
2424
import anki.collection.OpChanges
25+
import com.ichi2.anki.CollectionManager
2526
import com.ichi2.anki.CollectionManager.withCol
2627
import com.ichi2.anki.NoteEditor
2728
import com.ichi2.anki.importAnkiPackageUndoable
@@ -36,6 +37,7 @@ import com.ichi2.libanki.getDeckNamesRaw
3637
import com.ichi2.libanki.getFieldNamesRaw
3738
import com.ichi2.libanki.getImportAnkiPackagePresetsRaw
3839
import com.ichi2.libanki.getNotetypeNamesRaw
40+
import com.ichi2.libanki.sched.computeFsrsParamsRaw
3941
import com.ichi2.libanki.sched.computeOptimalRetentionRaw
4042
import com.ichi2.libanki.sched.evaluateParamsRaw
4143
import com.ichi2.libanki.sched.simulateFsrsReviewRaw
@@ -45,8 +47,10 @@ import com.ichi2.libanki.stats.graphsRaw
4547
import com.ichi2.libanki.stats.setGraphPreferencesRaw
4648
import com.ichi2.libanki.undoableOp
4749
import kotlinx.coroutines.Deferred
50+
import kotlinx.coroutines.Dispatchers
4851
import kotlinx.coroutines.async
4952
import kotlinx.coroutines.delay
53+
import kotlinx.coroutines.withContext
5054
import timber.log.Timber
5155

5256
interface PostRequestHandler {
@@ -77,12 +81,12 @@ val collectionMethods =
7781
"cardStats" to { bytes -> cardStatsRaw(bytes) },
7882
"getDeckConfigsForUpdate" to { bytes -> getDeckConfigsForUpdateRaw(bytes) },
7983
"computeOptimalRetention" to { bytes -> computeOptimalRetentionRaw(bytes) },
84+
"computeFsrsParams" to { bytes -> computeFsrsParamsRaw(bytes) },
8085
"evaluateParams" to { bytes -> evaluateParamsRaw(bytes) },
8186
"simulateFsrsReview" to { bytes -> simulateFsrsReviewRaw(bytes) },
8287
"getImageForOcclusion" to { bytes -> getImageForOcclusionRaw(bytes) },
8388
"getImageOcclusionNote" to { bytes -> getImageOcclusionNoteRaw(bytes) },
8489
"setWantsAbort" to { bytes -> setWantsAbortRaw(bytes) },
85-
"latestProgress" to { bytes -> latestProgressRaw(bytes) },
8690
"getSchedulingStatesWithContext" to { bytes -> getSchedulingStatesWithContextRaw(bytes) },
8791
"setSchedulingStates" to { bytes -> setSchedulingStatesRaw(bytes) },
8892
"getChangeNotetypeInfo" to { bytes -> getChangeNotetypeInfoRaw(bytes) },
@@ -110,6 +114,13 @@ val uiMethods =
110114
hashMapOf<String, UIBackendInterface>(
111115
"searchInBrowser" to { bytes -> lifecycleScope.async { searchInBrowser(bytes) } },
112116
"updateDeckConfigs" to { bytes -> lifecycleScope.async { updateDeckConfigsRaw(bytes) } },
117+
"latestProgress" to { bytes ->
118+
lifecycleScope.async {
119+
withContext(Dispatchers.IO) {
120+
CollectionManager.getBackend().latestProgressRaw(bytes)
121+
}
122+
}
123+
},
113124
"importCsv" to { bytes -> lifecycleScope.async { importCsvRaw(bytes) } },
114125
"importAnkiPackage" to { bytes -> lifecycleScope.async { importAnkiPackageUndoable(bytes) } },
115126
"addImageOcclusionNote" to { bytes ->
@@ -122,7 +133,6 @@ val uiMethods =
122133
withCol { updateImageOcclusionNoteRaw(bytes) }
123134
}
124135
},
125-
"computeFsrsParams" to { bytes -> lifecycleScope.async { computeFsrsParams(bytes) } },
126136
"deckOptionsReady" to { bytes -> lifecycleScope.async { deckOptionsReady(bytes) } },
127137
"deckOptionsRequireClose" to { bytes -> lifecycleScope.async { deckOptionsRequireClose(bytes) } },
128138
)

0 commit comments

Comments
 (0)