Skip to content

Commit

Permalink
docs(Card): document libanki methods
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Mar 24, 2024
1 parent 52792e3 commit 53a4450
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/libanki/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ open class Card : Cloneable {
}
}

@LibAnkiAlias("load")
fun load(col: Collection) {
val card = col.backend.getCard(id)
loadFromBackendCard(card)
}

@LibAnkiAlias("_load_from_backend_card")
private fun loadFromBackendCard(card: anki.cards.Card) {
renderOutput = null
note = null
Expand All @@ -144,6 +146,7 @@ open class Card : Cloneable {
desiredRetention = if (card.hasDesiredRetention()) card.desiredRetention else null
}

@LibAnkiAlias("_to_backend_card")
fun toBackendCard(): anki.cards.Card {
val builder = anki.cards.Card.newBuilder()
.setId(id)
Expand All @@ -168,25 +171,30 @@ open class Card : Cloneable {
return builder.build()
}

@LibAnkiAlias("question")
fun question(col: Collection, reload: Boolean = false, browser: Boolean = false): String {
return renderOutput(col, reload, browser).questionAndStyle()
}

@LibAnkiAlias("answer")
fun answer(col: Collection): String {
return renderOutput(col).answerAndStyle()
}

@LibAnkiAlias("question_av_tags")
fun questionAvTags(col: Collection): List<AvTag> {
return renderOutput(col).questionAvTags
}

@LibAnkiAlias("answer_av_tags")
fun answerAvTags(col: Collection): List<AvTag> {
return renderOutput(col).answerAvTags
}

/**
* @throws net.ankiweb.rsdroid.exceptions.BackendInvalidInputException: If the card does not exist
*/
@LibAnkiAlias("render_output")
open fun renderOutput(col: Collection, reload: Boolean = false, browser: Boolean = false): TemplateRenderOutput {
if (renderOutput == null || reload) {
renderOutput = TemplateManager.TemplateRenderContext.fromExistingCard(col, this, browser).render(col)
Expand All @@ -207,6 +215,7 @@ open class Card : Cloneable {
return note(col).notetype
}

@LibAnkiAlias("template")
fun template(col: Collection): JSONObject {
val m = noteType(col)
return if (m.isStd) {
Expand All @@ -216,10 +225,12 @@ open class Card : Cloneable {
}
}

@LibAnkiAlias("start_timer")
fun startTimer() {
timerStarted = TimeManager.time.intTimeMS()
}

@LibAnkiAlias("current_deck_id")
fun currentDeckId(): anki.decks.DeckId {
return anki.decks.DeckId.newBuilder()
.setDid(oDid.ifZero { did })
Expand All @@ -238,6 +249,7 @@ open class Card : Cloneable {
/*
* Time taken to answer card, in integer MS.
*/
@LibAnkiAlias("time_taken")
fun timeTaken(col: Collection): Int {
// Indeed an int. Difference between two big numbers is still small.
val total = (TimeManager.time.intTimeMS() - timerStarted).toInt()
Expand Down Expand Up @@ -285,6 +297,7 @@ open class Card : Cloneable {
return col.decks.configDictForDeckId(currentDeckId().did).getBoolean("autoplay")
}

@NotInLibAnki
public override fun clone(): Card {
return try {
super.clone() as Card
Expand Down Expand Up @@ -325,6 +338,7 @@ open class Card : Cloneable {
return (this.id xor (this.id ushr 32)).toInt()
}

@LibAnkiAlias("user_flag")
fun userFlag(): Int {
return flags and 0b111
}
Expand All @@ -334,11 +348,13 @@ open class Card : Cloneable {
flags = flag
}

// TODO deprecated in Anki: use col.set_user_flag_for_cards() instead
@LibAnkiAlias("set_user_flag")
fun setUserFlag(flag: Int) {
flags = setFlagInInt(flags, flag)
}

/** Non libAnki */
@NotInLibAnki
val isInDynamicDeck: Boolean
get() = // In Anki Desktop, a card with oDue <> 0 && oDid == 0 is not marked as dynamic.
oDid != 0L
Expand Down Expand Up @@ -370,6 +386,7 @@ open class Card : Cloneable {
* cache.reload();
* Card card2 = cache.getCard();
*/
@NotInLibAnki
open class Cache : Cloneable {
val col: Collection
val id: Long
Expand Down

0 comments on commit 53a4450

Please sign in to comment.