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 4bc262b95c2e..915bc5ff4d02 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.java +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.java @@ -204,52 +204,6 @@ private void unburyCardsForDeck(@NonNull List allDecks) { getTime().intTime(), mCol.usn()); } - /* - Deck list **************************************************************** ******************************* - */ - - - /** - * Returns [deckname, did, rev, lrn, new] - */ - @Override - protected @Nullable List deckDueList(@Nullable CancelListener cancelListener) { - _checkDay(); - mCol.getDecks().checkIntegrity(); - List allDecksSorted = mCol.getDecks().allSorted(); - HashMap lims = HashUtil.HashMapInit(allDecksSorted.size()); - ArrayList deckNodes = new ArrayList<>(allDecksSorted.size()); - for (Deck deck : allDecksSorted) { - if (isCancelled(cancelListener)) { - return null; - } - String deckName = deck.getString("name"); - String p = Decks.parent(deckName); - // new - int nlim = _deckNewLimitSingle(deck, false); - int rlim = _deckRevLimitSingle(deck, false); - if (!TextUtils.isEmpty(p)) { - Integer[] parentLims = lims.get(Decks.normalizeName(p)); - // 'temporary for diagnosis of bug #6383' - Assert.that(parentLims != null, "Deck %s is supposed to have parent %s. It has not be found.", deckName, p); - nlim = Math.min(nlim, parentLims[0]); - // review - rlim = Math.min(rlim, parentLims[1]); - } - int _new = _newForDeck(deck.getLong("id"), nlim); - // learning - int lrn = _lrnForDeck(deck.getLong("id")); - // reviews - int rev = _revForDeck(deck.getLong("id"), rlim); - // save to list - 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}); - } - return deckNodes; - } - - /* Getting the next card **************************************************** ******************************************* 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 8f70672663d8..35700b255c10 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/sched/SchedV2.java +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/sched/SchedV2.java @@ -512,62 +512,6 @@ protected int _walkingCount(@NonNull LimitMethod limFn, @NonNull CountMethod cnt return tot; } - - /* - Deck list **************************************************************** ******************************* - */ - - - /** - * Returns [deckname, did, rev, lrn, new] - * - * Return nulls when deck task is cancelled. - */ - private @NonNull List deckDueList() { - return deckDueList(null); - } - - // Overridden - /** - * Return sorted list of all decks.*/ - protected @Nullable List deckDueList(@Nullable CancelListener collectionTask) { - _checkDay(); - mCol.getDecks().checkIntegrity(); - List allDecksSorted = mCol.getDecks().allSorted(); - HashMap lims = HashUtil.HashMapInit(allDecksSorted.size()); - ArrayList deckNodes = new ArrayList<>(allDecksSorted.size()); - Decks.Node childMap = mCol.getDecks().childMap(); - for (Deck deck : allDecksSorted) { - if (isCancelled(collectionTask)) { - return null; - } - String deckName = deck.getString("name"); - String p = Decks.parent(deckName); - // new - int nlim = _deckNewLimitSingle(deck, false); - Integer plim = null; - if (!TextUtils.isEmpty(p)) { - Integer[] parentLims = lims.get(Decks.normalizeName(p)); - // 'temporary for diagnosis of bug #6383' - Assert.that(parentLims != null, "Deck %s is supposed to have parent %s. It has not be found.", deckName, p); - nlim = Math.min(nlim, parentLims[0]); - // reviews - plim = parentLims[1]; - } - int _new = _newForDeck(deck.getLong("id"), nlim); - // learning - int lrn = _lrnForDeck(deck.getLong("id")); - // reviews - int rlim = _deckRevLimitSingle(deck, plim, false); - int rev = _revForDeck(deck.getLong("id"), rlim, childMap); - // save to list - 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}); - } - return deckNodes; - } - /** Similar to deck due tree, but ignore the number of cards. It may takes a lot of time to compute the number of card, it @@ -576,19 +520,7 @@ protected int _walkingCount(@NonNull LimitMethod limFn, @NonNull CountMethod cnt @Override public @NonNull List> quickDeckDueTree() { - if (AnkiDroidApp.TESTING_USE_V16_BACKEND) { - return mCol.getBackend().legacyDeckDueTree(false); - } - - // Similar to deckDueList - ArrayList allDecksSorted = new ArrayList<>(); - for (JSONObject deck : mCol.getDecks().allSorted()) { - DeckTreeNode g = new DeckTreeNode(deck.getString("name"), deck.getLong("id")); - allDecksSorted.add(g); - } - // End of the similar part. - - return _groupChildren(allDecksSorted, false); + return mCol.getBackend().legacyDeckDueTree(false); } @@ -600,89 +532,9 @@ List> quickDeckDueTree() { @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> deckDueTree(@Nullable CancelListener cancelListener) { - if (AnkiDroidApp.TESTING_USE_V16_BACKEND) { - return mCol.getBackend().legacyDeckDueTree(true); - } else { - List allDecksSorted = deckDueList(cancelListener); - if (allDecksSorted == null) { - return null; - } - return _groupChildren(allDecksSorted, true); - } + return mCol.getBackend().legacyDeckDueTree(true); } - /** - * @return the tree with `allDecksSorted` content. - * @param allDecksSorted the set of all decks of the collection. Sorted. - * @param checkDone Whether the set of deck was checked. If false, we can't assume all decks have parents - * and that there is no duplicate. Instead, we'll ignore problems.*/ - protected @NonNull List> _groupChildren(@NonNull List allDecksSorted, boolean checkDone) { - return _groupChildren(allDecksSorted, 0, checkDone); - } - - /** - @return the tree structure of all decks from @descendants, starting - at specified depth. - - @param sortedDescendants a list of decks of dept at least depth, having all - the same first depth name elements, sorted in deck order. - @param depth The depth of the tree we are creating - @param checkDone whether the set of deck was checked. If - false, we can't assume all decks have parents and that there - is no duplicate. Instead, we'll ignore problems. - */ - protected @NonNull List> _groupChildren(@NonNull List sortedDescendants, int depth, boolean checkDone) { - List> sortedChildren = new ArrayList<>(); - // group and recurse - ListIterator it = sortedDescendants.listIterator(); - while (it.hasNext()) { - T child = it.next(); - String head = child.getDeckNameComponent(depth); - List sortedDescendantsOfChild = new ArrayList<>(); - /* Compose the "sortedChildren" node list. The sortedChildren is a - * list of all the nodes that proceed the current one that - * contain the same at depth `depth`, except for the - * current one itself. I.e., they are subdecks that stem - * from this descendant. This is our version of python's - * itertools.groupby. */ - if (!checkDone && child.getDepth() != depth) { - Deck deck = mCol.getDecks().get(child.getDid()); - Timber.d("Deck %s (%d)'s parent is missing. Ignoring for quick display.", deck.getString("name"), child.getDid()); - continue; - } - while (it.hasNext()) { - T descendantOfChild = it.next(); - if (head.equals(descendantOfChild.getDeckNameComponent(depth))) { - // Same head - add to tail of current head. - if (!checkDone && descendantOfChild.getDepth() == depth) { - Deck deck = mCol.getDecks().get(descendantOfChild.getDid()); - Timber.d("Deck %s (%d)'s is a duplicate name. Ignoring for quick display.", deck.getString("name"), descendantOfChild.getDid()); - continue; - } - sortedDescendantsOfChild.add(descendantOfChild); - } else { - // We've iterated past this head, so step back in order to use this descendant as the - // head in the next iteration of the outer loop. - it.previous(); - break; - } - } - // the childrenNode set contains direct child of `child`, but not - // any descendants of the children of `child`... - List> childrenNode = _groupChildren(sortedDescendantsOfChild, depth + 1, checkDone); - - // Add the child nodes, and process the addition - TreeNode toAdd = new TreeNode<>(child); - toAdd.getChildren().addAll(childrenNode); - List childValues = childrenNode.stream().map(TreeNode::getValue).collect(Collectors.toList()); - child.processChildren(mCol, childValues, "std".equals(getName())); - - sortedChildren.add(toAdd); - } - return sortedChildren; - } - - /* Getting the next card **************************************************** *******************************************