-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
NF: Use com.ichi2.anki.Ease as much as possible #17430
base: main
Are you sure you want to change the base?
Conversation
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.
Implementer's choice on most of these. Thanks so much for splitting them up!
AnkiDroid/src/main/java/com/ichi2/anki/provider/CardContentProvider.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/test/java/com/ichi2/anki/ReviewerKeyboardInputTest.kt
Outdated
Show resolved
Hide resolved
e3f5e07
to
047acc3
Compare
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.
Marking as 'second approval' with trust that the API documentation issues will be resolved
Minor concern we're moving away from upstream with the tests, but most of which will be in Rust by now.
AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt
Outdated
Show resolved
Hide resolved
047acc3
to
385a25b
Compare
|
*The function associating to [value] the Ease whose value is [value]. | ||
* E.g. it sends 1 to [Again] and 4 to [Easy] | ||
*/ | ||
fun fromValue(value: Int) = Ease.entries[value - 1] |
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 implementation assumes that the values in the enum are ordered. This is the case now, and tbh it is unlikely to change, but I prefer to avoid future human errors when possible.
fun fromValue(value: Int) = Ease.entries[value - 1] | |
fun fromValue(value: Int) = entries.first { it.value == value } |
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.
Currently, this is guaranteed by the documentation. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.enums/-enum-entries.html But fine. I doubt this is in the loop where it would be an issue to iterate over four elements
/** | ||
*The function associating to [value] the Ease whose value is [value]. | ||
* E.g. it sends 1 to [Again] and 4 to [Easy] | ||
*/ |
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.
From the name of the enum property and the name of this method, I think that it's quite intuitive to know its purpose and anything different from that would be unexpected IMO, so I don't think that this comment is useful.
This allo to remove else in `when` case, and generally improve typing. Also, allows to remove some constant that were duplicate of the enum entries.
385a25b
to
4221eb5
Compare
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 architectural request
companion object { | ||
fun Int.toEase() = entries.first { this == it.value } | ||
} |
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.
Ease.fromValue
(or similar).
Adding global extensions to Int
gets messy quickly.
var timeTaken: Long = -1 | ||
var bury = -1 | ||
var suspend = -1 | ||
for ((key) in valueSet) { | ||
when (key) { | ||
FlashCardsContract.ReviewInfo.NOTE_ID -> noteID = values.getAsLong(key) | ||
FlashCardsContract.ReviewInfo.CARD_ORD -> cardOrd = values.getAsInteger(key) | ||
FlashCardsContract.ReviewInfo.EASE -> ease = values.getAsInteger(key) | ||
FlashCardsContract.ReviewInfo.EASE -> { | ||
// The value corresponds to |
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.
sentence fragment
This allows to remove else in
when
case, and generally improve typing. Also, allows to remove some constant that were duplicate of the enum entries.