Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions AnkiDroid/src/main/java/com/ichi2/anki/pages/DeckOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import com.ichi2.anki.utils.openUrl
import com.ichi2.anki.withProgress
import com.ichi2.annotations.NeedsTest
import com.ichi2.libanki.DeckId
import com.ichi2.libanki.sched.computeFsrsParamsRaw
import com.ichi2.libanki.undoableOp
import com.ichi2.libanki.updateDeckConfigsRaw
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -263,17 +262,6 @@ suspend fun FragmentActivity.updateDeckConfigsRaw(input: ByteArray): ByteArray {
return output
}

suspend fun FragmentActivity.computeFsrsParams(input: ByteArray): ByteArray =
withContext(Dispatchers.Main) {
withProgress(extractProgress = {
text = this.toUpdatingCardsString() ?: getString(R.string.dialog_processing)
}) {
withContext(Dispatchers.IO) {
withCol { computeFsrsParamsRaw(input) }
}
}
}

/**
* ```
* Optimizing preset 1/20
Expand Down Expand Up @@ -301,24 +289,6 @@ private fun ProgressContext.toOptimizingPresetString(): String? {
return label + "\n" + reviewsLabel
}

/**
* ```
* Updating Cards: 45/23687
* ```
*
* @return the above string, or `null` if [ProgressContext] has no
* [compute parameters][Progress.hasComputeParams]
*/
private fun ProgressContext.toUpdatingCardsString(): String? {
if (!progress.hasComputeParams()) return null

val params = progress.computeParams
return TR.deckConfigUpdatingCards(
currentCardsCount = params.current,
totalCardsCount = params.total,
)
}

private fun FragmentActivity.requireDeckOptionsFragment(): DeckOptions {
require(this is SingleFragmentActivity) { "activity must be SingleFragmentActivity" }
return requireNotNull(this.fragment as? DeckOptions?) { "fragment must be DeckOptions" }
Expand Down
14 changes: 12 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/pages/PostRequestHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.annotation.VisibleForTesting
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import anki.collection.OpChanges
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.NoteEditor
import com.ichi2.anki.importAnkiPackageUndoable
Expand All @@ -36,6 +37,7 @@ import com.ichi2.libanki.getDeckNamesRaw
import com.ichi2.libanki.getFieldNamesRaw
import com.ichi2.libanki.getImportAnkiPackagePresetsRaw
import com.ichi2.libanki.getNotetypeNamesRaw
import com.ichi2.libanki.sched.computeFsrsParamsRaw
import com.ichi2.libanki.sched.computeOptimalRetentionRaw
import com.ichi2.libanki.sched.evaluateParamsRaw
import com.ichi2.libanki.sched.simulateFsrsReviewRaw
Expand All @@ -45,8 +47,10 @@ import com.ichi2.libanki.stats.graphsRaw
import com.ichi2.libanki.stats.setGraphPreferencesRaw
import com.ichi2.libanki.undoableOp
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
import timber.log.Timber

interface PostRequestHandler {
Expand Down Expand Up @@ -77,12 +81,12 @@ val collectionMethods =
"cardStats" to { bytes -> cardStatsRaw(bytes) },
"getDeckConfigsForUpdate" to { bytes -> getDeckConfigsForUpdateRaw(bytes) },
"computeOptimalRetention" to { bytes -> computeOptimalRetentionRaw(bytes) },
"computeFsrsParams" to { bytes -> computeFsrsParamsRaw(bytes) },
"evaluateParams" to { bytes -> evaluateParamsRaw(bytes) },
"simulateFsrsReview" to { bytes -> simulateFsrsReviewRaw(bytes) },
"getImageForOcclusion" to { bytes -> getImageForOcclusionRaw(bytes) },
"getImageOcclusionNote" to { bytes -> getImageOcclusionNoteRaw(bytes) },
"setWantsAbort" to { bytes -> setWantsAbortRaw(bytes) },
"latestProgress" to { bytes -> latestProgressRaw(bytes) },
"getSchedulingStatesWithContext" to { bytes -> getSchedulingStatesWithContextRaw(bytes) },
"setSchedulingStates" to { bytes -> setSchedulingStatesRaw(bytes) },
"getChangeNotetypeInfo" to { bytes -> getChangeNotetypeInfoRaw(bytes) },
Expand Down Expand Up @@ -110,6 +114,13 @@ val uiMethods =
hashMapOf<String, UIBackendInterface>(
"searchInBrowser" to { bytes -> lifecycleScope.async { searchInBrowser(bytes) } },
"updateDeckConfigs" to { bytes -> lifecycleScope.async { updateDeckConfigsRaw(bytes) } },
"latestProgress" to { bytes ->
lifecycleScope.async {
withContext(Dispatchers.IO) {
CollectionManager.getBackend().latestProgressRaw(bytes)
}
}
},
"importCsv" to { bytes -> lifecycleScope.async { importCsvRaw(bytes) } },
"importAnkiPackage" to { bytes -> lifecycleScope.async { importAnkiPackageUndoable(bytes) } },
"addImageOcclusionNote" to { bytes ->
Expand All @@ -122,7 +133,6 @@ val uiMethods =
withCol { updateImageOcclusionNoteRaw(bytes) }
}
},
"computeFsrsParams" to { bytes -> lifecycleScope.async { computeFsrsParams(bytes) } },
"deckOptionsReady" to { bytes -> lifecycleScope.async { deckOptionsReady(bytes) } },
"deckOptionsRequireClose" to { bytes -> lifecycleScope.async { deckOptionsRequireClose(bytes) } },
)
Expand Down