Skip to content

Commit

Permalink
Added review options related to the automatic showing of answer speci…
Browse files Browse the repository at this point in the history
…fic to a group of decks
  • Loading branch information
Acácio Correia authored and mikehardy committed Feb 10, 2020
1 parent 794caeb commit 3a7bea5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,19 @@ public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity {
protected boolean mSpeakText;
protected boolean mDisableClipboard = false;
protected boolean mNightMode = false;

protected boolean mOptUseGeneralTimerSettings;

protected boolean mUseTimer;
protected int mWaitAnswerSecond;
protected int mWaitQuestionSecond;

protected boolean mPrefUseTimer;

protected boolean mOptUseTimer;
protected int mOptWaitAnswerSecond;
protected int mOptWaitQuestionSecond;

private boolean mPrefCenterVertically;
protected boolean mUseInputTag;

Expand Down Expand Up @@ -773,8 +785,8 @@ public void run() {
}
};

protected int mWaitAnswerSecond;
protected int mWaitQuestionSecond;
protected int mPrefWaitAnswerSecond;
protected int mPrefWaitQuestionSecond;

protected int getDefaultEase() {
if (getCol().getSched().answerButtons(mCurrentCard) == 4) {
Expand Down Expand Up @@ -1702,6 +1714,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {

protected SharedPreferences restorePreferences() {
SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());

mPrefHideDueCount = preferences.getBoolean("hideDueCount", false);
mPrefShowETA = preferences.getBoolean("showETA", true);
mUseInputTag = preferences.getBoolean("useInputTag", false);
Expand All @@ -1715,8 +1728,8 @@ protected SharedPreferences restorePreferences() {
mRelativeButtonSize = preferences.getInt("answerButtonSize", 100);
mSpeakText = preferences.getBoolean("tts", false);
mPrefUseTimer = preferences.getBoolean("timeoutAnswer", false);
mWaitAnswerSecond = preferences.getInt("timeoutAnswerSeconds", 20);
mWaitQuestionSecond = preferences.getInt("timeoutQuestionSeconds", 60);
mPrefWaitAnswerSecond = preferences.getInt("timeoutAnswerSeconds", 6);
mPrefWaitQuestionSecond = preferences.getInt("timeoutQuestionSeconds", 60);
mScrollingButtons = preferences.getBoolean("scrolling_buttons", false);
mDoubleScrolling = preferences.getBoolean("double_scrolling", false);
mPrefCenterVertically = preferences.getBoolean("centerVertically", false);
Expand Down Expand Up @@ -1764,6 +1777,13 @@ private void restoreCollectionPreferences() {
try {
mShowNextReviewTime = getCol().getConf().getBoolean("estTimes");
mShowRemainingCardCount = getCol().getConf().getBoolean("dueCounts");

JSONObject revOptions = getCol().getDecks().confForDid(getCol().getDecks().current().getLong("id")).getJSONObject("rev");

mOptUseGeneralTimerSettings = revOptions.optBoolean("useGeneralTimeoutSettings", true);
mOptUseTimer = revOptions.optBoolean("timeoutAnswer", false);
mOptWaitAnswerSecond = revOptions.optInt("timeoutAnswerSeconds", 6);
mOptWaitQuestionSecond = revOptions.optInt("timeoutQuestionSeconds", 60);
} catch (JSONException e) {
throw new RuntimeException();
} catch (NullPointerException npe) {
Expand Down Expand Up @@ -1945,8 +1965,19 @@ protected void displayCardQuestion() {
updateCard(displayString);
hideEaseButtons();

// Check if it should use the general 'Timeout settings' or the ones specific to this deck
if (mOptUseGeneralTimerSettings){
mUseTimer = mPrefUseTimer;
mWaitAnswerSecond = mPrefWaitAnswerSecond;
mWaitQuestionSecond = mPrefWaitQuestionSecond;
}else{
mUseTimer = mOptUseTimer;
mWaitAnswerSecond = mOptWaitAnswerSecond;
mWaitQuestionSecond = mOptWaitQuestionSecond;
}

// If the user wants to show the answer automatically
if (mPrefUseTimer) {
if (mUseTimer) {
long delay = mWaitAnswerSecond * 1000 + mUseTimerDynamicMS;
if (delay > 0) {
mTimeoutHandler.removeCallbacks(mShowAnswerTask);
Expand Down Expand Up @@ -2032,7 +2063,7 @@ protected void displayCardAnswer() {
updateCard(enrichWithQADiv(answer, true));
showEaseButtons();
// If the user wants to show the next question automatically
if (mPrefUseTimer) {
if (mUseTimer) {
long delay = mWaitQuestionSecond * 1000 + mUseTimerDynamicMS;
if (delay > 0) {
mTimeoutHandler.removeCallbacks(mShowQuestionTask);
Expand Down Expand Up @@ -2120,7 +2151,7 @@ private void updateCard(String content) {
mSoundPlayer.resetSounds();
mAnswerSoundsAdded = false;
mSoundPlayer.addSounds(mBaseUrl, content, Sound.SOUNDS_QUESTION);
if (mPrefUseTimer && !mAnswerSoundsAdded && getConfigForCurrentCard().optBoolean("autoplay", false)) {
if (mUseTimer && !mAnswerSoundsAdded && getConfigForCurrentCard().optBoolean("autoplay", false)) {
addAnswerSounds(mCurrentCard.a());
}
}
Expand Down Expand Up @@ -2242,13 +2273,13 @@ protected void playSounds(boolean doAudioReplay) {
mSoundPlayer.playSounds(Sound.SOUNDS_QUESTION_AND_ANSWER);
} else if (sDisplayAnswer) {
mSoundPlayer.playSounds(Sound.SOUNDS_ANSWER);
if (mPrefUseTimer) {
if (mUseTimer) {
mUseTimerDynamicMS = mSoundPlayer.getSoundsLength(Sound.SOUNDS_ANSWER);
}
} else { // question is displayed
mSoundPlayer.playSounds(Sound.SOUNDS_QUESTION);
// If the user wants to show the answer automatically
if (mPrefUseTimer) {
if (mUseTimer) {
mUseTimerDynamicMS = mSoundPlayer.getSoundsLength(Sound.SOUNDS_QUESTION_AND_ANSWER);
}
}
Expand Down
18 changes: 18 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ private void cacheValues() {
mValues.put("revIvlFct", Integer.toString((int) (revOptions.getDouble("ivlFct") * 100)));
mValues.put("revMaxIvl", revOptions.getString("maxIvl"));
mValues.put("revBury", Boolean.toString(revOptions.optBoolean("bury", true)));

mValues.put("revUseGeneralTimeoutSettings", Boolean.toString(revOptions.optBoolean("useGeneralTimeoutSettings", true)));
mValues.put("revTimeoutAnswer", Boolean.toString(revOptions.optBoolean("timeoutAnswer", false)));
mValues.put("revTimeoutAnswerSeconds", Integer.toString(revOptions.optInt("timeoutAnswerSeconds", 6)));
mValues.put("revTimeoutQuestionSeconds", Integer.toString(revOptions.optInt("timeoutQuestionSeconds", 60)));

// lapse
JSONObject lapOptions = mOptions.getJSONObject("lapse");
mValues.put("lapSteps", StepsPreference.convertFromJSON(lapOptions.getJSONArray("delays")));
Expand Down Expand Up @@ -228,6 +234,18 @@ public boolean commit() {
case "revBury":
mOptions.getJSONObject("rev").put("bury", value);
break;
case "revUseGeneralTimeoutSettings":
mOptions.getJSONObject("rev").put("useGeneralTimeoutSettings", value);
break;
case "revTimeoutAnswer":
mOptions.getJSONObject("rev").put("timeoutAnswer", value);
break;
case "revTimeoutAnswerSeconds":
mOptions.getJSONObject("rev").put("timeoutAnswerSeconds", value);
break;
case "revTimeoutQuestionSeconds":
mOptions.getJSONObject("rev").put("timeoutQuestionSeconds", value);
break;
case "lapMinIvl":
mOptions.getJSONObject("lapse").put("minInt", value);
break;
Expand Down
27 changes: 27 additions & 0 deletions AnkiDroid/src/main/res/xml/deck_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,33 @@
android:key="revBury"
android:summary="@string/deck_conf_rev_bury_summ"
android:title="@string/deck_conf_rev_bury" />

<CheckBoxPreference
android:defaultValue="true"
android:disableDependentsState="true"
android:key="revUseGeneralTimeoutSettings"
android:title="Use general 'Automatic display answer' settings" />
<CheckBoxPreference
android:defaultValue="false"
android:disableDependentsState="false"
android:dependency="revUseGeneralTimeoutSettings"
android:key="revTimeoutAnswer"
android:summary="@string/timeout_answer_summ"
android:title="@string/timeout_answer_text" />
<com.ichi2.ui.SeekBarPreference
android:defaultValue="6"
android:dependency="revTimeoutAnswer"
android:key="revTimeoutAnswerSeconds"
android:max="30"
android:summary="@string/timeout_answer_seconds_summ"
android:title="@string/timeout_answer_seconds" />
<com.ichi2.ui.SeekBarPreference
android:defaultValue="60"
android:dependency="revTimeoutAnswer"
android:key="revTimeoutQuestionSeconds"
android:max="60"
android:summary="@string/timeout_question_seconds_summ"
android:title="@string/timeout_question_seconds" />
</PreferenceScreen>
<PreferenceScreen android:title="@string/deck_conf_lps_cards" >
<com.ichi2.preferences.StepsPreference
Expand Down

0 comments on commit 3a7bea5

Please sign in to comment.