1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-12-22 16:33:33 +01:00

Added timer for test

This commit is contained in:
Carlos Galindo 2019-09-13 00:01:58 +02:00
parent 7d835018e3
commit 93b7dce200
Signed by: kauron
GPG key ID: 83E68706DEE119A3

View file

@ -2,6 +2,7 @@ package es.kauron.jstudy.controller;
import es.kauron.jstudy.model.AppPrefs; import es.kauron.jstudy.model.AppPrefs;
import es.kauron.jstudy.model.TestItem; import es.kauron.jstudy.model.TestItem;
import javafx.application.Platform;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.*; import javafx.beans.property.*;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
@ -16,6 +17,8 @@ import javafx.scene.layout.HBox;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
public class TestController implements Initializable { public class TestController implements Initializable {
@FXML @FXML
@ -34,19 +37,30 @@ public class TestController implements Initializable {
private final IntegerProperty errors = new SimpleIntegerProperty(0); private final IntegerProperty errors = new SimpleIntegerProperty(0);
private final ObjectProperty<TestItem> item = new SimpleObjectProperty<>(); private final ObjectProperty<TestItem> item = new SimpleObjectProperty<>();
private final IntegerProperty done = new SimpleIntegerProperty(0); private final IntegerProperty done = new SimpleIntegerProperty(0);
// Time accounting
private final IntegerProperty seconds = new SimpleIntegerProperty(0);
private final IntegerProperty minutes = new SimpleIntegerProperty(0);
private final Timer timer = new Timer();
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
skipButton.disableProperty().bind(correctingError); skipButton.disableProperty().bind(correctingError);
feedback.visibleProperty().bind(AppPrefs.showFeedback); feedback.visibleProperty().bind(AppPrefs.showFeedback);
seconds.addListener((obj, o, n) -> {
if (n.intValue() == 60) {
minutes.set(minutes.get() + 1);
seconds.set(0);
}
});
} }
void setList(List<TestItem> list) { void setList(List<TestItem> list) {
this.list = list; this.list = list;
int total = list.size(); int total = list.size();
progressLabel.textProperty().bind(Bindings.format( progressLabel.textProperty().bind(Bindings.format(
String.format("%%.2f%%%% %%d / %d %%d mistakes", total), String.format("%%.2f%%%% %%d / %d %%d mistakes %%02d:%%02d", total),
done.multiply(100.0).divide(total), done, errors)); done.multiply(100.0).divide(total), done,
errors, minutes, seconds));
progress.progressProperty().bind(done.divide((double) total)); progress.progressProperty().bind(done.divide((double) total));
item.addListener((obj, o, n) -> { item.addListener((obj, o, n) -> {
if (o != null) { if (o != null) {
@ -55,6 +69,12 @@ public class TestController implements Initializable {
} }
question.setText(n.getQuestion()); question.setText(n.getQuestion());
}); });
timer.schedule(new TimerTask() {
@Override
public void run() {
Platform.runLater(() -> seconds.set(seconds.get() + 1));
}
}, 0, 1000);
onSkipAction(null); onSkipAction(null);
} }
@ -116,5 +136,6 @@ public class TestController implements Initializable {
answer.setText(""); answer.setText("");
answer.setDisable(true); answer.setDisable(true);
question.setText("That's it!"); question.setText("That's it!");
timer.cancel();
} }
} }