Skip to content

Commit

Permalink
use backend for show audio play buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
MorenoTropical committed Nov 20, 2024
1 parent 026ff16 commit 71d1df4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.core.app.ActivityCompat
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat
import anki.config.ConfigKey
import anki.config.copy
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.CollectionManager.withCol
Expand Down Expand Up @@ -139,9 +138,11 @@ class AppearanceSettingsFragment : SettingsFragment() {
// Note: Stored inverted in the collection as HIDE_AUDIO_PLAY_BUTTONS
requirePreference<SwitchPreferenceCompat>(R.string.show_audio_play_buttons_key).apply {
title = CollectionManager.TR.preferencesShowPlayButtonsOnCardsWith()
launchCatchingTask { isChecked = withCol { !config.getBool(ConfigKey.Bool.HIDE_AUDIO_PLAY_BUTTONS) } }
setOnPreferenceChangeListener { newValue ->
launchCatchingTask { withCol { config.setBool(ConfigKey.Bool.HIDE_AUDIO_PLAY_BUTTONS, !(newValue as Boolean)) } }
launchCatchingTask { isChecked = !getHidePlayAudioButtons() }
setOnPreferenceChangeListener { _, newValue ->
val newValueBool = newValue as? Boolean ?: return@setOnPreferenceChangeListener false
launchCatchingTask { setHideAudioPlayButtons(!newValueBool) }
true
}
}
}
Expand Down Expand Up @@ -208,7 +209,19 @@ class AppearanceSettingsFragment : SettingsFragment() {
undoableOp { setPreferences(newPrefs) }
Timber.i("Set showRemainingDueCounts to %b", value)
}

private suspend fun setHideAudioPlayButtons(value: Boolean) {
val prefs = withCol { getPreferences() }
val newPrefs = prefs.copy {
reviewing = reviewing.copy { hideAudioPlayButtons = value }
}
undoableOp { setPreferences(newPrefs) }
Timber.i("Set hideAudioPlayButtons to %b", value)
}
}

suspend fun getShowIntervalOnButtons(): Boolean =
withCol { getPreferences().reviewing.showIntervalsOnButtons }

suspend fun getHidePlayAudioButtons(): Boolean =
withCol { getPreferences().reviewing.hideAudioPlayButtons }
5 changes: 2 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Sound.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
package com.ichi2.libanki

import android.text.TextUtils
import anki.config.ConfigKey
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.preferences.getHidePlayAudioButtons
import com.ichi2.compat.CompatHelper
import com.ichi2.libanki.TemplateManager.TemplateRenderContext.TemplateRenderOutput
import com.ichi2.libanki.utils.NotInLibAnki
Expand Down Expand Up @@ -180,8 +180,7 @@ object Sound {
renderOutput: TemplateRenderOutput
): String {
val mediaDir = CollectionManager.withCol { media.dir }
val hidePlayButtons =
CollectionManager.withCol { config.getBool(ConfigKey.Bool.HIDE_AUDIO_PLAY_BUTTONS) }
val hidePlayButtons = getHidePlayAudioButtons()
return expandSounds(text, renderOutput, showAudioPlayButtons = !hidePlayButtons, mediaDir)
}

Expand Down

0 comments on commit 71d1df4

Please sign in to comment.