forked from ankidroid/Anki-Android
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cardviewer): optimize deck access
This reduces the number of times getConfigForCurrentCard is called
- Loading branch information
1 parent
0bafa3e
commit f945b6b
Showing
3 changed files
with
81 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
AnkiDroid/src/main/java/com/ichi2/anki/cardviewer/SoundPlayer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2021 David Allison <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free Software | ||
* Foundation; either version 3 of the License, or (at your option) any later | ||
* version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.ichi2.anki.cardviewer | ||
|
||
import com.ichi2.anki.CardUtils | ||
import com.ichi2.libanki.Card | ||
import com.ichi2.libanki.Collection | ||
import com.ichi2.libanki.SoundOrVideoTag | ||
import com.ichi2.libanki.TTSTag | ||
|
||
/** | ||
* Work in Progress | ||
* | ||
* Handles the two ways an Anki card defines sound: | ||
* * Regular Sound (file-based, mp3 etc..): [SoundOrVideoTag] | ||
* * Text to Speech [TTSTag] | ||
* | ||
* https://docs.ankiweb.net/templates/fields.html?highlight=tts#text-to-speech | ||
* No manual reference for [sound:], but this handles Sound or Video with a reference to the file | ||
* in the media folder. | ||
* | ||
* AnkiDroid also introduced a "tts" setting, which existed before Anki Desktop TTS. | ||
* This only allowed TTS if a setting was enabled, | ||
* | ||
* This class combines the above concerns behind an "adapter" interface in order to simplify complexity. | ||
* | ||
* I hope that we can then test and reduce the complexity of this class. | ||
*/ | ||
class SoundPlayer { | ||
|
||
/** The options for playing sound for a given card */ | ||
class CardSoundConfig(val replayQuestion: Boolean, val autoplay: Boolean) { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun create(col: Collection, card: Card): CardSoundConfig { | ||
val deckConfig = col.decks.confForDid(CardUtils.getDeckIdForCard(card)) | ||
|
||
val autoPlay = deckConfig.optBoolean("autoplay", false) | ||
|
||
val replayQuestion: Boolean = deckConfig.optBoolean("replayq", true) | ||
|
||
return CardSoundConfig(replayQuestion, autoPlay) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters