Skip to content

Commit

Permalink
Added Option to choose the default answer(Again, Hard, Good, Easy) on…
Browse files Browse the repository at this point in the history
… timeout when the "automatic display answer" setting is used
  • Loading branch information
IAmJaishree committed Mar 22, 2021
1 parent 7921fc2 commit 5dc0ec7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity i
private boolean mTouchStarted = false;
private boolean mInAnswer = false;
private boolean mAnswerSoundsAdded = false;
private int mAutomaticAnswerSelection;

private CardTemplate mCardTemplate;

Expand Down Expand Up @@ -1798,6 +1799,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 +1930,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
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>"Again"</item>
<item>"Hard (or Good if Hard is not an option)"</item>
<item>"Good (Default)"</item>
<item>"Easy (or Good if Easy is not an option)"</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 5dc0ec7

Please sign in to comment.