Skip to content

Commit

Permalink
Enable backend deck list code for v2 scheduler
Browse files Browse the repository at this point in the history
This requires david-allison/anki#2 to be merged
into a new AnkiDroid backend release before this can be used.
  • Loading branch information
dae committed Jun 11, 2022
1 parent 427e494 commit 51af3d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 7 additions & 11 deletions AnkiDroid/src/main/java/com/ichi2/libanki/sched/SchedV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,19 +597,15 @@ protected int _walkingCount(@NonNull LimitMethod limFn, @NonNull CountMethod cnt
@RustCleanup("enable for v2 once backend is updated to 2.1.41+")
@RustCleanup("once both v1 and v2 are using backend, cancelListener can be removed")
public List<TreeNode<DeckDueTreeNode>> deckDueTree(@Nullable CancelListener cancelListener) {
if (AnkiDroidApp.TESTING_USE_V16_BACKEND && this instanceof Sched) {
// The 2.1.34 backend code can't be used for V2 at the moment, because
// the deck list count handling changed in 2.1.41, and test_review_limits
// expects the newer behaviour (which was already ported to AnkiDroid).
// So we only use the backend to calculate V1 at the moment.
if (AnkiDroidApp.TESTING_USE_V16_BACKEND) {
return mCol.getBackend().legacyDeckDueTree(true);
} else {
List<DeckDueTreeNode> allDecksSorted = deckDueList(cancelListener);
if (allDecksSorted == null) {
return null;
}
return _groupChildren(allDecksSorted, true);
}

List<DeckDueTreeNode> allDecksSorted = deckDueList(cancelListener);
if (allDecksSorted == null) {
return null;
}
return _groupChildren(allDecksSorted, true);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions AnkiDroid/src/test/java/com/ichi2/libanki/sched/SchedV2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,12 @@ public void test_review_limits() throws Exception {
c.flush();
}

// position 0 is default deck. Different from upstream
TreeNode<DeckDueTreeNode> tree = col.getSched().deckDueTree().get(1);
int parentIndex = 0;
if (!AnkiDroidApp.TESTING_USE_V16_BACKEND) {
// position 0 is default deck. Different from upstream
parentIndex = 1;
}
TreeNode<DeckDueTreeNode> tree = col.getSched().deckDueTree().get(parentIndex);
// (('parent', 1514457677462, 5, 0, 0, (('child', 1514457677463, 5, 0, 0, ()),)))
assertEquals("parent", tree.getValue().getFullDeckName());
assertEquals(5, tree.getValue().getRevCount()); // paren, tree.review_count)t
Expand All @@ -837,7 +841,7 @@ public void test_review_limits() throws Exception {
col.getSched().answerCard(c, BUTTON_THREE);
assertEquals(new Counts(0, 0, 9), col.getSched().counts());

tree = col.getSched().deckDueTree().get(1);
tree = col.getSched().deckDueTree().get(parentIndex);
assertEquals(4, tree.getValue().getRevCount());
assertEquals(9, tree.getChildren().get(0).getValue().getRevCount());
}
Expand Down

0 comments on commit 51af3d8

Please sign in to comment.