-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(split-cardbrowser): list is empty when toggling to notes only mode #20027
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
base: main
Are you sure you want to change the base?
Conversation
david-allison
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be handling the outcome of #19805
In addition, I feel we should prefer null over 0 here.
'No row/no selected row' is a valid state for the browser (for example: if a query produces no rows) and we should handle this.
| /** | ||
| * Safely determines the current card ID to display in the note editor. | ||
| */ | ||
| suspend fun safeGetCurrentCardId(): CardId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use 0 instead of null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code expects a CardId (which is a Long), and 0 lets us avoid changing everything to nullable types. 0 serves as our 'no card' sentinel that maintains non-null types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 'null' if it can be null
Could you elaborate it? |
I already handles right? or am I missed anything? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentCardId being non-null is a bad abstraction.
It was added in Java in:
and should be nullable now we're in Kotlin (if it even needs to continue to exist)
david-allison
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So much better, thanks!
AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserViewModel.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserViewModel.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserViewModel.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/test/java/com/ichi2/anki/browser/CardBrowserViewModelTest.kt
Outdated
Show resolved
Hide resolved
david-allison
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SO MUCH BETTER!
One method name/implementation issue.
A unit test on the ViewModel side would be ideal.
I'm questioning the domain modelling assumptions that a note may not have cards (we should probably expose this as a warning that the user needs to check database).
Probably add in a TODO to think about this.
AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserViewModel.kt
Outdated
Show resolved
Hide resolved
| * @property cardId The ID of the card to edit. | ||
| * @property animation The animation direction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a name change, or a new class.
Logically, passing in a null card to edit a card doesn't sit well with me
david-allison
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One issue on EditCard no longer accepting a CardId
| * TODO: Notes without cards likely indicate an invalid or corrupted collection state. | ||
| * We currently handle this gracefully by returning an empty list, | ||
| * we may want to surface this as a warning or integrity check for the user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this TODO out of libanki,
I missed that this was library code. Handing the issue is an application-level concern
david-allison
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers!
Purpose / Description
java.util.NoSuchElementException: List is empty when toggling Card/Notes
Fixes
Approach
Moved logic to ViewModel with safe handling
How Has This Been Tested?
Chromebook
Checklist
Please, go through these checks before submitting the PR.