From 674ed9d7cf1b5787f8432ca826b1d64fb17c48b9 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Tue, 10 Sep 2019 15:14:50 +0200 Subject: [PATCH] Added option to repeat question immediately until gotten right --- .../jstudy/controller/SettingsController.java | 15 ++++----- .../jstudy/controller/TestController.java | 31 +++++++++++++++---- .../es/kauron/jstudy/model/AppConfig.java | 18 ++++++++--- .../es/kauron/jstudy/view/settings.fxml | 1 + .../resources/es/kauron/jstudy/view/test.fxml | 2 +- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/main/java/es/kauron/jstudy/controller/SettingsController.java b/src/main/java/es/kauron/jstudy/controller/SettingsController.java index fa53ac5..587e200 100644 --- a/src/main/java/es/kauron/jstudy/controller/SettingsController.java +++ b/src/main/java/es/kauron/jstudy/controller/SettingsController.java @@ -10,15 +10,16 @@ import java.util.ResourceBundle; public class SettingsController implements Initializable { @FXML - private JFXCheckBox repeatMistakes, showFeedback; + private JFXCheckBox repeatMistakes, showFeedback, repeatImmediately; @Override public void initialize(URL location, ResourceBundle resources) { - repeatMistakes.setSelected(AppConfig.repeatWrong); - repeatMistakes.selectedProperty().addListener((observable, old, value) -> AppConfig.repeatWrong = value); - showFeedback.setSelected(AppConfig.showFeedback); - showFeedback.selectedProperty().addListener((observable, old, value) -> AppConfig.showFeedback = value); + repeatImmediately.disableProperty().bind(repeatMistakes.selectedProperty().not()); + repeatImmediately.selectedProperty().bindBidirectional(AppConfig.repeatImmediately); + repeatMistakes.selectedProperty().bindBidirectional(AppConfig.repeatWrong); + showFeedback.selectedProperty().bindBidirectional(AppConfig.showFeedback); + repeatMistakes.selectedProperty().addListener((obj, o, n) -> { + if (!n) repeatImmediately.setSelected(false); + }); } - - } diff --git a/src/main/java/es/kauron/jstudy/controller/TestController.java b/src/main/java/es/kauron/jstudy/controller/TestController.java index e958620..0ce5e77 100644 --- a/src/main/java/es/kauron/jstudy/controller/TestController.java +++ b/src/main/java/es/kauron/jstudy/controller/TestController.java @@ -2,10 +2,12 @@ package es.kauron.jstudy.controller; import es.kauron.jstudy.model.AppConfig; import es.kauron.jstudy.model.TestItem; +import javafx.beans.property.SimpleBooleanProperty; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.geometry.Insets; +import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ProgressBar; import javafx.scene.control.TextField; @@ -24,13 +26,17 @@ public class TestController implements Initializable { private ProgressBar progress; @FXML private HBox feedback; + @FXML + private Button skipButton; + private SimpleBooleanProperty correctingError = new SimpleBooleanProperty(false); private List list; private int total, current = -1; private int done = 0, errors = 0; @Override public void initialize(URL url, ResourceBundle resourceBundle) { + skipButton.disableProperty().bind(correctingError); } void setList(List list) { @@ -59,29 +65,42 @@ public class TestController implements Initializable { } // Remove the question from the pool if the question was correctly answered or there is no repetition - if (right || !AppConfig.repeatWrong) { + if ((right && !correctingError.get()) || !AppConfig.repeatWrong.get()) { list.remove(current); - progress.setProgress(++done/(double)total); + progress.setProgress(++done / (double) total); progressLabel.setText(done + "/" + total); if (list.size() == 0) { - onEndAction(event); + onEndAction(null); return; } + chooseQuestion(); + } else if (!AppConfig.repeatImmediately.get()) { + chooseQuestion(); } - onSkipAction(event); + correctingError.set(!right && AppConfig.repeatImmediately.get()); + setQuestion(); } - @FXML - private void onSkipAction(ActionEvent event) { + private void chooseQuestion() { answer.setText(""); int previous = current; do current = (int) (Math.random() * list.size()); while (list.size() > 1 && current == previous); + } + + private void setQuestion() { + answer.setText(""); question.setText(list.get(current).getQuestion()); answer.requestFocus(); } + @FXML + private void onSkipAction(ActionEvent event) { + chooseQuestion(); + setQuestion(); + } + @FXML private void onEndAction(ActionEvent event) { answer.setText(""); diff --git a/src/main/java/es/kauron/jstudy/model/AppConfig.java b/src/main/java/es/kauron/jstudy/model/AppConfig.java index 26a277a..a0454a5 100644 --- a/src/main/java/es/kauron/jstudy/model/AppConfig.java +++ b/src/main/java/es/kauron/jstudy/model/AppConfig.java @@ -1,17 +1,21 @@ package es.kauron.jstudy.model; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; + import java.io.File; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; public class AppConfig { - public static boolean repeatWrong, showFeedback; + public static BooleanProperty repeatWrong, showFeedback, repeatImmediately; public static File lastDir; public static void save() { Preferences prefs = Preferences.userRoot(); - prefs.putBoolean("repeatWrong", repeatWrong); - prefs.putBoolean("showFeedback", showFeedback); + prefs.putBoolean("repeatWrong", repeatWrong.get()); + prefs.putBoolean("showFeedback", showFeedback.get()); + prefs.putBoolean("repeatImmediately", repeatImmediately.get()); prefs.put("lastDir", lastDir == null ? "" : lastDir.getAbsolutePath()); try { prefs.flush(); @@ -22,8 +26,12 @@ public class AppConfig { public static void load() { Preferences prefs = Preferences.userRoot(); - repeatWrong = prefs.getBoolean("repeatWrong", true); - showFeedback = prefs.getBoolean("showFeedback", true); + repeatWrong = new SimpleBooleanProperty(prefs.getBoolean("repeatWrong", true)); + showFeedback = new SimpleBooleanProperty(prefs.getBoolean("showFeedback", true)); + repeatImmediately = new SimpleBooleanProperty(prefs.getBoolean("repeatImmediately", false)); + repeatWrong.addListener((obj, o, n) -> save()); + showFeedback.addListener((obj, o, n) -> save()); + repeatImmediately.addListener((obj, o, n) -> save()); String dirPath = prefs.get("lastDir", ""); if (!dirPath.isEmpty()) lastDir = new File(dirPath); } diff --git a/src/main/resources/es/kauron/jstudy/view/settings.fxml b/src/main/resources/es/kauron/jstudy/view/settings.fxml index a0f191c..b74acfd 100644 --- a/src/main/resources/es/kauron/jstudy/view/settings.fxml +++ b/src/main/resources/es/kauron/jstudy/view/settings.fxml @@ -6,6 +6,7 @@ + diff --git a/src/main/resources/es/kauron/jstudy/view/test.fxml b/src/main/resources/es/kauron/jstudy/view/test.fxml index 3d035b2..9e3e59c 100644 --- a/src/main/resources/es/kauron/jstudy/view/test.fxml +++ b/src/main/resources/es/kauron/jstudy/view/test.fxml @@ -64,7 +64,7 @@