Skip to content
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

Remove Automatic Display Answer global setting #17464

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,7 @@ abstract class AbstractFlashcardViewer :
// These are preferences we pull out of the collection instead of SharedPreferences
try {
showNextReviewTime = col.config.get("estTimes") ?: true
val preferences = baseContext.sharedPrefs()
automaticAnswer = AutomaticAnswer.createInstance(this, preferences, col)
automaticAnswer = AutomaticAnswer.createInstance(this, col)
} catch (ex: Exception) {
Timber.w(ex)
onCollectionLoadError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ object UsageAnalytics {
"dayOffset", // Start of next day
"learnCutoff", // Learn ahead limit
"timeLimit", // Timebox time limit
"timeoutAnswer", // Automatic display answer
"keepScreenOn", // Disable screen timeout
"doubleTapTimeInterval", // Double tap time interval (milliseconds)
// Sync
Expand Down
17 changes: 4 additions & 13 deletions AnkiDroid/src/main/java/com/ichi2/anki/reviewer/AutomaticAnswer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.ichi2.anki.reviewer

import android.content.SharedPreferences
import androidx.annotation.CheckResult
import androidx.annotation.VisibleForTesting
import com.ichi2.anki.CollectionManager.TR
Expand Down Expand Up @@ -149,7 +148,6 @@ class AutomaticAnswer(

/** Stop any "Automatic show answer" tasks in order to avoid race conditions */
fun onDisplayQuestion() {
if (!settings.useTimer) return
if (!settings.autoAdvanceIfShowingQuestion) return
hasPlayedSounds = false

Expand All @@ -158,7 +156,6 @@ class AutomaticAnswer(

/** Stop any "Automatic show question" tasks in order to avoid race conditions */
fun onDisplayAnswer() {
if (!settings.useTimer) return
if (!settings.autoAdvanceIfShowingAnswer) return
hasPlayedSounds = false

Expand Down Expand Up @@ -187,7 +184,6 @@ class AutomaticAnswer(
* after a user-specified duration, plus an additional delay for media
*/
fun scheduleAutomaticDisplayAnswer(additionalDelay: Long = 0) {
if (!settings.useTimer) return
if (!settings.autoAdvanceIfShowingQuestion) return
if (hasPlayedSounds) return
hasPlayedSounds = true
Expand All @@ -199,7 +195,6 @@ class AutomaticAnswer(
* after a user-specified duration, plus an additional delay for media
*/
fun scheduleAutomaticDisplayQuestion(additionalMediaDelay: Long = 0) {
if (!settings.useTimer) return
if (!settings.autoAdvanceIfShowingAnswer) return
if (hasPlayedSounds) return
hasPlayedSounds = true
Expand Down Expand Up @@ -228,8 +223,8 @@ class AutomaticAnswer(
}

@CheckResult
fun createInstance(target: AutomaticallyAnswered, preferences: SharedPreferences, col: Collection): AutomaticAnswer {
val settings = AutomaticAnswerSettings.createInstance(preferences, col)
fun createInstance(target: AutomaticallyAnswered, col: Collection): AutomaticAnswer {
val settings = AutomaticAnswerSettings.createInstance(col)
return AutomaticAnswer(target, settings)
}
}
Expand All @@ -253,7 +248,6 @@ class AutomaticAnswer(
*/
class AutomaticAnswerSettings(
val answerAction: AutomaticAnswerAction = AutomaticAnswerAction.BURY_CARD,
@get:JvmName("useTimer") val useTimer: Boolean = false,
private val secondsToShowQuestionFor: Double = 60.0,
private val secondsToShowAnswerFor: Double = 20.0
) {
Expand All @@ -271,24 +265,21 @@ class AutomaticAnswerSettings(
*/
@NeedsTest("ensure question setting maps to question parameter")
fun queryOptions(
preferences: SharedPreferences,
col: Collection,
selectedDid: DeckId
): AutomaticAnswerSettings {
val conf = col.decks.configDictForDeckId(selectedDid)
val action = getAction(conf)
val useTimer = preferences.getBoolean("timeoutAnswer", false)

return AutomaticAnswerSettings(
answerAction = action,
useTimer = useTimer,
secondsToShowQuestionFor = conf.secondsToShowQuestion,
secondsToShowAnswerFor = conf.secondsToShowAnswer
)
}

fun createInstance(preferences: SharedPreferences, col: Collection): AutomaticAnswerSettings {
return queryOptions(preferences, col, col.decks.selected())
fun createInstance(col: Collection): AutomaticAnswerSettings {
return queryOptions(col, col.decks.selected())
}

private fun getAction(conf: DeckConfig): AutomaticAnswerAction {
Expand Down
2 changes: 0 additions & 2 deletions AnkiDroid/src/main/res/values/10-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@
<string name="notification_minimum_cards_due">More than %d cards due</string>
<string name="notification_minimum_cards_due_vibrate" maxLength="41">Vibrate</string>
<string name="notification_minimum_cards_due_blink" maxLength="41">Blink light</string>
<string name="timeout_answer_text" maxLength="41">Automatic display answer</string>
<string name="timeout_answer_summ2">Show answer automatically without user input. Configure from deck options.</string>
<string name="select_locale_title">Select language</string>
<string name="software_render" maxLength="41">Disable card hardware render</string>
<string name="software_render_summ">Hardware render is faster but may have problems, specifically on Android 8/8.1. If you cannot see parts of the card review user interface, try this setting.</string>
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/values/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@

<string-array name="reviewing_summary_entries">
<item>@string/pref_cat_scheduling</item>
<item>@string/timeout_answer_text</item>
<item>@string/pref_keep_screen_on</item>
</string-array>

<string-array name="sync_summary_entries">
Expand Down
1 change: 0 additions & 1 deletion AnkiDroid/src/main/res/values/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<string name="day_offset_preference">dayOffset</string>
<string name="learn_cutoff_preference">learnCutoff</string>
<string name="time_limit_preference">timeLimit</string>
<string name="timeout_answer_preference">timeoutAnswer</string>
<string name="keep_screen_on_preference">keepScreenOn</string>
<string name="double_tap_time_interval_preference">doubleTapTimeInterval</string>
<!-- Sync -->
Expand Down
8 changes: 0 additions & 8 deletions AnkiDroid/src/main/res/xml/preferences_reviewing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@
app:min="0"
app1:summaryFormat="@plurals/pref_summ_minutes"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/timeout_answer_text" >
<SwitchPreferenceCompat
android:defaultValue="false"
android:disableDependentsState="false"
android:key="@string/timeout_answer_preference"
android:summary="@string/timeout_answer_summ2"
android:title="@string/timeout_answer_text" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_cat_advanced">
<SwitchPreferenceCompat
android:defaultValue="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class AbstractFlashcardViewerTest : RobolectricTest() {
fun noAutomaticAnswerAfterRenderProcessGoneAndPaused_issue9632() = runTest {
val controller = getViewerController(addCard = true, startedWithShortcut = false)
val viewer = controller.get()
viewer.automaticAnswer = AutomaticAnswer(viewer, AutomaticAnswerSettings(AutomaticAnswerAction.BURY_CARD, true, 5.0, 5.0))
viewer.automaticAnswer = AutomaticAnswer(viewer, AutomaticAnswerSettings(AutomaticAnswerAction.BURY_CARD, 5.0, 5.0))
viewer.executeCommand(ViewerCommand.SHOW_ANSWER)
assertThat("messages after flipping card", viewer.hasAutomaticAnswerQueued(), equalTo(true))
controller.pause()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ class AutomaticAnswerAndroidTest : RobolectricTest() {
}

private fun createInstance() =
AutomaticAnswer.createInstance(mock(), super.getPreferences(), super.col)
AutomaticAnswer.createInstance(mock(), super.col)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class AutomaticAnswerTest : JvmTest() {
val answer = AutomaticAnswer(
target = automaticallyAnsweredMock(),
settings = AutomaticAnswerSettings(
useTimer = true,
secondsToShowQuestionFor = 0.0,
secondsToShowAnswerFor = 0.0
)
Expand Down Expand Up @@ -136,7 +135,6 @@ class AutomaticAnswerTest : JvmTest() {
return AutomaticAnswer(
target = automaticAnswerHandler,
settings = AutomaticAnswerSettings(
useTimer = true,
secondsToShowQuestionFor = 10.0,
secondsToShowAnswerFor = 10.0
)
Expand Down