Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the empty regular deck check, now uses foreach to check all the… #18007

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

devyk100
Copy link

@devyk100 devyk100 commented Feb 22, 2025

Purpose / Description

Creating a deck A::B, if B subdeck is empty and parent A is empty, clicking on the parent it should show 'this deck is empty', instead of the finished deck message.

Fixes

Approach

The earlier code just checked for the following conditions:

  • If the deck clicked has subdecks (at the topmost list level only) - getNodeByDid(did).children.isEmpty()
  • If only the deck clicked has 0 cards - decks.isEmpty(did)

This would fail at cases where the deck has subdecks, which are also empty.

Now the check is done to not just check subdecks, but the count of cards of these subdecks too.

  • using the forEach recursive function of DeckNode to traverse the entire tree of subdecks to check if all of them are empty for triggering the empty deck snackbar

How Has This Been Tested?

ran all tests from ./gradlew jacocoTestReport on emulator (android 15 VanillaIceCream)
PC config:
processor: i5 12500H
RAM: 16GB
SDK: 21
results: ran with 0 failures
Also I tested with creation of "A::B::C", "A::B" decks, and adding the cards to the subdecks.

clicking on A shows finished deck on A click
image image
clicking on B shows finished deck on B
image image

After fix

clicking on A clicking on B
image image

Update commit - 2e33db4

Now uses a new function isDeckAndSubdeckEmpty, and DeckNode implements Iterable, and hence the entire tree empty check is done using deckNode.all{}, which efficiently returns true or false.
Also refactored the previous query function that returned enums.

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Copy link

welcome bot commented Feb 22, 2025

First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible.

@devyk100
Copy link
Author

I'd really appreciate any feedback on improving this.

Copy link
Member

@Arthur-Milchior Arthur-Milchior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your first contribution. It does exactly what I wanted, that's great!

I have a few suggestion in order to improve the codebase quality generally.
Indeed, I didn't really know the part of the codebase you touched and it's only while reviewing your PR that I saw some improvement potential in our current codebase.

In particular, I think we can remove CompletedDeckStatus. When it was introduced, each status lead to a different action. Today, every status but the empty deck lead to the same action. Thus, the only thing that matter is "is the deck (and its subdeck) empty or not"
So we should have a function that answer this question (and write unit test to ensure it's answered properly) and then either display the snackbar or execute onDeckCompleted

Would you be willing to do all of those changes?

@devyk100
Copy link
Author

Thanks for the review and suggestions! I'll work on improving it

@devyk100
Copy link
Author

devyk100 commented Feb 24, 2025

@Arthur-Milchior really grateful for your reviews I was able to refactor this code. Can you have a look at it now? I'd appreciate if there are any improvements still possible in this.

Copy link
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left a comment. Thanks!

decks.isEmpty(did)
} -> CompletedDeckStatus.EMPTY_REGULAR_DECK
else -> CompletedDeckStatus.REGULAR_DECK_NO_MORE_CARDS_TODAY
private suspend fun isDeckAndSubdeckEmpty(did: DeckId): Boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I believe that areDeckAndSubdecksEmpty is more gramatically correct

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the first subject in the phrase is not plural, so I used 'is', but what you said makes sense. Shall I create a new commit to this PR fixing this?

@BrayanDSO BrayanDSO added the Needs Second Approval Has one approval, one more approval to merge label Feb 24, 2025
@devyk100
Copy link
Author

devyk100 commented Mar 3, 2025

@Arthur-Milchior I'd really appreciate your review if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Second Approval Has one approval, one more approval to merge New contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"This deck is empty" should appear even when the deck has empty subdeck
3 participants