Skip to content
Snippets Groups Projects
Commit d6d3cf27 authored by Alexis Durgnat's avatar Alexis Durgnat :milky_way:
Browse files

Merge branch 'devel' of ssh://ssh.hesge.ch:10572/pirkl-poo-2018/tp-4 into devel

parents cfd39c37 e14fa5e4
No related branches found
No related tags found
1 merge request!21*poof* final version
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){
......@@ -29,6 +29,12 @@ public class Meteo {
*/
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":
......
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(
......
......@@ -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() {
......@@ -33,6 +35,10 @@ public class LeftJourney implements Event, Serializable {
return this.connection;
}
public String getWeatherToDestination(){
return weatherToDestination;
}
@Override
public String toString() {
// TODO
......
......@@ -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();
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment