Skip to content

Commit

Permalink
Added option to change default automatic answer
Browse files Browse the repository at this point in the history
This commit provides functionality of choosing the default answer
for automatic display answer" scenario and by default
"Good" is selected instead of "Again" as the answer.

Fixes ankidroid#2609
  • Loading branch information
IAmJaishree committed Mar 22, 2021
1 parent 7921fc2 commit e37b462
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity i
private boolean mInAnswer = false;
private boolean mAnswerSoundsAdded = false;

/** Preferred option that should be selected in "Automatic answer" scenario **/
private int mAutomaticAnswerSelection;

private CardTemplate mCardTemplate;

/**
Expand Down Expand Up @@ -1798,6 +1801,8 @@ protected void initControls() {
protected SharedPreferences restorePreferences() {
SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());


mAutomaticAnswerSelection = Integer.parseInt(preferences.getString("automaticAnswer", "3"));
mUseInputTag = preferences.getBoolean("useInputTag", false);
mDoNotUseCodeFormatting = preferences.getBoolean("noCodeFormatting", false);
// On newer Androids, ignore this setting, which should be hidden in the prefs anyway.
Expand Down Expand Up @@ -1927,9 +1932,51 @@ protected void updateDeckName() {
protected final Runnable mShowQuestionTask = new Runnable() {
@Override
public void run() {
// Assume hitting the "Again" button when auto next question
if (mEase1Layout.isEnabled() && mEase1Layout.getVisibility() == View.VISIBLE) {
mEase1Layout.performClick();
// Hitting button based on the user preference for "automaticdisplayanswer" scenario
switch (mAutomaticAnswerSelection) {
// Again
case 1: {
// "Again" is always present as the first button
if (mEase1Layout.isEnabled() && mEase1Layout.getVisibility() == View.VISIBLE) {
mEase1Layout.performClick();
}
break;
}
// Hard(or Good if Hard is not an option)
case 2: {
// Second button can either be "Hard" or "Good"
// If "hard "is present it will be second button otherwise "Good" will be the second button
if (mEase2Layout.isEnabled() && mEase2Layout.getVisibility() == View.VISIBLE) {
mEase2Layout.performClick();
}
break;
}
// "Good"
case 3: {
if (getAnswerButtonCount() == 2 && mEase2Layout.isEnabled() && mEase2Layout.getVisibility() == View.VISIBLE) {
// In case of only two buttons "Good" is the Second option
mEase2Layout.performClick();
} else if (mEase3Layout.isEnabled() && mEase3Layout.getVisibility() == View.VISIBLE) {
// If more than two buttons are present then "Good" is the third option
mEase3Layout.performClick();
}
break;
}
// "Easy (or Good if Easy is not an option )"
case 4: {
if (getAnswerButtonCount() == 4 && mEase4Layout.isEnabled() && mEase4Layout.getVisibility() == View.VISIBLE) {
// In case of All 4 buttons are present "Easy" is the 4th button
mEase4Layout.performClick();
} else if (getAnswerButtonCount() == 3 && mEase3Layout.isEnabled() && mEase3Layout.getVisibility() == View.VISIBLE) {
// If 3 buttons are present then if "Easy" is present it is the third option
// or if "Easy" is not present then "Good" is the third option
mEase3Layout.performClick();
} else if (mEase2Layout.isEnabled() && mEase2Layout.getVisibility() == View.VISIBLE) {
// If only two buttons are present then "Good" is the second option
mEase2Layout.performClick();
}
break;
}
}
}
};
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/10-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<string name="notification_minimum_cards_due_vibrate">Vibrate</string>
<string name="notification_minimum_cards_due_blink">Blink light</string>
<string name="timeout_answer_text">Automatic display answer</string>
<string name="timeout_answer">Timeout answer</string>
<string name="timeout_answer_summ">Show answer automatically without user input. Delay includes time for automatically played audio files.</string>
<string name="timeout_answer_seconds">Time to show answer</string>
<string name="timeout_answer_seconds_summ" comment="The time to wait (in seconds) in the reviewer before automatically showing the next question or answer">XXX s</string>
Expand Down
4 changes: 4 additions & 0 deletions AnkiDroid/src/main/res/values/11-arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,9 @@
<string name="gesture_toggle_whiteboard">Toggle Whiteboard</string>
<string name="record_voice">Record Voice</string>
<string name="replay_voice">Replay Voice</string>
<string name="automatic_answer_option_1">Again</string>
<string name="automatic_answer_option_2">Hard (or Good if Hard is not an option)</string>
<string name="automatic_answer_option_3">Good (Default)</string>
<string name="automatic_answer_option_4">Easy (or Good if Easy is not an option)</string>

</resources>
12 changes: 12 additions & 0 deletions AnkiDroid/src/main/res/values/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@
<item>1</item>
<item>2</item>
</string-array>
<string-array name="automatic_answer_options">
<item>@string/automatic_answer_option_1</item>
<item>@string/automatic_answer_option_2</item>
<item>@string/automatic_answer_option_3</item>
<item>@string/automatic_answer_option_4</item>
</string-array>
<string-array name="automatic_answer_values">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
<string-array name="override_font_values">
<item>0</item>
<item>1</item>
Expand Down
7 changes: 7 additions & 0 deletions AnkiDroid/src/main/res/xml/preferences_reviewing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@
android:key="timeoutAnswer"
android:summary="@string/timeout_answer_summ"
android:title="@string/timeout_answer_text" />
<ListPreference
android:entries="@array/automatic_answer_options"
android:dependency="timeoutAnswer"
android:entryValues="@array/automatic_answer_values"
android:defaultValue="3"
android:key="automaticAnswer"
android:title="@string/timeout_answer" />
<com.ichi2.ui.SeekBarPreference
android:defaultValue="20"
android:dependency="timeoutAnswer"
Expand Down

0 comments on commit e37b462

Please sign in to comment.