Skip to content

refactor: Convert Sched to Kotlin #12301

Merged
Arthur-Milchior merged 2 commits into
ankidroid:mainfrom
david-allison:kotlin-sched
Sep 4, 2022
Merged

refactor: Convert Sched to Kotlin #12301
Arthur-Milchior merged 2 commits into
ankidroid:mainfrom
david-allison:kotlin-sched

Conversation

@david-allison

Copy link
Copy Markdown
Member

No description provided.

com.ichi2.libanki.sched.Sched

@lukstbit lukstbit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, just some minor cleanups.

Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
@lukstbit lukstbit added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Sep 3, 2022

@Arthur-Milchior Arthur-Milchior left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I probably missed some cleanup, this class is incredibly long. (And I plead guilty for part of it)
Still, I believe a bunch of cleanup that may improve code eventually

Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
var rlim = _deckRevLimitSingle(deck, false)
if (!TextUtils.isEmpty(p)) {
Integer[] parentLims = lims.get(Decks.normalizeName(p));
val parentLims = lims[Decks.normalizeName(p)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd consider putting the !! here, to make clear that it's directly non null

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This breaks the Assert below

Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt Outdated
Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt Outdated
List<Long> ids = getCol().findCards(search, orderLimit);
private fun _fillDyn(deck: Deck): List<Long> {
val terms = deck.getJSONArray("terms").getJSONArray(0)
var search = terms.getString(0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

KotlinCleanup: transform this into val

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This breaks libAnki compat

Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
private fun _rescheduleRev(card: Card, @BUTTON_TYPE ease: Int) {
// update interval
card.setLastIvl(card.getIvl());
card.lastIvl = card.ivl

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

KotlinCleanup: Either card.apply or even define it as Card._rescheduleRev.
Same for other methods rescheduling cards

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This breaks libAnki compat

Comment thread AnkiDroid/src/main/java/com/ichi2/libanki/sched/Sched.kt
com.ichi2.libanki.sched.Sched
@dae

dae commented Sep 4, 2022

Copy link
Copy Markdown
Contributor

I don't recommend expending much effort on this file, since reviewing with the v1 scheduler is no longer possible since #11808

@david-allison

Copy link
Copy Markdown
Member Author

Agreed, just want to get to 0% Java so we can cut down the excess code and hopefully reduce compile times

@Arthur-Milchior Arthur-Milchior merged commit 61ec185 into ankidroid:main Sep 4, 2022
@github-actions github-actions Bot added this to the 2.16 release milestone Sep 4, 2022
@github-actions github-actions Bot removed the Needs Second Approval Has one approval, one more approval to merge label Sep 4, 2022
@Arthur-Milchior

Copy link
Copy Markdown
Member

Merged. If we don't care about cleanup because the code will disappear, no need to wait for the cleanup

@david-allison david-allison deleted the kotlin-sched branch September 4, 2022 16:47
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.

4 participants