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 19, 2024
1 parent 13466d0 commit a74f938
Show file tree
Hide file tree
Showing 2 changed files with 18 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 { setHidePlayAudioButtons(!newValueBool) }
true
}
}
}
Expand Down Expand Up @@ -207,8 +208,19 @@ class AppearanceSettingsFragment : SettingsFragment() {
undoableOp { setPreferences(newPrefs) }
}

private suspend fun setHidePlayAudioButtons(value: Boolean) {
val prefs = withCol { getPreferences() }
val newPrefs = prefs.copy {
reviewing = reviewing.copy { hideAudioPlayButtons = value }
}
undoableOp { setPreferences(newPrefs) }
}

companion object {
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.AppearanceSettingsFragment
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 = AppearanceSettingsFragment.getHidePlayAudioButtons()
return expandSounds(text, renderOutput, showAudioPlayButtons = !hidePlayButtons, mediaDir)
}

Expand Down

0 comments on commit a74f938

Please sign in to comment.