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

refactor(libanki): convert Consts to enums #17431

Merged
merged 3 commits into from
Jan 4, 2025

Conversation

Arthur-Milchior
Copy link
Member

@Arthur-Milchior Arthur-Milchior commented Nov 12, 2024

This PR should be merged after #17430. It contains #17430 and removing #17430 would create a ton of merge conflict.

It transforms IntDef of Consts.kt into enum

@david-allison david-allison added the Blocked by dependency Currently blocked by some other dependent / related change label Nov 13, 2024
@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author and removed Blocked by dependency Currently blocked by some other dependent / related change Has Conflicts labels Dec 6, 2024
@david-allison
Copy link
Member

@Arthur-Milchior Unblocked

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Incomplete review, I'm not going to have time to finish it

@@ -246,12 +246,12 @@ open class AnkiDroidJsAPI(private val activity: AbstractFlashcardViewer) {
"cardMod" -> convertToByteArray(apiContract, currentCard.mod)
"cardId" -> convertToByteArray(apiContract, currentCard.id)
"cardNid" -> convertToByteArray(apiContract, currentCard.nid)
"cardType" -> convertToByteArray(apiContract, currentCard.type)
"cardType" -> convertToByteArray(apiContract, currentCard.type.ordinal)
Copy link
Member

Choose a reason for hiding this comment

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

! Should be a constant, not dependent on the enum order

AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/libanki/Collection.kt Outdated Show resolved Hide resolved
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Dec 8, 2024
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Doesn't compile

Last round of feedback. Let's get this in

AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/libanki/Collection.kt Outdated Show resolved Hide resolved
fun reviewable() =
when (this) {
MANUALLY_BURIED, SIBLING_BURIED, SUSPENDED -> false
NEW, LRN, REV, DAY_LEARN_RELEARN, PREVIEW -> true
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't make sense to me as a name. Preview is reviewable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Would "viewable" be better?
I'd be fine with a NOTREACHED() for the "preview" case because we should never reach it.

AnkiDroid/src/main/java/com/ichi2/libanki/Consts.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/libanki/NotetypeJson.kt Outdated Show resolved Hide resolved
AnkiDroid/src/test/java/com/ichi2/libanki/ModelTest.kt Outdated Show resolved Hide resolved
@Arthur-Milchior Arthur-Milchior force-pushed the CONSTS branch 3 times, most recently from 194ac14 to 74c7155 Compare December 12, 2024 21:14
@Arthur-Milchior Arthur-Milchior removed the Needs Author Reply Waiting for a reply from the original author label Dec 12, 2024
@Arthur-Milchior Arthur-Milchior force-pushed the CONSTS branch 2 times, most recently from 1148af6 to fdc3513 Compare December 12, 2024 21:34
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Dec 13, 2024
@Arthur-Milchior Arthur-Milchior force-pushed the CONSTS branch 2 times, most recently from e9f22c1 to 5cd6e10 Compare December 14, 2024 02:12
@Arthur-Milchior Arthur-Milchior removed Needs Author Reply Waiting for a reply from the original author Has Conflicts labels Dec 14, 2024
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Cheers!

AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.kt Outdated Show resolved Hide resolved
@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Author Reply Waiting for a reply from the original author Needs Review Has Conflicts labels Dec 29, 2024
@david-allison david-allison changed the title Consts refactor(libanki): convert Consts to enums Dec 29, 2024
@Arthur-Milchior
Copy link
Member Author

I hope I understood correctly what you asked me to do with the unknown case.
Now if the database contains data that we don't know how to interpret we'll have a Unknown queue and card type.
I was effrayed it would break ankidroid in unexpected way. But actually, as we don't do anything except display value, I guess if anything break, it'll be backend job to handle it.

@david-allison
Copy link
Member

Needs ./gradlew --rerun-tasks ktLintFormat, maybe over a few commits

Would also question why the pre-commit hook isn't firing. This may want to be rebased on main if it hasn't already

This improves typing. It's also clearer what will be the behavior of
the app if we encounter code with a new kind of card type.
This improve the typing.
sealed class CardType(
val code: Int,
) {
object New : CardType(0)
Copy link
Member

Choose a reason for hiding this comment

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

prefer data object

@lukstbit
Copy link
Member

lukstbit commented Jan 4, 2025

Merging this now so it doesn't take any more conflicts.

@lukstbit lukstbit added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Jan 4, 2025
@lukstbit lukstbit added this pull request to the merge queue Jan 4, 2025
Merged via the queue into ankidroid:main with commit a01983b Jan 4, 2025
9 checks passed
@github-actions github-actions bot added this to the 2.21 release milestone Jan 4, 2025
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Jan 4, 2025
@Arthur-Milchior Arthur-Milchior deleted the CONSTS branch January 5, 2025 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants