Skip to content

Commit

Permalink
[Air quality] Fixing air quality is not displayed when it's saved wit…
Browse files Browse the repository at this point in the history
…h a different language

#1193
  • Loading branch information
wolfgang-ch committed Oct 17, 2023
1 parent 84a69ca commit 5e4b82c
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (C) 2023 Wolfgang Schramm and Contributors
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*******************************************************************************/
package net.tourbook.common.weather;

/**
* These names are saved in the database
*/
public enum AirQuality {

IsNotDefined, //

Good, //
Fair, //
Moderate, //
Poor, //
VeryPoor, //

}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public interface IWeather {
/**
* Text for the weather
*/
public static final String[] cloudText = new String[] {
public static final String[] cloudText = new String[] {

cloudIsNotDefined,

Expand All @@ -195,14 +195,14 @@ public interface IWeather {

};

public static final String airQualityIsNotDefined = Messages.Weather_AirQuality_0_IsNotDefined;
public static final String WEATHER_AIR_QUALITY_IS_NOT_DEFINED = Messages.Weather_AirQuality_0_IsNotDefined;

/**
* Text for the weather's air quality
*/
public static final String[] airQualityTexts = new String[] {
public static final String[] AIR_QUALITY_TEXTS = new String[] {

airQualityIsNotDefined,
WEATHER_AIR_QUALITY_IS_NOT_DEFINED,

Messages.Weather_AirQuality_1_Good,
Messages.Weather_AirQuality_2_Fair,
Expand All @@ -212,10 +212,24 @@ public interface IWeather {

};

/**
* Weather's air quality values which are saved in the db
*/
public static final AirQuality[] AIR_QUALITY = new AirQuality[] {

AirQuality.IsNotDefined,

AirQuality.Good,
AirQuality.Fair,
AirQuality.Moderate,
AirQuality.Poor,
AirQuality.VeryPoor
};

/**
* Icons for the weather
*/
public static final String[] cloudIcon = new String[] {
public static final String[] cloudIcon = new String[] {

UI.IMAGE_EMPTY_16,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void testManualTourUpload() {
tour.setWeather_Wind_Direction(267);
tour.setWeather_Precipitation(3);
tour.setWeather_Snowfall(1.3f);
tour.setWeather_AirQuality(IWeather.airQualityTexts[5]);
tour.setWeather_AirQuality(IWeather.AIR_QUALITY_TEXTS[5]);

selectedTours.add(tour);
stravaUploader.uploadTours(selectedTours);
Expand Down
10 changes: 5 additions & 5 deletions bundles/net.tourbook/src/net/tourbook/OtherMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ public class OtherMessages {
public static final String THEME_FONT_LOGGING_PREVIEW_TEXT = de.byteholder.geoclipse.preferences.Messages.Theme_Font_Logging_PREVIEW_TEXT;
public static final String THEME_FONT_LOGGING = de.byteholder.geoclipse.preferences.Messages.Theme_Font_Logging;

public static final String WEATHER_AIRQUAlITY_1_GOOD = net.tourbook.common.Messages.Weather_AirQuality_1_Good;
public static final String WEATHER_AIRQUAlITY_1_FAIR = net.tourbook.common.Messages.Weather_AirQuality_2_Fair;
public static final String WEATHER_AIRQUAlITY_1_MODERATE = net.tourbook.common.Messages.Weather_AirQuality_3_Moderate;
public static final String WEATHER_AIRQUAlITY_1_POOR = net.tourbook.common.Messages.Weather_AirQuality_4_Poor;
public static final String WEATHER_AIRQUAlITY_1_VERYPOOR = net.tourbook.common.Messages.Weather_AirQuality_5_VeryPoor;
public static final String WEATHER_AIR_QUAlITY_1_GOOD = net.tourbook.common.Messages.Weather_AirQuality_1_Good;
public static final String WEATHER_AIR_QUAlITY_2_FAIR = net.tourbook.common.Messages.Weather_AirQuality_2_Fair;
public static final String WEATHER_AIR_QUAlITY_3_MODERATE = net.tourbook.common.Messages.Weather_AirQuality_3_Moderate;
public static final String WEATHER_AIR_QUAlITY_4_POOR = net.tourbook.common.Messages.Weather_AirQuality_4_Poor;
public static final String WEATHER_AIR_QUAlITY_5_VERYPOOR = net.tourbook.common.Messages.Weather_AirQuality_5_VeryPoor;

// SET_FORMATTING_ON
}
12 changes: 6 additions & 6 deletions bundles/net.tourbook/src/net/tourbook/data/TourData.java
Original file line number Diff line number Diff line change
Expand Up @@ -10960,7 +10960,7 @@ public String getWeather_AirQuality() {

/**
* @return Returns the index for the air quality value in
* {@link IWeather#airQualityTexts} or 0 when the air quality
* {@link IWeather#AIR_QUALITY_TEXTS} or 0 when the air quality
* index is not defined
*/
public int getWeather_AirQuality_TextIndex() {
Expand Down Expand Up @@ -11274,11 +11274,11 @@ public boolean isSurfing_IsMinDistance() {

public boolean isTemperatureAvailable() {

return getWeather_Temperature_Average() != 0 ||
getWeather_Temperature_Max() != 0 ||
getWeather_Temperature_Min() != 0 ||
getWeather_Temperature_WindChill() != 0 ||
isWeatherDataFromProvider();
return getWeather_Temperature_Average() != 0
|| getWeather_Temperature_Max() != 0
|| getWeather_Temperature_Min() != 0
|| getWeather_Temperature_WindChill() != 0
|| isWeatherDataFromProvider();
}

public boolean isTimeSerieWithTimeZoneAdjustment() {
Expand Down
27 changes: 26 additions & 1 deletion bundles/net.tourbook/src/net/tourbook/database/TourDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import net.tourbook.ui.TourTypeFilter;
import net.tourbook.ui.TreeColumnFactory;
import net.tourbook.ui.UI;
import net.tourbook.weather.WeatherUtils;

import org.apache.derby.drda.NetworkServerControl;
import org.eclipse.core.runtime.IProgressMonitor;
Expand Down Expand Up @@ -112,7 +113,7 @@ public class TourDatabase {
* <li>/net.tourbook.export/format-templates/mt-1.0.vm</li>
* <li>net.tourbook.device.mt.MT_StAXHandler</li>
*/
private static final int TOURBOOK_DB_VERSION = 51;
private static final int TOURBOOK_DB_VERSION = 52;

// private static final int TOURBOOK_DB_VERSION = 51; // 23.8 ??????

Expand Down Expand Up @@ -6039,6 +6040,7 @@ private boolean updateDb__2_Data(final Connection conn, final SplashManager spla
updateDb_046_to_047_DataUpdate(conn, splashManager);
updateDb_049_To_050_DataUpdate(conn, splashManager);
updateDb_050_To_051_DataUpdate(conn, splashManager);
updateDb_051_To_052_DataUpdate(conn, splashManager);

updateDb__3_Data_Concurrent(conn, splashManager, new TourDataUpdate_047_to_048());

Expand Down Expand Up @@ -9880,6 +9882,29 @@ private void updateDb_050_To_051_DataUpdate(final Connection conn, final SplashM
updateVersionNumber_20_AfterDataUpdate(conn, dbDataVersion, startTime);
}

/**
* @param conn
* @param splashManager
*
* @throws SQLException
*/
private void updateDb_051_To_052_DataUpdate(final Connection conn, final SplashManager splashManager) throws SQLException {

final long startTime = System.currentTimeMillis();

final int dbDataVersion = 52;

if (getDbVersion(conn, TABLE_DB_VERSION_DATA) >= dbDataVersion) {

// data version is higher -> nothing to do
return;
}

WeatherUtils.dbDataUpdate_052();

updateVersionNumber_20_AfterDataUpdate(conn, dbDataVersion, startTime);
}

private void updateMonitor(final SplashManager splashManager, final int newDbVersion) {

if (splashManager != null) {
Expand Down
2 changes: 1 addition & 1 deletion bundles/net.tourbook/src/net/tourbook/tour/TourInfoUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,7 @@ private void updateUI() {

// Air Quality
final String airQuality = _tourData.getWeather_AirQuality();
if (StringUtils.hasContent(airQuality) && !airQuality.equals(IWeather.airQualityIsNotDefined)) {
if (StringUtils.hasContent(airQuality) && !airQuality.equals(IWeather.WEATHER_AIR_QUALITY_IS_NOT_DEFINED)) {

_lblAirQuality.setText(airQuality);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ public class TourFilterManager {

private static final String[] VALUES_AIRQUALITY = {

IWeather.airQualityIsNotDefined,
OtherMessages.WEATHER_AIRQUAlITY_1_GOOD,
OtherMessages.WEATHER_AIRQUAlITY_1_FAIR,
OtherMessages.WEATHER_AIRQUAlITY_1_MODERATE,
OtherMessages.WEATHER_AIRQUAlITY_1_POOR,
OtherMessages.WEATHER_AIRQUAlITY_1_VERYPOOR
IWeather.WEATHER_AIR_QUALITY_IS_NOT_DEFINED,
OtherMessages.WEATHER_AIR_QUAlITY_1_GOOD,
OtherMessages.WEATHER_AIR_QUAlITY_2_FAIR,
OtherMessages.WEATHER_AIR_QUAlITY_3_MODERATE,
OtherMessages.WEATHER_AIR_QUAlITY_4_POOR,
OtherMessages.WEATHER_AIR_QUAlITY_5_VERYPOOR
};

private static final TourFilterFieldOperator[] FILTER_OPERATORS_TEXT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6870,12 +6870,12 @@ private void enableControls() {

private void fillAirQualityCombo() {

for (int index = 0; index < IWeather.airQualityTexts.length; index++) {
for (int index = 0; index < IWeather.AIR_QUALITY_TEXTS.length; index++) {

final TableItem tableItem = new TableItem(_tableComboWeather_AirQuality.getTable(), SWT.READ_ONLY);

// set the column text
tableItem.setText(IWeather.airQualityTexts[index]);
tableItem.setText(IWeather.AIR_QUALITY_TEXTS[index]);

Color backgroundColor = null;
Color foregroundColor = null;
Expand Down Expand Up @@ -7747,8 +7747,8 @@ private void onResize_TagContent() {
private void onSelect_AirQuality() {

final int airQuality_SelectionIndex = _tableComboWeather_AirQuality.getSelectionIndex();
String airQualityValue = IWeather.airQualityTexts[airQuality_SelectionIndex];
if (airQualityValue.equals(IWeather.airQualityIsNotDefined)) {
String airQualityValue = IWeather.AIR_QUALITY_TEXTS[airQuality_SelectionIndex];
if (airQualityValue.equals(IWeather.WEATHER_AIR_QUALITY_IS_NOT_DEFINED)) {
// replace invalid value
airQualityValue = UI.EMPTY_STRING;
}
Expand Down

0 comments on commit 5e4b82c

Please sign in to comment.