diff --git a/bundles/net.tourbook.cloud/src/net/tourbook/cloud/strava/StravaUploader.java b/bundles/net.tourbook.cloud/src/net/tourbook/cloud/strava/StravaUploader.java index 13d93aed78..55069c3713 100644 --- a/bundles/net.tourbook.cloud/src/net/tourbook/cloud/strava/StravaUploader.java +++ b/bundles/net.tourbook.cloud/src/net/tourbook/cloud/strava/StravaUploader.java @@ -193,7 +193,7 @@ private String buildFormattedDescription(final TourData tourData) { if (StringUtils.hasContent(description.toString())) { description.append(UI.SYSTEM_NEW_LINE); } - String weatherData = WeatherUtils.buildWeatherDataString(tourData, false, false, false); + String weatherData = WeatherUtils.buildWeatherDataString(tourData, false, false, false, false); if (StringUtils.hasContent(description.toString())) { weatherData = UI.NEW_LINE1 + weatherData; } diff --git a/bundles/net.tourbook/src/net/tourbook/Messages.java b/bundles/net.tourbook/src/net/tourbook/Messages.java index 1adf151af3..540b4df5e9 100644 --- a/bundles/net.tourbook/src/net/tourbook/Messages.java +++ b/bundles/net.tourbook/src/net/tourbook/Messages.java @@ -1257,6 +1257,7 @@ public class Messages extends NLS { public static String Log_HistoricalWeatherRetriever_001_WeatherData_Precipitation; public static String Log_HistoricalWeatherRetriever_001_WeatherData_Pressure; public static String Log_HistoricalWeatherRetriever_001_WeatherData_Snowfall; + public static String Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Avg; public static String Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_FeelsLike; public static String Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Max; public static String Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Min; diff --git a/bundles/net.tourbook/src/net/tourbook/messages.properties b/bundles/net.tourbook/src/net/tourbook/messages.properties index fa0316b556..6d78cadbce 100755 --- a/bundles/net.tourbook/src/net/tourbook/messages.properties +++ b/bundles/net.tourbook/src/net/tourbook/messages.properties @@ -1359,6 +1359,7 @@ Log_HistoricalWeatherRetriever_001_WeatherData_Humidity = humidity Log_HistoricalWeatherRetriever_001_WeatherData_Precipitation = precipitation Log_HistoricalWeatherRetriever_001_WeatherData_Pressure = pressure Log_HistoricalWeatherRetriever_001_WeatherData_Snowfall = snowfall +Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Avg = avg. Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_FeelsLike = feels like Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Max = max. Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Min = min. diff --git a/bundles/net.tourbook/src/net/tourbook/ui/views/TourBlogView.java b/bundles/net.tourbook/src/net/tourbook/ui/views/TourBlogView.java index ea767fe595..c051030364 100644 --- a/bundles/net.tourbook/src/net/tourbook/ui/views/TourBlogView.java +++ b/bundles/net.tourbook/src/net/tourbook/ui/views/TourBlogView.java @@ -413,7 +413,7 @@ private void create_24_Tour(final StringBuilder sb) { String tourTitle = _tourData.getTourTitle(); String tourDescription = _tourData.getTourDescription(); - String tourWeather = WeatherUtils.buildWeatherDataString(_tourData, true, true, true); + String tourWeather = WeatherUtils.buildWeatherDataString(_tourData, true, true, true, true); final boolean isDescription = tourDescription.length() > 0; final boolean isTitle = tourTitle.length() > 0; diff --git a/bundles/net.tourbook/src/net/tourbook/weather/TourWeatherRetriever.java b/bundles/net.tourbook/src/net/tourbook/weather/TourWeatherRetriever.java index 06402c3144..2d3e5f9e33 100644 --- a/bundles/net.tourbook/src/net/tourbook/weather/TourWeatherRetriever.java +++ b/bundles/net.tourbook/src/net/tourbook/weather/TourWeatherRetriever.java @@ -69,7 +69,7 @@ public static boolean retrieveWeatherData(final TourData tourData, TourLogManager.subLog_OK(TourManager.getTourDateTimeShort(tourData) + UI.SYMBOL_COLON + UI.SPACE + - WeatherUtils.buildWeatherDataString(tourData, true, true, true)); + WeatherUtils.buildWeatherDataString(tourData, true, true, true, false)); if (_prefStore.getBoolean(ITourbookPreferences.WEATHER_DISPLAY_FULL_LOG)) { diff --git a/bundles/net.tourbook/src/net/tourbook/weather/WeatherUtils.java b/bundles/net.tourbook/src/net/tourbook/weather/WeatherUtils.java index d9d5afacdc..1512186241 100644 --- a/bundles/net.tourbook/src/net/tourbook/weather/WeatherUtils.java +++ b/bundles/net.tourbook/src/net/tourbook/weather/WeatherUtils.java @@ -141,29 +141,38 @@ public static String buildFullWeatherDataString(final float temperatureValue, * Returns the weather data as a human readable string, depending on the * desired data. * Example: ☀ Sunny, 19°C, max. 26°C, min. 10°C, feels like 19°C, 6km/h from SSE, 34% humidity + * + * @param tourData + * @param isDisplayMinimumTemperature + * @param isDisplayMaximumTemperature + * @param isDisplayPressure + * @param isWeatherDataSeparatorNewLine + * @return */ public static String buildWeatherDataString(final TourData tourData, - final boolean displayMinimumTemperature, - final boolean displayMaximumTemperature, - final boolean displayPressure) { + final boolean isDisplayMinimumTemperature, + final boolean isDisplayMaximumTemperature, + final boolean isDisplayPressure, + final boolean isWeatherDataSeparatorNewLine) { - final List weatherDataList = new ArrayList<>(); + final List weatherHourValues = new ArrayList<>(); + final List weatherAvgValues = new ArrayList<>(); // Icon final String weatherIcon = getWeatherIcon(tourData.getWeatherIndex()); if (StringUtils.hasContent(weatherIcon)) { - weatherDataList.add(weatherIcon.trim()); + weatherHourValues.add(weatherIcon.trim()); } // Description final String weatherText = tourData.getWeather(); if (StringUtils.hasContent(weatherText)) { - if (weatherDataList.size() == 1) { - weatherDataList.set(0, weatherDataList.get(0) + UI.SPACE + weatherText); + if (weatherHourValues.size() == 1) { + weatherHourValues.set(0, weatherHourValues.get(0) + UI.SPACE + weatherText); } else { - weatherDataList.add(weatherText); + weatherHourValues.add(weatherText); } } @@ -172,41 +181,39 @@ public static String buildWeatherDataString(final TourData tourData, // Average temperature final float averageTemperature = tourData.getWeather_Temperature_Average(); if (averageTemperature != Float.MIN_VALUE) { - weatherDataList.add(FormatManager.formatTemperature(UI.convertTemperatureFromMetric(averageTemperature)) + - UI.UNIT_LABEL_TEMPERATURE); - } - // Maximum temperature - if (displayMaximumTemperature) { - - weatherDataList.add( - Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Max + - UI.SPACE + - FormatManager.formatTemperature( - UI.convertTemperatureFromMetric(tourData.getWeather_Temperature_Max())) + - UI.UNIT_LABEL_TEMPERATURE); + weatherAvgValues.add(Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Avg + + UI.SPACE + + FormatManager.formatTemperature(UI.convertTemperatureFromMetric(averageTemperature)) + + UI.UNIT_LABEL_TEMPERATURE); } // Minimum temperature - if (displayMinimumTemperature) { - - weatherDataList.add( - Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Min + - UI.SPACE + - FormatManager.formatTemperature( - UI.convertTemperatureFromMetric(tourData.getWeather_Temperature_Min())) + - UI.UNIT_LABEL_TEMPERATURE); + if (isDisplayMinimumTemperature) { + + weatherAvgValues.add(Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Min + + UI.SPACE + + FormatManager.formatTemperature(UI.convertTemperatureFromMetric(tourData.getWeather_Temperature_Min())) + + UI.UNIT_LABEL_TEMPERATURE); + } + + // Maximum temperature + if (isDisplayMaximumTemperature) { + + weatherAvgValues.add(Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_Max + + UI.SPACE + + FormatManager.formatTemperature(UI.convertTemperatureFromMetric(tourData.getWeather_Temperature_Max())) + + UI.UNIT_LABEL_TEMPERATURE); } // Wind chill final float temperatureWindChill = tourData.getWeather_Temperature_WindChill(); if (temperatureWindChill != Float.MIN_VALUE) { - weatherDataList.add( - Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_FeelsLike + - UI.SPACE + - FormatManager.formatTemperature(UI.convertTemperatureFromMetric(temperatureWindChill)) + - UI.UNIT_LABEL_TEMPERATURE); + weatherAvgValues.add(Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Temperature_FeelsLike + + UI.SPACE + + FormatManager.formatTemperature(UI.convertTemperatureFromMetric(temperatureWindChill)) + + UI.UNIT_LABEL_TEMPERATURE); } } @@ -214,58 +221,70 @@ public static String buildWeatherDataString(final TourData tourData, final int windSpeed = tourData.getWeather_Wind_Speed(); if (windSpeed > 0) { - final String windDirection = tourData.getWeather_Wind_Direction() != -1 - ? UI.SPACE + - Messages.Log_HistoricalWeatherRetriever_001_WeatherData_WindDirection + - UI.SPACE + - getWindDirectionText(tourData.getWeather_Wind_Direction()) + final int weather_Wind_Direction = tourData.getWeather_Wind_Direction(); + + final String windDirection = weather_Wind_Direction != -1 + ? UI.SPACE + + Messages.Log_HistoricalWeatherRetriever_001_WeatherData_WindDirection + + UI.SPACE + + getWindDirectionText(weather_Wind_Direction) : UI.EMPTY_STRING; - weatherDataList.add(Math.round(UI.convertSpeed_FromMetric(windSpeed)) + - UI.UNIT_LABEL_SPEED + - windDirection); + + weatherAvgValues.add(Math.round(UI.convertSpeed_FromMetric(windSpeed)) + + UI.UNIT_LABEL_SPEED + + windDirection); } // Humidity final float humidity = tourData.getWeather_Humidity(); if (humidity > 0) { - weatherDataList.add((int) humidity + - UI.SYMBOL_PERCENTAGE + - UI.SPACE + - Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Humidity); + weatherAvgValues.add(Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Humidity + + UI.SPACE + + (int) humidity + + UI.SYMBOL_PERCENTAGE); } // Pressure final float weatherPressure = tourData.getWeather_Pressure(); - if (weatherPressure > 0 && displayPressure) { + if (weatherPressure > 0 && isDisplayPressure) { - weatherDataList.add(roundDoubleToFloat(weatherPressure) + - UI.UNIT_LABEL_PRESSURE_MBAR_OR_INHG + - UI.SPACE + - Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Pressure); + weatherAvgValues.add(Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Pressure + + UI.SPACE + + roundDoubleToFloat(weatherPressure) + + UI.UNIT_LABEL_PRESSURE_MBAR_OR_INHG); } // Precipitation final float precipitation = tourData.getWeather_Precipitation(); if (precipitation > 0) { - weatherDataList.add(Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Precipitation + - UI.SPACE + - roundDoubleToFloat(UI.convertPrecipitation_FromMetric(precipitation)) + - UI.UNIT_LABEL_DISTANCE_MM_OR_INCH); + weatherAvgValues.add(Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Precipitation + + UI.SPACE + + roundDoubleToFloat(UI.convertPrecipitation_FromMetric(precipitation)) + + UI.UNIT_LABEL_DISTANCE_MM_OR_INCH); } // Snowfall final float snowfall = tourData.getWeather_Snowfall(); if (snowfall > 0) { - weatherDataList.add(Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Snowfall + - UI.SPACE + - roundDoubleToFloat(UI.convertPrecipitation_FromMetric(snowfall)) + - UI.UNIT_LABEL_DISTANCE_MM_OR_INCH); + weatherAvgValues.add(Messages.Log_HistoricalWeatherRetriever_001_WeatherData_Snowfall + + UI.SPACE + + roundDoubleToFloat(UI.convertPrecipitation_FromMetric(snowfall)) + + UI.UNIT_LABEL_DISTANCE_MM_OR_INCH); } - final String weatherData = String.join(UI.COMMA_SPACE, weatherDataList); + final String weatherHourValuesJoined = String.join(UI.COMMA_SPACE, weatherHourValues); + final String weatherAvgValuesJoined = String.join(UI.COMMA_SPACE, weatherAvgValues); + + final String weatherDataSeparator = isWeatherDataSeparatorNewLine ? UI.NEW_LINE1 : UI.COMMA_SPACE; + + final String weatherData = weatherHourValuesJoined + + + (weatherAvgValuesJoined.length() == 0 + ? UI.EMPTY_STRING + : weatherDataSeparator + weatherAvgValuesJoined); return weatherData; }