diff --git a/src/main/java/es/kauron/estraba/controller/DashboardController.java b/src/main/java/es/kauron/estraba/controller/DashboardController.java index aad4c7c..de85431 100644 --- a/src/main/java/es/kauron/estraba/controller/DashboardController.java +++ b/src/main/java/es/kauron/estraba/controller/DashboardController.java @@ -37,7 +37,10 @@ import es.kauron.estraba.model.DataBundle; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.chart.AreaChart; import javafx.scene.chart.LineChart; import javafx.scene.chart.PieChart; @@ -46,8 +49,10 @@ import javafx.scene.control.Tab; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; +import javafx.stage.Stage; import jgpx.model.analysis.Chunk; +import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; @@ -62,7 +67,7 @@ public class DashboardController implements Initializable, MapComponentInitializ private AnchorPane root; @FXML - private Tab tabDashboard, tabMap, tabGraph, tabSettings; + private Tab tabDashboard, tabMap, tabGraph; @FXML private ImageView imgHR, imgSpeed, imgCadence, imgDate, imgDistance, imgElevation; @@ -92,6 +97,7 @@ public class DashboardController implements Initializable, MapComponentInitializ @Override public void initialize(URL location, ResourceBundle resources) { + mapView.setVisible(false); // populate map icons ((ImageView)elevationButton.getGraphic()).setImage(new Image(App.class.getResourceAsStream("img/elevation.png"))); ((ImageView)speedButton.getGraphic()).setImage(new Image(App.class.getResourceAsStream("img/speed.png"))); @@ -107,6 +113,19 @@ public class DashboardController implements Initializable, MapComponentInitializ imgElevation.setImage(new Image(App.class.getResourceAsStream("img/elevation.png"))); } + @FXML + private void loadFile() { + FXMLLoader loader = new FXMLLoader( + App.class.getResource("fxml/Splash.fxml"), App.GENERAL_BUNDLE); + Parent parent; + try { + parent = loader.load(); + ((Stage) root.getScene().getWindow()).setScene(new Scene(parent)); + } catch (IOException e) { + e.printStackTrace(); + } + } + @FXML private void onMapButton(ActionEvent event){ switch (((JFXButton)event.getSource()).getId()) { @@ -196,16 +215,12 @@ public class DashboardController implements Initializable, MapComponentInitializ coord[W] = Math.min(lon, coord[W]); pathArray.push(new LatLong(lat, lon)); }); - // Create and add the polyline using the array - // This polyline displays instantly with no problem - // TODO: add color with PolylineOptions.strokeColor("#ffff00") to match the color schemes of the app - // When using that method, the line does not load properly, it needs an update to the zoom to show up. map.addMarker(new Marker(new MarkerOptions() .position(new LatLong( chunks.get(0).getFirstPoint().getLatitude(), chunks.get(0).getFirstPoint().getLongitude())) .title("label.begin"))); - map.addMapShape(new Polyline(new PolylineOptions().path(pathArray))); + map.addMapShape(new Polyline(new PolylineOptions().path(pathArray).strokeColor("#fc4c02"))); map.addMarker(new Marker(new MarkerOptions() .position(new LatLong( chunks.get(chunks.size() - 1).getLastPoint().getLatitude(), diff --git a/src/main/java/es/kauron/estraba/controller/SplashController.java b/src/main/java/es/kauron/estraba/controller/SplashController.java index b199931..9dc1600 100644 --- a/src/main/java/es/kauron/estraba/controller/SplashController.java +++ b/src/main/java/es/kauron/estraba/controller/SplashController.java @@ -38,12 +38,17 @@ import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Parent; import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Dialog; import javafx.scene.control.Label; +import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.Dragboard; import javafx.scene.input.TransferMode; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.GridPane; +import javafx.scene.text.Text; import javafx.stage.FileChooser; import javafx.stage.Stage; @@ -78,6 +83,7 @@ public class SplashController implements Initializable{ private JFXSnackbar snackbar; private File file; + private int maxHR; @FXML private void loadGPXFile(ActionEvent event) throws Exception { @@ -93,15 +99,16 @@ public class SplashController implements Initializable{ } public void loadGPXFile(File file) { + maxHR = showHRDialog(); + if (maxHR < 0) errorLoading(); buttonLoad.setVisible(false); labelWelcome.setVisible(false); spinner.setVisible(true); - snackbar.registerSnackbarContainer(root); snackbar.show("Loading file", 5000); Thread th = new Thread(new Task() { @Override protected DataBundle call() throws Exception { - return DataBundle.loadFrom(file); + return DataBundle.loadFrom(file, maxHR); } @Override @@ -169,6 +176,7 @@ public class SplashController implements Initializable{ e.setDropCompleted(success); e.consume(); })); + snackbar.registerSnackbarContainer(root); } private void errorLoading() { @@ -177,5 +185,36 @@ public class SplashController implements Initializable{ spinner.setVisible(false); snackbar.show("Error loading file", 3000); } + + private int showHRDialog() { + Dialog dialog = new Dialog<>(); + dialog.setTitle("Input your maximum heart rate or age"); + GridPane grid = new GridPane(); + grid.setHgap(5); + grid.setVgap(2); + grid.addColumn(0, new Text("Heart rate:"), new Text("Age:")); + Spinner spinnerAge = new Spinner<>(18, 99, 25, 1); + Spinner spinnerHR = new Spinner<>(60, 202, 180, 5); + spinnerAge.valueProperty().addListener((obs, oldV, newV) -> + spinnerHR.setValueFactory(new SpinnerValueFactory + .IntegerSpinnerValueFactory(60, 202, 220 - newV, 5))); + spinnerHR.valueProperty().addListener((obs, old, newV) -> + spinnerAge.setValueFactory(new SpinnerValueFactory + .IntegerSpinnerValueFactory(18, 99, 220 - newV, 1))); + grid.addColumn(1, spinnerHR, spinnerAge); + Button buttonOk = new Button("Ok"); + buttonOk.setDefaultButton(true); + buttonOk.setOnAction(event -> { + dialog.setResult(spinnerHR.getValue()); + dialog.close(); + }); + grid.add(buttonOk, 1, 2); + dialog.getDialogPane().setContent(grid); + dialog.showAndWait(); + if (dialog.getResult() != null) + return dialog.getResult(); + else + return -1; + } } diff --git a/src/main/java/es/kauron/estraba/model/DataBundle.java b/src/main/java/es/kauron/estraba/model/DataBundle.java index 2a2a548..bb27f1c 100644 --- a/src/main/java/es/kauron/estraba/model/DataBundle.java +++ b/src/main/java/es/kauron/estraba/model/DataBundle.java @@ -55,7 +55,7 @@ public class DataBundle { public ObservableList pieData; public ObservableList chunks; - private DataBundle(TrackData track) { + private DataBundle(TrackData track, int maxHR) { HRAvg = track.getAverageHeartrate() + App.GENERAL_BUNDLE.getString("unit.bpm"); HRMax = track.getMaxHeartrate() + App.GENERAL_BUNDLE.getString("unit.bpm"); @@ -106,10 +106,10 @@ public class DataBundle { cadenceSeries.getData().add(new XYChart.Data<>(currentDistance, chunk.getAvgCadence())); String zone; - if (chunk.getAvgHeartRate() > 170) zone = App.GENERAL_BUNDLE.getString("zone.anaerobic"); - else if (chunk.getAvgHeartRate() > 150) zone = App.GENERAL_BUNDLE.getString("zone.threshold"); - else if (chunk.getAvgHeartRate() > 130) zone = App.GENERAL_BUNDLE.getString("zone.tempo"); - else if (chunk.getAvgHeartRate() > 110) zone = App.GENERAL_BUNDLE.getString("zone.endurance"); + if (chunk.getAvgHeartRate() > maxHR * .9) zone = App.GENERAL_BUNDLE.getString("zone.anaerobic"); + else if (chunk.getAvgHeartRate() > maxHR * .8) zone = App.GENERAL_BUNDLE.getString("zone.threshold"); + else if (chunk.getAvgHeartRate() > maxHR * .7) zone = App.GENERAL_BUNDLE.getString("zone.tempo"); + else if (chunk.getAvgHeartRate() > maxHR * .6) zone = App.GENERAL_BUNDLE.getString("zone.endurance"); else zone = App.GENERAL_BUNDLE.getString("zone.recovery"); boolean pieFound = false; @@ -117,13 +117,14 @@ public class DataBundle { if (d.getName().equals(zone)) { pieFound = true; d.setPieValue(d.getPieValue() + 1); + break; } } if (!pieFound) pieData.add( new PieChart.Data(zone, 1) ); } } - public static DataBundle loadFrom(File file) throws Exception { + public static DataBundle loadFrom(File file, int maxHR) throws Exception { JAXBElement jaxbElement; JAXBContext jaxbContext = JAXBContext.newInstance(GpxType.class, TrackPointExtensionT.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); @@ -131,6 +132,6 @@ public class DataBundle { GpxType gpx = (GpxType) jaxbElement.getValue(); if (gpx == null) throw new Exception(); - return new DataBundle(new TrackData(new Track(gpx.getTrk().get(0)))); + return new DataBundle(new TrackData(new Track(gpx.getTrk().get(0))), maxHR); } } diff --git a/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml b/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml index 9f53176..959399c 100644 --- a/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml +++ b/src/main/resources/es/kauron/estraba/fxml/Dashboard.fxml @@ -25,17 +25,26 @@ ~ --> - + + + - - - - - - - - + + + + + + + + + + + + + + + + @@ -201,7 +210,7 @@ - + @@ -346,18 +355,11 @@ - + + + + + @@ -365,7 +367,7 @@ - + @@ -456,8 +458,5 @@ - - -