@Override public void onNext(Word word) { Timber.d("Got word " + word + " and this is the subscriber " + this); if (RANDOM.nextDouble() <= 0.25 || currentAvailableWords.isEmpty()) { word = targetWord; } if (targetWordLanguage.equals(ENGLISH)) { view.showOptionalWord(word.getTextSpa()); currentDisplayedWord = word.getTextSpa(); } else { view.showOptionalWord(word.getTextEng()); currentDisplayedWord = word.getTextEng(); } }
/** Choose the next target word and remove it from the available ones */ private void chooseTargetWord() { targetWord = currentAvailableWords.remove(RANDOM.nextInt(currentAvailableWords.size())); String targetTranslation; if (RANDOM.nextDouble() < 0.5) { targetTranslation = targetWord.getTextEng(); targetWordLanguage = ENGLISH; } else { targetTranslation = targetWord.getTextSpa(); targetWordLanguage = SPANISH; } bus.post(new NewTargetWordEvent(targetTranslation)); removeWordUseCase .remove(targetWord) .compose(schedulerTransformer.applySchedulers()) .subscribe(); }
/** Is the current optional word equal to the target word? */ private boolean isCurrentTranslationCorrect() { return currentDisplayedWord.equals(targetWord.getTextEng()) || currentDisplayedWord.equals(targetWord.getTextSpa()); }