diff --git a/src/main/java/ch/hepia/api/weather/Meteo.java b/src/main/java/ch/hepia/api/weather/Meteo.java index 3ab134477c3c2d23cd199a8d0b565213a0f77a61..32258236835d81681048bb42babd28f1f1eb0c52 100644 --- a/src/main/java/ch/hepia/api/weather/Meteo.java +++ b/src/main/java/ch/hepia/api/weather/Meteo.java @@ -1,7 +1,7 @@ package ch.hepia.api.weather; -import org.json.JSONObject; import ch.hepia.config.AppConfig; +import org.json.JSONObject; public class Meteo { private double temperature; @@ -9,7 +9,7 @@ public class Meteo { /** * Constructor of Meteo class to obtain basic information on the weather - * @param temperature + * @param temperature La température actuelle * @param conditions */ private Meteo(double temperature, String conditions){ @@ -28,7 +28,13 @@ public class Meteo { * @return conditions */ public String getConditions(){ return conditions; } - + + /** + * Converts a meteo condition into one of our icons + * @return The path to our icon + * @apiNote Aussi appellé le switch des enfers. + * @apiNote Retourne sunny si ne trouve rien (politique du verre à moitié plein) + */ public String getConditionsIcon(){ switch (this.conditions) { case "Stratus": diff --git a/src/main/java/ch/hepia/config/AppConfig.java b/src/main/java/ch/hepia/config/AppConfig.java index fca8277ed0dbcef26532ae9000066914d7371267..9c6b30d30eb45a77f71c44932aabbadaa29309e8 100644 --- a/src/main/java/ch/hepia/config/AppConfig.java +++ b/src/main/java/ch/hepia/config/AppConfig.java @@ -1,9 +1,9 @@ package ch.hepia.config; -import java.util.List; - import javafx.scene.paint.Color; +import java.util.List; + /** * The variables of the app */ @@ -22,6 +22,7 @@ public final class AppConfig { public static final String ERROR_API_UNREACHABLE = "Impossible de contacter les services de transport Suisses."; + public static final String ERROR_API_MQ = "Une erreur s'est produite lors de la publication de cet évènement."; public static final String DEFAULT_JOURNEY_TEXT = "Vous n'avez prévu aucun voyage pour le moment."; public static List<String> CHAT_COMMANDS = List.of( diff --git a/src/main/java/ch/hepia/events/LeftJourney.java b/src/main/java/ch/hepia/events/LeftJourney.java index 0ec8de362dd3b8134b0eb97aae75f0637abc6125..f9e389c68277d64298110a7ceaed7503fd69e827 100644 --- a/src/main/java/ch/hepia/events/LeftJourney.java +++ b/src/main/java/ch/hepia/events/LeftJourney.java @@ -14,15 +14,17 @@ public class LeftJourney implements Event, Serializable { private static final long serialVersionUID = 0xAEF34565674L; private User user; private Connection connection; + private String weatherToDestination; /** * Main constructor * @param user The user triggering the event * @param connection The sections of the journey */ - public LeftJourney(User user, Connection connection){ + public LeftJourney(User user, Connection connection, String weatherToDestination){ this.user = user; this.connection = connection; + this.weatherToDestination = weatherToDestination; } public User getUser() { @@ -32,7 +34,11 @@ public class LeftJourney implements Event, Serializable { public Connection getConnection() { return this.connection; } - + + public String getWeatherToDestination(){ + return weatherToDestination; + } + @Override public String toString() { // TODO diff --git a/src/main/java/ch/hepia/ui/MainWindowController.java b/src/main/java/ch/hepia/ui/MainWindowController.java index 28d7660d8296a276d23d204e4a32dc1ca4045fd6..116426345cd402cfea2d07352102862a6e8f0bf5 100644 --- a/src/main/java/ch/hepia/ui/MainWindowController.java +++ b/src/main/java/ch/hepia/ui/MainWindowController.java @@ -261,8 +261,8 @@ public class MainWindowController implements Initializable { * Leaves a journey and broadcast it * @param app The app context */ - private void leaveJourney(AppContext app){ - app.getMessageManager().sendLeftJourney(new LeftJourney(app.getUser().get(), currentJourney)); + private void leaveJourney(AppContext app, String weatherIcon){ + app.getMessageManager().sendLeftJourney(new LeftJourney(app.getUser().get(), currentJourney, weatherIcon)); currentJourneyLabel.setText(AppConfig.DEFAULT_JOURNEY_TEXT); try { currentJourney = new Connection.EmptyConnection(); @@ -282,11 +282,12 @@ public class MainWindowController implements Initializable { private void createJourney(AppContext app, Pane pnl) throws IOException { Integer pos = Integer.parseInt(pnl.getId()); WeatherAPI api = new WeatherAPI(); + Connection connection = displayedConnections.get(pos); if (!(currentJourney instanceof Connection.EmptyConnection)){ - leaveJourney(app); + leaveJourney(app, api.getWeatherFrom(connection.getTo().toString()).getConditions()); } - Connection connection = displayedConnections.get(pos); - String weather = api.getWeatherFrom(connection.getFrom().toString()).getConditions(); + + String weather = api.getWeatherFrom(connection.getTo().toString()).getConditions(); JoinedJourney joinedJourney = new JoinedJourney(app.getUser().get(), connection, weather); app.getMessageManager().sendJoinedJourney(joinedJourney); @@ -305,7 +306,12 @@ public class MainWindowController implements Initializable { Optional<ButtonType> result = alert.showAndWait(); if (result.get().equals(oui)){ - leaveJourney(app); + try { + leaveJourney(app, api.getWeatherFrom(connection.getTo().toString()).getConditions()); + } catch (IOException e) { + showSadMessage(AppConfig.ERROR_API_MQ); + e.printStackTrace(); + } } }); } @@ -472,7 +478,7 @@ public class MainWindowController implements Initializable { try { createJourney(app, pnl); } catch (IOException ex){ - showSadMessage("Une erreur s'est produite lors de la publication de cet évènement."); + showSadMessage(AppConfig.ERROR_API_MQ); ex.printStackTrace(); } });