diff --git a/src/main/java/es/kauron/estraba/controller/DashboardController.java b/src/main/java/es/kauron/estraba/controller/DashboardController.java index bbcca17..59be425 100644 --- a/src/main/java/es/kauron/estraba/controller/DashboardController.java +++ b/src/main/java/es/kauron/estraba/controller/DashboardController.java @@ -110,6 +110,9 @@ public class DashboardController implements Initializable, MapComponentInitializ loadTrack(bundle); } + private String randomMotivation() { + return App.GENERAL_BUNDLE.getString("label.welcome"); + } private void loadTrack(DataBundle bundle) { valueHRAvg.setText(bundle.HRAvg); valueHRMax.setText(bundle.HRMax); @@ -126,7 +129,6 @@ public class DashboardController implements Initializable, MapComponentInitializ valueElevation.setText(bundle.elevation); valueAscent.setText(bundle.ascent); valueDescent.setText(bundle.descent); - zoneChart.setData(bundle.pieData); // populate the charts diff --git a/src/main/java/es/kauron/estraba/controller/SplashController.java b/src/main/java/es/kauron/estraba/controller/SplashController.java index b5399ce..82b0cb4 100644 --- a/src/main/java/es/kauron/estraba/controller/SplashController.java +++ b/src/main/java/es/kauron/estraba/controller/SplashController.java @@ -50,8 +50,7 @@ public class SplashController implements Initializable{ private File file; @FXML - private void loadGPXFile(ActionEvent event) { - + private void loadGPXFile(ActionEvent event) throws Exception { buttonLoad.setVisible(false); labelWelcome.setVisible(false); spinner.setVisible(true); @@ -59,40 +58,42 @@ public class SplashController implements Initializable{ snackbar.show("Loading file", 5000); FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters().add( - new FileChooser.ExtensionFilter(App.GENERAL_BUNDLE.getString("app.extension.filter.name"), "*.gpx")); + new FileChooser.ExtensionFilter(App.GENERAL_BUNDLE.getString("app.extension"), "*.gpx")); file = fileChooser.showOpenDialog(root.getScene().getWindow()); if (file == null) { errorLoading(); return; } - Task task = new Task() { + + Task t = new Task() { @Override protected DataBundle call() throws Exception { - try { - updateValue(DataBundle.loadFrom(file)); - succeeded(); - } catch (IOException e) { - updateValue(null); - errorLoading(); - } - return getValue(); + DataBundle db = DataBundle.loadFrom(file); + System.out.println("done"); + updateProgress(1, 1); + return db; } }; - Thread t = new Thread(task); - t.setDaemon(true); - t.start(); - task.setOnSucceeded(state -> { - DataBundle bundle = (DataBundle) state.getSource().getValue(); + + t.setOnSucceeded(ev -> { + DataBundle bundle = t.getValue(); if (bundle == null) errorLoading(); FXMLLoader loader = new FXMLLoader( App.class.getResource("fxml/Dashboard.fxml"), App.GENERAL_BUNDLE); Parent parent = null; try { parent = loader.load(); - } catch (IOException e) {errorLoading();} + } catch (IOException e) { + errorLoading(); + } loader.getController().postInit(bundle); ((Stage) root.getScene().getWindow()).setScene(new Scene(parent)); }); + + Thread th = new Thread(t); + th.setDaemon(true); + th.start(); + } @Override diff --git a/src/main/java/es/kauron/estraba/model/DataBundle.java b/src/main/java/es/kauron/estraba/model/DataBundle.java index 367059e..8e5aa6e 100644 --- a/src/main/java/es/kauron/estraba/model/DataBundle.java +++ b/src/main/java/es/kauron/estraba/model/DataBundle.java @@ -26,15 +26,11 @@ public class DataBundle { public String HRAvg, HRMax, HRMin, speedAvg, speedMax, cadenceAvg, cadenceMax; public String date, time, activeTime, totalTime, distance, elevation, ascent, descent; - public XYChart.Series elevationSeries = new XYChart.Series<>(), - speedSeries = new XYChart.Series<>(), - hrSeries = new XYChart.Series<>(), - cadenceSeries = new XYChart.Series<>(); - public ObservableList pieData = FXCollections.emptyObservableList(); + public XYChart.Series elevationSeries, speedSeries, hrSeries, cadenceSeries; + public ObservableList pieData; public ObservableList chunks; public static DataBundle loadFrom(File file) throws Exception { - String name = file.getName(); JAXBElement jaxbElement; JAXBContext jaxbContext = JAXBContext.newInstance(GpxType.class, TrackPointExtensionT.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); @@ -46,8 +42,9 @@ public class DataBundle { } private DataBundle(TrackData track) { + HRAvg = track.getAverageHeartrate() + App.GENERAL_BUNDLE.getString("unit.bpm"); - HRMax = (track.getMaxHeartrate() + App.GENERAL_BUNDLE.getString("unit.bpm")); + HRMax = track.getMaxHeartrate() + App.GENERAL_BUNDLE.getString("unit.bpm"); HRMin = track.getMinHeartRate() + App.GENERAL_BUNDLE.getString("unit.bpm"); // speed is given as m/s @@ -77,6 +74,13 @@ public class DataBundle { chunks = track.getChunks(); double currentDistance = 0.0; double currentHeight = chunks.get(0).getFirstPoint().getElevation(); + + elevationSeries = new XYChart.Series<>(); + cadenceSeries = new XYChart.Series<>(); + hrSeries = new XYChart.Series<>(); + speedSeries = new XYChart.Series<>(); + pieData = FXCollections.observableArrayList(); + for (Chunk chunk : chunks) { currentDistance += chunk.getDistance(); if (chunk.getDistance() < DISTANCE_EPSILON) continue; diff --git a/src/main/resources/es/kauron/estraba/css/estraba.css b/src/main/resources/es/kauron/estraba/css/estraba.css new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml b/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml index 0b8f902..2d5eac0 100644 --- a/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml +++ b/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml @@ -61,7 +61,7 @@ - +