diff --git a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendFragment.java b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendFragment.java index 52911c8..296c938 100644 --- a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendFragment.java +++ b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendFragment.java @@ -1,5 +1,7 @@ package cc.pogoda.mobile.pogodacc.activity.trend.pressure; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -79,7 +81,15 @@ public class PressureTrendFragment extends Fragment { }); try { - pressureTrendViewModel.updateData(); + if (!pressureTrendViewModel.updateData()) { + AlertDialog.Builder builder = new AlertDialog.Builder(container.getContext()); + builder.setMessage(R.string.no_comm_with_backend); + builder.setPositiveButton(R.string.ok, (DialogInterface var1, int var2) -> { + var1.dismiss(); + }); + builder.create(); + builder.show(); + } } catch (Exception e) { ; diff --git a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendViewModel.java b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendViewModel.java index 1beba45..abde3b0 100644 --- a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendViewModel.java +++ b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/pressure/PressureTrendViewModel.java @@ -40,7 +40,7 @@ public class PressureTrendViewModel extends ViewModel { trendDao = new TrendDao(); } - public void updateData() { + public boolean updateData() { Trend trend = trendDao.getStationTrend(station); if (trend != null) { @@ -50,7 +50,7 @@ public class PressureTrendViewModel extends ViewModel { lastMeasuremenetTime.postValue(dt); stationName.postValue(trend.displayed_name); - if (!trend.current_qnh_qf.equals("NOT_AVALIABLE")) { + if (!trend.current_qnh_qf.equals("NOT_AVALIABLE") && !trend.current_qnh_qf.equals("NO_DATA")) { currentValue.postValue(String.format("%.1f hPa", trend.pressure_trend.current_value)); twoHoursValue.postValue(String.format("%.1f hPa", trend.pressure_trend.two_hours_value)); fourHoursValue.postValue(String.format("%.1f hPa", trend.pressure_trend.four_hours_value)); @@ -64,9 +64,15 @@ public class PressureTrendViewModel extends ViewModel { sixHoursValue.postValue("-- hPa"); eightHoursValue.postValue("-- hPa"); } + return true; } else { - + currentValue.postValue("-- hPa"); + twoHoursValue.postValue("-- hPa"); + fourHoursValue.postValue("-- hPa"); + sixHoursValue.postValue("-- hPa"); + eightHoursValue.postValue("-- hPa"); + return false; } } diff --git a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/temperature/TemperatureTrendFragment.java b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/temperature/TemperatureTrendFragment.java index 6608bce..2e4b141 100644 --- a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/temperature/TemperatureTrendFragment.java +++ b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/temperature/TemperatureTrendFragment.java @@ -1,5 +1,7 @@ package cc.pogoda.mobile.pogodacc.activity.trend.temperature; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -122,7 +124,15 @@ public class TemperatureTrendFragment extends Fragment { textViewTemperatureTrendEightHoursHVal.setText(s); }); - temperatureTrendViewModel.getData(); + if(!temperatureTrendViewModel.getData()) { + AlertDialog.Builder builder = new AlertDialog.Builder(container.getContext()); + builder.setMessage(R.string.no_comm_with_backend); + builder.setPositiveButton(R.string.ok, (DialogInterface var1, int var2) -> { + var1.dismiss(); + }); + builder.create(); + builder.show(); + } return root; } diff --git a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/temperature/TemperatureTrendViewModel.java b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/temperature/TemperatureTrendViewModel.java index 3d944ee..e1dac5e 100644 --- a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/temperature/TemperatureTrendViewModel.java +++ b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/temperature/TemperatureTrendViewModel.java @@ -105,7 +105,7 @@ public class TemperatureTrendViewModel extends ViewModel { eightHoursHumidityValue = new MutableLiveData(); } - public void getData() { + public boolean getData() { Trend trend = trendDao.getStationTrend(this.station); if (trend != null) { @@ -115,13 +115,9 @@ public class TemperatureTrendViewModel extends ViewModel { lastMeasuremenetTime.postValue(dt); displayedStationName.postValue(trend.displayed_name); - currentTemperatureValue.postValue(String.format("%.1f °C", trend.temperature_trend.current_value)); - twoHoursTemperatureValue.postValue(String.format("%.1f °C", trend.temperature_trend.two_hours_value)); - fourHoursTemperatureValue.postValue(String.format("%.1f °C", trend.temperature_trend.four_hours_value)); - sixHoursTemperatureValue.postValue(String.format("%.1f °C", trend.temperature_trend.six_hours_value)); - eightHoursTemperatureValue.postValue(String.format("%.1f °C", trend.temperature_trend.eight_hours_value)); + if (!trend.current_humidity_qf.equals("NOT_AVALIABLE") && !trend.current_humidity_qf.equals("NO_DATA")) { + - if (!trend.current_humidity_qf.equals("NOT_AVALIABLE")) { currentHumidityValue.postValue(String.format("%.1f %%", trend.humidity_trend.current_value)); twoHoursHumidityValue.postValue(String.format("%.1f %%", trend.humidity_trend.two_hours_value)); fourHoursHumidityValue.postValue(String.format("%.1f %%", trend.humidity_trend.four_hours_value)); @@ -129,15 +125,45 @@ public class TemperatureTrendViewModel extends ViewModel { eightHoursHumidityValue.postValue(String.format("%.1f %%", trend.humidity_trend.eight_hours_value)); } else { - currentHumidityValue.postValue(String.format("-- %%")); - twoHoursHumidityValue.postValue(String.format("-- %%")); - fourHoursHumidityValue.postValue(String.format("-- %%")); - sixHoursHumidityValue.postValue(String.format("-- %%")); - eightHoursHumidityValue.postValue(String.format("-- %%")); + + + currentHumidityValue.postValue("-- %"); + twoHoursHumidityValue.postValue("-- %"); + fourHoursHumidityValue.postValue("-- %"); + sixHoursHumidityValue.postValue("-- %"); + eightHoursHumidityValue.postValue("-- %"); + } + + if (!trend.current_temperature_qf.equals("NOT_AVALIABLE") && !trend.current_temperature_qf.equals("NO_DATA")) { + currentTemperatureValue.postValue(String.format("%.1f °C", trend.temperature_trend.current_value)); + twoHoursTemperatureValue.postValue(String.format("%.1f °C", trend.temperature_trend.two_hours_value)); + fourHoursTemperatureValue.postValue(String.format("%.1f °C", trend.temperature_trend.four_hours_value)); + sixHoursTemperatureValue.postValue(String.format("%.1f °C", trend.temperature_trend.six_hours_value)); + eightHoursTemperatureValue.postValue(String.format("%.1f °C", trend.temperature_trend.eight_hours_value)); + } + else { + currentTemperatureValue.postValue("-- °C"); + twoHoursTemperatureValue.postValue("-- °C"); + fourHoursTemperatureValue.postValue("-- °C"); + sixHoursTemperatureValue.postValue("-- °C"); + eightHoursTemperatureValue.postValue("-- °C"); + } + return true; } else { - ; + currentTemperatureValue.postValue("-- °C"); + twoHoursTemperatureValue.postValue("-- °C"); + fourHoursTemperatureValue.postValue("-- °C"); + sixHoursTemperatureValue.postValue("-- °C"); + eightHoursTemperatureValue.postValue("-- °C"); + + currentHumidityValue.postValue("-- %"); + twoHoursHumidityValue.postValue("-- %"); + fourHoursHumidityValue.postValue("-- %"); + sixHoursHumidityValue.postValue("-- %"); + eightHoursHumidityValue.postValue("-- %"); + return false; } } diff --git a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/wind/WindTrendFragment.java b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/wind/WindTrendFragment.java index 5de6a0b..77de1f9 100644 --- a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/wind/WindTrendFragment.java +++ b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/wind/WindTrendFragment.java @@ -1,5 +1,7 @@ package cc.pogoda.mobile.pogodacc.activity.trend.wind; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -114,7 +116,15 @@ public class WindTrendFragment extends Fragment { textViewWindTrendEightHoursGustsVal.setText(s); }); - windTrendViewModel.updateData(); + if (!windTrendViewModel.updateData()) { + AlertDialog.Builder builder = new AlertDialog.Builder(container.getContext()); + builder.setMessage(R.string.no_comm_with_backend); + builder.setPositiveButton(R.string.ok, (DialogInterface var1, int var2) -> { + var1.dismiss(); + }); + builder.create(); + builder.show(); + } return root; } diff --git a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/wind/WindTrendViewModel.java b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/wind/WindTrendViewModel.java index 8b806d9..32386cd 100644 --- a/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/wind/WindTrendViewModel.java +++ b/app/src/main/java/cc/pogoda/mobile/pogodacc/activity/trend/wind/WindTrendViewModel.java @@ -108,17 +108,18 @@ public class WindTrendViewModel extends ViewModel { } - public void updateData() { + public boolean updateData() { Trend trend = trendDao.getStationTrend(station); - // format the time and date according to current locale - String dt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).format(LocalDateTime.ofEpochSecond(trend.last_timestamp, 0, ZoneOffset.UTC).atOffset(ZoneOffset.UTC).atZoneSameInstant(ZoneOffset.systemDefault())); - if (trend != null) { + + // format the time and date according to current locale + String dt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).format(LocalDateTime.ofEpochSecond(trend.last_timestamp, 0, ZoneOffset.UTC).atOffset(ZoneOffset.UTC).atZoneSameInstant(ZoneOffset.systemDefault())); + lastMeasuremenetTime.postValue(dt); displayedStationName.postValue(trend.displayed_name); - if (!trend.current_wind_qf.equals("NOT_AVALIABLE")) { + if (!trend.current_wind_qf.equals("NOT_AVALIABLE") && !trend.current_wind_qf.equals("NO_DATA")) { if (AppConfiguration.replaceMsWithKnots) { // if knots currentMeanValue.postValue(String.format("%.0f kts", trend.average_wind_speed_trend.current_value)); @@ -159,6 +160,21 @@ public class WindTrendViewModel extends ViewModel { sixHoursGustValue.postValue("--"); eightHoursGustValue.postValue("--"); } + return true; + } + else { + currentMeanValue.postValue("--"); + twoHoursMeanValue.postValue("--"); + fourHoursMeanValue.postValue("--"); + sixHoursMeanValue.postValue("--"); + eightHoursMeanValue.postValue("--"); + + currentGustValue.postValue("--"); + twoHoursGustValue.postValue("--"); + fourHoursGustValue.postValue("--"); + sixHoursGustValue.postValue("--"); + eightHoursGustValue.postValue("--"); + return false; } } diff --git a/app/src/main/res/values-en-rUS/strings.xml b/app/src/main/res/values-en-rUS/strings.xml index 27a2890..6742aa0 100644 --- a/app/src/main/res/values-en-rUS/strings.xml +++ b/app/src/main/res/values-en-rUS/strings.xml @@ -78,4 +78,5 @@ Four hours ago Six hours ago Eight hours ago + No communication with a server \ No newline at end of file diff --git a/app/src/main/res/values-lv-rLV/strings.xml b/app/src/main/res/values-lv-rLV/strings.xml index 958166e..c69adf6 100644 --- a/app/src/main/res/values-lv-rLV/strings.xml +++ b/app/src/main/res/values-lv-rLV/strings.xml @@ -78,4 +78,5 @@ - - - + - \ No newline at end of file diff --git a/app/src/main/res/values-lv/strings.xml b/app/src/main/res/values-lv/strings.xml index 300516d..a9d07a9 100644 --- a/app/src/main/res/values-lv/strings.xml +++ b/app/src/main/res/values-lv/strings.xml @@ -78,5 +78,6 @@ - - - + - \ No newline at end of file diff --git a/app/src/main/res/values-pl-rPL/strings.xml b/app/src/main/res/values-pl-rPL/strings.xml index e1a14e7..f1299b9 100644 --- a/app/src/main/res/values-pl-rPL/strings.xml +++ b/app/src/main/res/values-pl-rPL/strings.xml @@ -78,4 +78,5 @@ Cztery godziny temu Sześć godzin temu Osiem godzin temu + Brak komunikacji z serwerem \ No newline at end of file diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 5189ac9..1e4080e 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -78,4 +78,5 @@ Cztery godziny temu Sześć godzin temu Osiem godzin temu + Brak komunikacji z serwerem \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ccbc3c8..285ffcd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -85,4 +85,5 @@ Four hours ago Six hours ago Eight hours ago + No communication with a server \ No newline at end of file