Skip to content

Commit

Permalink
refactor[auto answer]: extract Q/A display
Browse files Browse the repository at this point in the history
moves more behavior inside the object

Still not too well factored, but getting there
  • Loading branch information
david-allison authored and mikehardy committed Oct 13, 2021
1 parent 0ffc8d7 commit 331a8b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1900,15 +1900,7 @@ protected void displayCardQuestion(boolean reload) {
hideEaseButtons();

// If the user wants to show the answer automatically
if (mAutomaticAnswerSettings.useTimer()) {
if (mAutomaticAnswerSettings.autoAdvanceAnswer()) {
mAutomaticAnswerSettings.stopShowingAnswer();
if (!mSpeakText) {
long delay = mAutomaticAnswerSettings.getAnswerDelayMilliseconds() + mUseTimerDynamicMS;
mAutomaticAnswerSettings.delayedShowAnswer(delay);
}
}
}
mAutomaticAnswerSettings.onDisplayQuestion(!mSpeakText, mUseTimerDynamicMS);

Timber.i("AbstractFlashcardViewer:: Question successfully shown for card id %d", mCurrentCard.getId());
}
Expand Down Expand Up @@ -1950,15 +1942,7 @@ protected void displayCardAnswer() {
updateCard(CardAppearance.enrichWithQADiv(answer, true));
displayAnswerBottomBar();
// If the user wants to show the next question automatically
if (mAutomaticAnswerSettings.useTimer()) {
if (mAutomaticAnswerSettings.autoAdvanceQuestion()) {
mAutomaticAnswerSettings.stopShowingQuestion();
if (!mSpeakText) {
long delay = mAutomaticAnswerSettings.getQuestionDelayMilliseconds() + mUseTimerDynamicMS;
mAutomaticAnswerSettings.delayedShowQuestion(delay);
}
}
}
mAutomaticAnswerSettings.onDisplayAnswer(!mSpeakText, mUseTimerDynamicMS);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ class AutomaticAnswerSettings(
stopShowingQuestion()
}

fun onDisplayQuestion(reschedule: Boolean, additionalDelay: Long) {
if (!useTimer) return
if (!autoAdvanceAnswer) return

stopShowingAnswer()

if (!reschedule) return
val delay: Long = answerDelayMilliseconds + additionalDelay
delayedShowAnswer(delay)
}

fun onDisplayAnswer(reschedule: Boolean, additionalDelay: Long) {
if (!useTimer) return
if (!autoAdvanceQuestion) return

stopShowingQuestion()

if (!reschedule) return
val delay: Long = questionDelayMilliseconds + additionalDelay
delayedShowQuestion(delay)
}

interface AutomaticallyAnswered {
fun automaticShowAnswer()
fun automaticShowQuestion()
Expand Down

0 comments on commit 331a8b5

Please sign in to comment.