diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/AbstractDeckTreeNode.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/AbstractDeckTreeNode.kt index a448ce44080a..3237e7fe1da9 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/AbstractDeckTreeNode.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/AbstractDeckTreeNode.kt @@ -32,7 +32,6 @@ import java.util.* * [processChildren] should be called if the children of this node are modified. */ abstract class AbstractDeckTreeNode( - val col: Collection, /** * @return The full deck name, e.g. "A::B::C" */ @@ -68,7 +67,7 @@ abstract class AbstractDeckTreeNode( ) } - abstract fun processChildren(children: List, addRev: Boolean) + abstract fun processChildren(col: Collection, children: List, addRev: Boolean) override fun toString(): String { val buf = StringBuffer() diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckDueTreeNode.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckDueTreeNode.kt index ac519b58b071..c3d5d445f976 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckDueTreeNode.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckDueTreeNode.kt @@ -34,7 +34,7 @@ import kotlin.math.min */ @KotlinCleanup("maybe possible to remove gettres for revCount/lrnCount") @KotlinCleanup("rename name -> fullDeckName") -class DeckDueTreeNode(col: Collection, name: String, did: Long, override var revCount: Int, override var lrnCount: Int, override var newCount: Int) : AbstractDeckTreeNode(col, name, did) { +class DeckDueTreeNode(name: String, did: Long, override var revCount: Int, override var lrnCount: Int, override var newCount: Int) : AbstractDeckTreeNode(name, did) { override fun toString(): String { return String.format( Locale.US, "%s, %d, %d, %d, %d", @@ -50,7 +50,7 @@ class DeckDueTreeNode(col: Collection, name: String, did: Long, override var rev newCount = max(0, min(newCount, limit)) } - override fun processChildren(children: List, addRev: Boolean) { + override fun processChildren(col: Collection, children: List, addRev: Boolean) { // tally up children counts for (ch in children) { lrnCount += ch.lrnCount diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckTreeNode.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckTreeNode.kt index ef4f6275e607..82194c2cbbc8 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckTreeNode.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/DeckTreeNode.kt @@ -16,11 +16,11 @@ package com.ichi2.libanki.sched import com.ichi2.libanki.Collection -import com.ichi2.utils.KotlinCleanup +import net.ankiweb.rsdroid.RustCleanup -@KotlinCleanup("confusing nullability for col, verify real nullability after code related to scheduling is fully migrated to kotlin") -class DeckTreeNode(col: Collection, name: String, did: Long) : AbstractDeckTreeNode(col, name, did) { - override fun processChildren(children: List, addRev: Boolean) { +@RustCleanup("processChildren() can be removed after migrating to backend implementation") +class DeckTreeNode(name: String, did: Long) : AbstractDeckTreeNode(name, did) { + override fun processChildren(col: Collection, children: List, addRev: Boolean) { // intentionally blank } } diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.java b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.java index 2716d5983a34..d7749e166ce2 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.java +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.java @@ -242,7 +242,7 @@ private void unburyCardsForDeck(@NonNull List allDecks) { // reviews int rev = _revForDeck(deck.getLong("id"), rlim); // save to list - deckNodes.add(new DeckDueTreeNode(getCol(), deck.getString("name"), deck.getLong("id"), rev, lrn, _new)); + deckNodes.add(new DeckDueTreeNode(deck.getString("name"), deck.getLong("id"), rev, lrn, _new)); // add deck as a parent lims.put(Decks.normalizeName(deck.getString("name")), new Integer[]{nlim, rlim}); } diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/SchedV2.java b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/SchedV2.java index e6ce0cc517c4..0b6e3cae7a60 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/SchedV2.java +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/SchedV2.java @@ -561,7 +561,7 @@ protected int _walkingCount(@NonNull LimitMethod limFn, @NonNull CountMethod cnt int rlim = _deckRevLimitSingle(deck, plim, false); int rev = _revForDeck(deck.getLong("id"), rlim, childMap); // save to list - deckNodes.add(new DeckDueTreeNode(getCol(), deck.getString("name"), deck.getLong("id"), rev, lrn, _new)); + deckNodes.add(new DeckDueTreeNode(deck.getString("name"), deck.getLong("id"), rev, lrn, _new)); // add deck as a parent lims.put(Decks.normalizeName(deck.getString("name")), new Integer[]{nlim, rlim}); } @@ -580,7 +580,7 @@ protected int _walkingCount(@NonNull LimitMethod limFn, @NonNull CountMethod cnt // Similar to deckDueList ArrayList allDecksSorted = new ArrayList<>(); for (JSONObject deck : getCol().getDecks().allSorted()) { - DeckTreeNode g = new DeckTreeNode(getCol(), deck.getString("name"), deck.getLong("id")); + DeckTreeNode g = new DeckTreeNode(deck.getString("name"), deck.getLong("id")); allDecksSorted.add(g); } // End of the similar part. @@ -666,7 +666,7 @@ public List> deckDueTree(@Nullable CancelListener canc TreeNode toAdd = new TreeNode<>(child); toAdd.getChildren().addAll(childrenNode); List childValues = childrenNode.stream().map(TreeNode::getValue).collect(Collectors.toList()); - child.processChildren(childValues, "std".equals(getName())); + child.processChildren(mCol, childValues, "std".equals(getName())); sortedChildren.add(toAdd); } diff --git a/AnkiDroid/src/test/java/com/ichi2/libanki/sched/SchedV2Test.java b/AnkiDroid/src/test/java/com/ichi2/libanki/sched/SchedV2Test.java index 75d40748bdb2..e16361654a04 100644 --- a/AnkiDroid/src/test/java/com/ichi2/libanki/sched/SchedV2Test.java +++ b/AnkiDroid/src/test/java/com/ichi2/libanki/sched/SchedV2Test.java @@ -112,16 +112,16 @@ protected static List> expectedTree(Collection col, bo // These matched the previous Java data // These may want to be changed back List> expected = new ArrayList<>(); - DeckDueTreeNode caz = new DeckDueTreeNode(col, "cmxieunwoogyxsctnjmv::abcdefgh::ZYXW", 1596783600480L, 0, 0, 0); - DeckDueTreeNode ca = new DeckDueTreeNode(col, "cmxieunwoogyxsctnjmv::abcdefgh", 1596783600460L, 0, 0, 0); - DeckDueTreeNode ci = new DeckDueTreeNode(col, "cmxieunwoogyxsctnjmv::INSBGDS", 1596783600500L, 0, 0, 0); - DeckDueTreeNode c = new DeckDueTreeNode(col, "cmxieunwoogyxsctnjmv", 1596783600440L, 0, 0, 0); - DeckDueTreeNode defaul = new DeckDueTreeNode(col, "Default", 1, 0, 0, 0); - DeckDueTreeNode s = new DeckDueTreeNode(col, "scxipjiyozczaaczoawo", 1596783600420L, 0, 0, 0); - DeckDueTreeNode f = new DeckDueTreeNode(col, "blank::foobar", 1596783600540L, 0, 0, 0); - DeckDueTreeNode b = new DeckDueTreeNode(col, "blank", 1596783600520L, 0, 0, 0); - DeckDueTreeNode aBlank = new DeckDueTreeNode(col, "A::blank", 1596783600580L, 0, 0, 0); - DeckDueTreeNode a = new DeckDueTreeNode(col, "A", 1596783600560L, 0, 0, 0); + DeckDueTreeNode caz = new DeckDueTreeNode("cmxieunwoogyxsctnjmv::abcdefgh::ZYXW", 1596783600480L, 0, 0, 0); + DeckDueTreeNode ca = new DeckDueTreeNode("cmxieunwoogyxsctnjmv::abcdefgh", 1596783600460L, 0, 0, 0); + DeckDueTreeNode ci = new DeckDueTreeNode("cmxieunwoogyxsctnjmv::INSBGDS", 1596783600500L, 0, 0, 0); + DeckDueTreeNode c = new DeckDueTreeNode("cmxieunwoogyxsctnjmv", 1596783600440L, 0, 0, 0); + DeckDueTreeNode defaul = new DeckDueTreeNode("Default", 1, 0, 0, 0); + DeckDueTreeNode s = new DeckDueTreeNode("scxipjiyozczaaczoawo", 1596783600420L, 0, 0, 0); + DeckDueTreeNode f = new DeckDueTreeNode("blank::foobar", 1596783600540L, 0, 0, 0); + DeckDueTreeNode b = new DeckDueTreeNode("blank", 1596783600520L, 0, 0, 0); + DeckDueTreeNode aBlank = new DeckDueTreeNode("A::blank", 1596783600580L, 0, 0, 0); + DeckDueTreeNode a = new DeckDueTreeNode("A", 1596783600560L, 0, 0, 0); TreeNode cazNode = new TreeNode<>(caz); @@ -135,7 +135,7 @@ protected static List> expectedTree(Collection col, bo // add "caz" to "ca" caNode.getChildren().add(cazNode); - caNode.getValue().processChildren(Collections.singletonList(cazNode.getValue()), addRev); + caNode.getValue().processChildren(col, Collections.singletonList(cazNode.getValue()), addRev); // add "ca" and "ci" to "c" cNode.getChildren().add(caNode); @@ -143,15 +143,15 @@ protected static List> expectedTree(Collection col, bo ArrayList cChildren = new ArrayList<>(); cChildren.add(caNode.getValue()); cChildren.add(ciNode.getValue()); - cNode.getValue().processChildren(cChildren, addRev); + cNode.getValue().processChildren(col, cChildren, addRev); // add "f" to "b" bNode.getChildren().add(fNode); - bNode.getValue().processChildren(Collections.singletonList(fNode.getValue()), addRev); + bNode.getValue().processChildren(col, Collections.singletonList(fNode.getValue()), addRev); // add "A::" to "A" aNode.getChildren().add(aBlankNode); - aNode.getValue().processChildren(Collections.singletonList(aBlankNode.getValue()), addRev); + aNode.getValue().processChildren(col, Collections.singletonList(aBlankNode.getValue()), addRev); expected.add(aNode); expected.add(bNode);