From 3a7bea554181ff0a741c9f92dfee15f54e84c343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ac=C3=A1cio=20Correia?= Date: Sat, 1 Feb 2020 14:48:50 +0000 Subject: [PATCH] Added review options related to the automatic showing of answer specific to a group of decks --- .../ichi2/anki/AbstractFlashcardViewer.java | 49 +++++++++++++++---- .../main/java/com/ichi2/anki/DeckOptions.java | 18 +++++++ AnkiDroid/src/main/res/xml/deck_options.xml | 27 ++++++++++ 3 files changed, 85 insertions(+), 9 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java index 5552f5408ceb..33c06c05bdab 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java @@ -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; @@ -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) { @@ -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); @@ -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); @@ -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) { @@ -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); @@ -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); @@ -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()); } } @@ -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); } } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/DeckOptions.java b/AnkiDroid/src/main/java/com/ichi2/anki/DeckOptions.java index 81617f87c018..cf94122fea8b 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/DeckOptions.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/DeckOptions.java @@ -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"))); @@ -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; diff --git a/AnkiDroid/src/main/res/xml/deck_options.xml b/AnkiDroid/src/main/res/xml/deck_options.xml index d4c74636b3b3..112de9a99996 100644 --- a/AnkiDroid/src/main/res/xml/deck_options.xml +++ b/AnkiDroid/src/main/res/xml/deck_options.xml @@ -135,6 +135,33 @@ android:key="revBury" android:summary="@string/deck_conf_rev_bury_summ" android:title="@string/deck_conf_rev_bury" /> + + + + +