0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00

nf: extract render_output to collection

This is not part of libAnki, overridable for the rust implementation
This commit is contained in:
David Allison 2021-10-31 09:58:34 +00:00 committed by Mike Hardy
parent 28736a6345
commit 584161eb8d
2 changed files with 27 additions and 11 deletions

View File

@ -31,6 +31,7 @@ import com.ichi2.libanki.template.TemplateError
import com.ichi2.utils.Assert
import com.ichi2.utils.JSONObject
import com.ichi2.utils.LanguageUtil
import net.ankiweb.rsdroid.RustCleanup
import timber.log.Timber
import java.util.*
import java.util.concurrent.CancellationException
@ -238,19 +239,10 @@ open class Card : Cloneable {
}
@JvmOverloads
@RustCleanup("move col.render_output back to Card once the java collection is removed")
fun render_output(reload: Boolean = false, browser: Boolean = false): HashMap<String, String>? {
if (render_output == null || reload) {
val f = note(reload)
val m = model()
val t = template()
val did = if (isInDynamicDeck) oDid else did
render_output = if (browser) {
val bqfmt = t.getString("bqfmt")
val bafmt = t.getString("bafmt")
col._renderQA(this.id, m, did, ord, f.stringTags(), f.fields, flags, browser, bqfmt, bafmt)
} else {
col._renderQA(this.id, m, did, ord, f.stringTags(), f.fields, flags)
}
render_output = col.render_output(this, reload, browser)
}
return render_output
}
@ -414,6 +406,9 @@ open class Card : Cloneable {
flags = flag
}
/** Should use [userFlag] */
fun internalGetFlags() = flags
fun setUserFlag(flag: Int) {
flags = setFlagInInt(flags, flag)
}

View File

@ -1380,6 +1380,27 @@ public class Collection implements CollectionGetter {
}
@Nullable
public HashMap<String, String> render_output(@NonNull Card c, boolean reload, boolean browser) {
Note f = c.note(reload);
Model m = c.model();
JSONObject t = c.template();
long did;
if (c.isInDynamicDeck()) {
did = c.getODid();
} else {
did = c.getDid();
}
if (browser) {
String bqfmt = t.getString("bqfmt");
String bafmt = t.getString("bafmt");
return _renderQA(c.getId(), m, did, c.getOrd(), f.stringTags(), f.getFields(), c.internalGetFlags(), browser, bqfmt, bafmt);
} else {
return _renderQA(c.getId(), m, did, c.getOrd(), f.stringTags(), f.getFields(), c.internalGetFlags());
}
}
@VisibleForTesting
public static class UndoReview extends UndoAction {
private final boolean mWasLeech;