From a31eae457ede39c1a9a1358a7ae4b4a7750fa4b2 Mon Sep 17 00:00:00 2001 From: David Allison <62114487+david-allison-1@users.noreply.github.com> Date: Mon, 1 Nov 2021 08:03:34 +0000 Subject: [PATCH] nf: make methods static getAnswerFormat removeFrontSideAudio These will be extracted --- .../com/ichi2/anki/AbstractFlashcardViewer.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java index fccc702f0c..3e90b048ca 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java @@ -1748,13 +1748,13 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity i /** - * getAnswerFormat returns the answer part of this card's template as entered by user, without any parsing + * @return the answer part of this card's template as entered by user, without any parsing */ - public String getAnswerFormat() { - Model model = mCurrentCard.model(); + public static String getAnswerFormat(Card card) { + Model model = card.model(); JSONObject template; if (model.isStd()) { - template = model.getJSONArray("tmpls").getJSONObject(mCurrentCard.getOrd()); + template = model.getJSONArray("tmpls").getJSONObject(card.getOrd()); } else { template = model.getJSONArray("tmpls").getJSONObject(0); } @@ -1766,7 +1766,7 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity i // don't add answer sounds multiple times, such as when reshowing card after exiting editor // additionally, this condition reduces computation time if (!mAnswerSoundsAdded) { - String answerSoundSource = removeFrontSideAudio(answer); + String answerSoundSource = removeFrontSideAudio(mCurrentCard, answer); List tags = Sound.extractTagsFromLegacyContent(answerSoundSource); mSoundPlayer.addSounds(mBaseUrl, tags, SoundSide.ANSWER); mAnswerSoundsAdded = true; @@ -2516,14 +2516,15 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity i /** * Removes first occurrence in answerContent of any audio that is present due to use of * {{FrontSide}} on the answer. + * @param card The card to strip content from * @param answerContent The content from which to remove front side audio. * @return The content stripped of audio due to {{FrontSide}} inclusion. */ - private String removeFrontSideAudio(String answerContent) { - String answerFormat = getAnswerFormat(); + private static String removeFrontSideAudio(Card card, String answerContent) { + String answerFormat = getAnswerFormat(card); String newAnswerContent = answerContent; if (answerFormat.contains("{{FrontSide}}")) { // possible audio removal necessary - String frontSideFormat = mCurrentCard.render_output(false).getQuestionText(); + String frontSideFormat = card.render_output(false).getQuestionText(); Matcher audioReferences = Sound.SOUND_PATTERN.matcher(frontSideFormat); // remove the first instance of audio contained in "{{FrontSide}}" while (audioReferences.find()) {