kopia lustrzana https://github.com/SP8EBC/MeteoSystem
better quality factors handling in trend activity
rodzic
091dd8c7d6
commit
3bb7bc5908
|
@ -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) {
|
||||
;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class TemperatureTrendViewModel extends ViewModel {
|
|||
eightHoursHumidityValue = new MutableLiveData<String>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,4 +78,5 @@
|
|||
<string name="h4_value">Four hours ago</string>
|
||||
<string name="h6_value">Six hours ago</string>
|
||||
<string name="h8_value">Eight hours ago</string>
|
||||
<string name="no_comm_with_backend">No communication with a server</string>
|
||||
</resources>
|
|
@ -78,4 +78,5 @@
|
|||
<string name="h4_value">-</string>
|
||||
<string name="h6_value">-</string>
|
||||
<string name="h8_value">-</string>
|
||||
<string name="no_comm_with_backend">-</string>
|
||||
</resources>
|
|
@ -78,5 +78,6 @@
|
|||
<string name="h4_value">-</string>
|
||||
<string name="h6_value">-</string>
|
||||
<string name="h8_value">-</string>
|
||||
<string name="no_comm_with_backend">-</string>
|
||||
|
||||
</resources>
|
|
@ -78,4 +78,5 @@
|
|||
<string name="h4_value">Cztery godziny temu</string>
|
||||
<string name="h6_value">Sześć godzin temu</string>
|
||||
<string name="h8_value">Osiem godzin temu</string>
|
||||
<string name="no_comm_with_backend">Brak komunikacji z serwerem</string>
|
||||
</resources>
|
|
@ -78,4 +78,5 @@
|
|||
<string name="h4_value">Cztery godziny temu</string>
|
||||
<string name="h6_value">Sześć godzin temu</string>
|
||||
<string name="h8_value">Osiem godzin temu</string>
|
||||
<string name="no_comm_with_backend">Brak komunikacji z serwerem</string>
|
||||
</resources>
|
|
@ -85,4 +85,5 @@
|
|||
<string name="h4_value">Four hours ago</string>
|
||||
<string name="h6_value">Six hours ago</string>
|
||||
<string name="h8_value">Eight hours ago</string>
|
||||
<string name="no_comm_with_backend">No communication with a server</string>
|
||||
</resources>
|
Ładowanie…
Reference in New Issue