-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fixed bug which was causing AnkiDroid API to not list media on cards. #17859
base: main
Are you sure you want to change the base?
Conversation
First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible. |
currentCard: Card, | ||
includeRemote: Boolean = false, | ||
): List<String> { | ||
val l: MutableList<String> = ArrayList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like upstream code:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@david-allison I have reimplemented the old code for the fileinStr
from here:
fun filesInStr(mid: Long?, string: String, includeRemote: Boolean = false): List<String> { |
This logic was able to extract the image file names but it could not extract the AV tags. My guess is that this is because the
Card.renderOutput
returns AVTags
and it is in the form SoundOrVideoTag(filename)
. To address this, I added some logic in the function to extract the AVTags
as well, and it is now working as expected! Could you please review the changes and let me know if you think this implementation is correct? Any feedback or suggestions for improvement would be greatly appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should follow upstream as close as possible in libanki, unless there's a strong reason not to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I will try again with the upstream code you provided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @david-allison,
I have attempted to implement the upstream code and although the logic successfully includes image files in the returned media array, the audio files are missing. From my observation, the logic I initially added for extracting audio files ensures they are included in the media array.
Here's the code I used:
fun filesInStr(
currentCard: Card,
includeRemote: Boolean = false,
): List<String> {
val l: MutableList<String> = ArrayList()
val model = currentCard.noteType(col)
val renderOutput = currentCard.renderOutput(col)
val string = renderOutput.questionText + renderOutput.answerText
var strings: MutableList<String?> = ArrayList()
if (model!!.isCloze && string.contains("{{c")) {
// Expand clozes if necessary
strings = expandClozes(string)
} else {
strings.add(string)
}
for (s in strings) {
var s = s
// Handle LaTeX
@KotlinCleanup("change to .map { }")
val svg = model.optBoolean("latexsvg", false)
s = LaTeX.mungeQA(s!!, col, svg)
// Extract filenames from the strings using regex patterns
var m: Matcher
for (p in REGEXPS) {
val fnameIdx =
when (p) {
fSoundRegexps -> 2
fImgAudioRegExpU -> 2
else -> 3
}
m = p.matcher(s)
while (m.find()) {
val fname = m.group(fnameIdx)!!
val isLocal = !fRemotePattern.matcher(fname.lowercase(Locale.getDefault())).find()
if (isLocal || includeRemote) {
l.add(fname)
}
}
}
}
return l
}
Could you please advise on how you would like to proceed? Should I enhance the upstream logic to account for audio files, or is there another direction you'd suggest?
Purpose / Description
Fixed the bug which was causing AnkiDroid API to not list media on cards. Added a unit test to confirm that media files are listed correctly in the ReviewInfo.
Fixes
Approach
Reimplemented the
filesinStr
function which was causing the bug.How Has This Been Tested?
A unit test
testMediaFilesAddedCorrectlyInReviewInfo()
has been added in theContentProviderTest.kt
to confirm that theMEDIA_FILES
attribute ofReviewInfo
gets populated correctly.Checklist
Please, go through these checks before submitting the PR.