Skip to content

Commit

Permalink
[Tour Blog] Separated weather common values with a new line instead o…
Browse files Browse the repository at this point in the history
…f being on the same line as the last hour values
  • Loading branch information
wolfgang-ch committed Mar 16, 2023
1 parent 2caf69a commit 9670c32
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 62 deletions.
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions bundles/net.tourbook/src/net/tourbook/Messages.java
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions bundles/net.tourbook/src/net/tourbook/messages.properties
Expand Up @@ -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.
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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)) {

Expand Down
137 changes: 78 additions & 59 deletions bundles/net.tourbook/src/net/tourbook/weather/WeatherUtils.java
Expand Up @@ -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<String> weatherDataList = new ArrayList<>();
final List<String> weatherHourValues = new ArrayList<>();
final List<String> 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);
}
}

Expand All @@ -172,100 +181,110 @@ 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);
}
}

// Wind
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);

This comment has been minimized.

Copy link
@wolfgang-ch

wolfgang-ch Mar 16, 2023

Author Collaborator

Moved the common weather values in the tour blog into a separate line, in the tour log it's still on the same line.

Reordered min/max values and exchanged text and value for some data to have the same layout as the hour values

image

This comment has been minimized.

Copy link
@FJBDev

FJBDev Mar 20, 2023

Collaborator

I don't like it because now, for my 1-line weather, it's not in 1 line anymore and the cloud type is on its own line
Before:
image

After:

image

This comment has been minimized.

Copy link
@wolfgang-ch

wolfgang-ch Mar 23, 2023

Author Collaborator

The issue depended on the the setting, if the weather is saved in the description

This fix e4b7fd9 is now working this way

image

image


return weatherData;
}
Expand Down

0 comments on commit 9670c32

Please sign in to comment.