mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-19 19:42:17 +02:00
Implement deckDueTree() backend method
Adds a complete implementation(+ supporting method) that follows the desktop code. Seea179da3827/pylib/anki/scheduler/base.py (L69-L81)
Seea179da3827/pylib/anki/decks.py (L188-L198)
Note that there was already a deckDueTree method defined in the Scheduler class which didn't take any parameters and returned a DeckNode. Ideally the two methods would be combined into one, this was not done here because the full implementation returns a nullable DeckNodeTree and the multiple call sites using the parameterless method would require lots of changes.
This commit is contained in:
parent
bd28bf2f22
commit
e009291ea4
@ -34,6 +34,7 @@ import anki.deck_config.UpdateDeckConfigsRequest
|
||||
import anki.decks.DeckTreeNode
|
||||
import anki.decks.FilteredDeckForUpdate
|
||||
import anki.decks.SetDeckCollapsedRequest
|
||||
import anki.decks.deck
|
||||
import com.google.protobuf.kotlin.toByteStringUtf8
|
||||
import com.ichi2.annotations.NeedsTest
|
||||
import com.ichi2.libanki.backend.BackendUtils
|
||||
@ -198,6 +199,16 @@ class Decks(private val col: Collection) {
|
||||
TODO()
|
||||
}
|
||||
|
||||
@LibAnkiAlias("find_deck_in_tree")
|
||||
fun findDeckInTree(node: DeckTreeNode, deckId: DeckId): DeckTreeNode? {
|
||||
if (node.deckId == deckId) return node
|
||||
for (child in node.childrenList) {
|
||||
val foundNode = findDeckInTree(child, deckId)
|
||||
if (foundNode != null) return foundNode
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@RustCleanup("implement and make public")
|
||||
@Suppress("unused")
|
||||
/** "All decks. Expensive; prefer [allNamesAndIds] */
|
||||
|
@ -25,6 +25,7 @@ import anki.collection.OpChangesWithCount
|
||||
import anki.config.ConfigKey
|
||||
import anki.config.OptionalStringConfigKey
|
||||
import anki.config.optionalStringConfigKey
|
||||
import anki.decks.DeckTreeNode
|
||||
import anki.frontend.SchedulingStatesWithContext
|
||||
import anki.i18n.FormatTimespanRequest
|
||||
import anki.scheduler.BuryOrSuspendCardsRequest
|
||||
@ -451,6 +452,21 @@ open class Scheduler(val col: Collection) {
|
||||
return deckTree(true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a tree of decks with counts. If [deckId] is provided, only the according subtree is
|
||||
* returned.
|
||||
*
|
||||
* // TODO look into combining this method with parameterless deckDueTree
|
||||
*/
|
||||
@LibAnkiAlias("deck_due_tree")
|
||||
fun deckDueTree(deckId: DeckId? = null): DeckTreeNode? {
|
||||
val tree = col.backend.deckTree(now = time.intTime())
|
||||
if (deckId != null) {
|
||||
return col.decks.findDeckInTree(tree, deckId)
|
||||
}
|
||||
return tree
|
||||
}
|
||||
|
||||
fun deckTree(includeCounts: Boolean): DeckNode {
|
||||
return DeckNode(col.backend.deckTree(now = if (includeCounts) time.intTime() else 0), "")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user