kopia lustrzana https://github.com/SP8EBC/MeteoSystem
showing NOT_AVALIABLE parameters in red
rodzic
6566b24b15
commit
6e57412b1f
|
@ -1,7 +1,9 @@
|
|||
package cc.pogoda.mobile.pogodacc.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.TypedValue;
|
||||
|
@ -28,6 +30,8 @@ public class StationDetailsSummaryActivity extends AppCompatActivity {
|
|||
|
||||
elems = new StationSummaryActElements();
|
||||
|
||||
int color = ContextCompat.getColor(this, android.R.color.secondary_text_light);
|
||||
|
||||
Summary summary = null;
|
||||
SummaryDao summary_dao = new SummaryDao();
|
||||
|
||||
|
@ -54,6 +58,9 @@ public class StationDetailsSummaryActivity extends AppCompatActivity {
|
|||
elems.humidity_val = findViewById(R.id.textViewHumidityValue);
|
||||
elems.message = findViewById(R.id.textViewSummaryMessage);
|
||||
|
||||
elems.goodColor = color;
|
||||
elems.badColor = Color.RED;
|
||||
|
||||
// get the summary data for this station
|
||||
summary = summary_dao.getStationSummary(station.getSystemName());
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package cc.pogoda.mobile.pogodacc.activity.updater;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.os.Handler;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -8,7 +10,10 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
import cc.pogoda.mobile.pogodacc.R;
|
||||
import cc.pogoda.mobile.pogodacc.dao.AvailableParametersDao;
|
||||
import cc.pogoda.mobile.pogodacc.dao.SummaryDao;
|
||||
import cc.pogoda.mobile.pogodacc.type.web.AvailableParametersWeb;
|
||||
import cc.pogoda.mobile.pogodacc.type.web.QualityFactor;
|
||||
import cc.pogoda.mobile.pogodacc.type.web.Summary;
|
||||
|
||||
|
@ -33,6 +38,11 @@ public class FavouritesStationDetailsUpdater implements Runnable {
|
|||
*/
|
||||
private SummaryDao dao = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private AvailableParametersDao availableParametersDao = null;
|
||||
|
||||
/**
|
||||
* Not sure if this is really required but just to be sure that updater won't be started
|
||||
* after the activity had been torn down.
|
||||
|
@ -43,6 +53,7 @@ public class FavouritesStationDetailsUpdater implements Runnable {
|
|||
handler = _handler;
|
||||
dao = new SummaryDao();
|
||||
stationsToUpdate = new HashMap<>();
|
||||
availableParametersDao = new AvailableParametersDao();
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
|
@ -57,6 +68,7 @@ public class FavouritesStationDetailsUpdater implements Runnable {
|
|||
stationsToUpdate.put(_station_system_name, _tv);
|
||||
}
|
||||
|
||||
@SuppressLint("ResourceAsColor")
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
|
@ -78,15 +90,18 @@ public class FavouritesStationDetailsUpdater implements Runnable {
|
|||
// query web service for station data
|
||||
Summary summary = dao.getStationSummary(stationSystemName);
|
||||
|
||||
// query for available parameters
|
||||
AvailableParametersWeb params = availableParametersDao.getAvaliableParamsByStationName(stationSystemName);
|
||||
|
||||
// if data has been collected
|
||||
if (summary != null) {
|
||||
String str;
|
||||
|
||||
// check if this station transmits wind information
|
||||
if (summary.wind_qf_native.equals(QualityFactor.FULL) || summary.wind_qf_native.equals(QualityFactor.DEGRADED)) {
|
||||
if (params.hasWind) {
|
||||
|
||||
// check if station transmits humidity
|
||||
if (summary.humidity_qf_native.equals(QualityFactor.FULL) || summary.humidity_qf_native.equals(QualityFactor.DEGRADED)) {
|
||||
if (params.hasHumidity) {
|
||||
str = String.format("%s %d%% %s %s max %s", summary.getTemperatureStr(false, true), summary.humidity, summary.getWindDirStr(), summary.getWindspeedStr(false), summary.getWindgustsStr(false));
|
||||
}
|
||||
else {
|
||||
|
@ -94,7 +109,7 @@ public class FavouritesStationDetailsUpdater implements Runnable {
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (summary.humidity_qf_native.equals(QualityFactor.FULL) || summary.humidity_qf_native.equals(QualityFactor.DEGRADED)) {
|
||||
if (params.hasHumidity) {
|
||||
str = String.format("%s %d%%", summary.getTemperatureStr(false, true), summary.humidity);
|
||||
}
|
||||
else {
|
||||
|
@ -105,6 +120,16 @@ public class FavouritesStationDetailsUpdater implements Runnable {
|
|||
|
||||
// update text view on the favourites list
|
||||
toUpdate.setText(str);
|
||||
|
||||
if ( (params.hasHumidity && summary.humidity_qf_native.equals(QualityFactor.NOT_AVALIABLE)) ||
|
||||
(summary.temperature_qf_native.equals(QualityFactor.NOT_AVALIABLE)) ||
|
||||
(params.hasWind && summary.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)))
|
||||
{
|
||||
toUpdate.setTextColor(Color.RED);
|
||||
}
|
||||
else {
|
||||
toUpdate.setTextColor(androidx.activity.R.color.secondary_text_default_material_light);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import cc.pogoda.mobile.pogodacc.R;
|
|||
import cc.pogoda.mobile.pogodacc.activity.handler.AllStationsActRecyclerViewButtonClickEvent;
|
||||
import cc.pogoda.mobile.pogodacc.activity.updater.FavouritesStationDetailsUpdater;
|
||||
import cc.pogoda.mobile.pogodacc.activity.view.AllStationsActRecyclerViewHolder;
|
||||
import cc.pogoda.mobile.pogodacc.dao.AvailableParametersDao;
|
||||
import cc.pogoda.mobile.pogodacc.dao.SummaryDao;
|
||||
import cc.pogoda.mobile.pogodacc.type.ParceableFavsCallReason;
|
||||
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
|
||||
|
@ -33,6 +34,8 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter<AllS
|
|||
ParceableFavsCallReason.Reason reason;
|
||||
|
||||
SummaryDao summaryDao;
|
||||
|
||||
AvailableParametersDao paramsDao;
|
||||
|
||||
FavouritesStationDetailsUpdater favsUpdater = null;
|
||||
|
||||
|
@ -43,6 +46,7 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter<AllS
|
|||
this.activity = parentActivity;
|
||||
this.reason = callReason;
|
||||
this.summaryDao = new SummaryDao();
|
||||
this.paramsDao = new AvailableParametersDao();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package cc.pogoda.mobile.pogodacc.dao;
|
||||
|
||||
import cc.pogoda.mobile.pogodacc.type.web.AvailableParametersWeb;
|
||||
import cc.pogoda.mobile.pogodacc.web.AvailableParametersConsumer;
|
||||
import cc.pogoda.mobile.pogodacc.web.RestClientConfig;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class AvailableParametersDao {
|
||||
|
||||
RestClientConfig restClient;
|
||||
|
||||
Response<AvailableParametersWeb> response = null;
|
||||
|
||||
String stationName;
|
||||
|
||||
class Worker implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
restClient = new RestClientConfig();
|
||||
|
||||
AvailableParametersConsumer consumer = restClient.getWeatherStationClient().create(AvailableParametersConsumer.class);
|
||||
|
||||
try {
|
||||
response = consumer.getParametersForStation(stationName).execute();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AvailableParametersWeb getAvaliableParamsByStationName(String name) {
|
||||
AvailableParametersWeb out = null;
|
||||
|
||||
stationName = name;
|
||||
|
||||
Thread t = new Thread(new Worker());
|
||||
|
||||
t.start();
|
||||
|
||||
try {
|
||||
t.join();
|
||||
|
||||
out = response.body();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package cc.pogoda.mobile.pogodacc.type;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import cc.pogoda.mobile.pogodacc.type.web.AvailableParametersWeb;
|
||||
import cc.pogoda.mobile.pogodacc.type.web.StationDefinition;
|
||||
|
||||
public class AvailableParameters implements Serializable {
|
||||
|
@ -33,6 +34,20 @@ public class AvailableParameters implements Serializable {
|
|||
rain = false;
|
||||
}
|
||||
|
||||
public static AvailableParameters fromWebData(AvailableParametersWeb w) {
|
||||
AvailableParameters out = new AvailableParameters();
|
||||
|
||||
out.humidity = w.hasHumidity;
|
||||
out.windSpeed = w.hasWind;
|
||||
out.windGusts = w.hasWind;
|
||||
out.windDirection = w.hasWind;
|
||||
out.qnh = w.hasQnh;
|
||||
out.airTemperature = true;
|
||||
out.rain = w.hasRain;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public static AvailableParameters fromStation(StationDefinition s) {
|
||||
AvailableParameters out = new AvailableParameters();
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@ public class StationSummaryActElements implements StationActivityElements {
|
|||
public TextView humidity_val = null;
|
||||
public TextView message = null;
|
||||
|
||||
public int goodColor = 0;
|
||||
public int badColor = 0;
|
||||
|
||||
public static String convertDegreesToDir(int directionInDegrees) {
|
||||
String out = null;
|
||||
|
||||
|
@ -108,43 +111,80 @@ public class StationSummaryActElements implements StationActivityElements {
|
|||
message.setTextColor(Color.argb(0xFF, 0xFF, 0x0, 0x0));
|
||||
}
|
||||
|
||||
if (!s.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE) && enabledForStation.windSpeed) {
|
||||
if (enabledForStation.windSpeed) {
|
||||
wind_speed_val.setText(String.format("%s", s.getWindspeedStr(true)));
|
||||
|
||||
if (goodColor != 0 && !s.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
|
||||
wind_speed_val.setTextColor(goodColor);
|
||||
}
|
||||
else if (badColor != 0) {
|
||||
wind_speed_val.setTextColor(badColor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
wind_speed_val.setText("---");
|
||||
}
|
||||
|
||||
if (!s.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE) && enabledForStation.windGusts) {
|
||||
if (enabledForStation.windGusts) {
|
||||
wind_gusts_val.setText(String.format("%s", s.getWindgustsStr(true)));
|
||||
|
||||
if (goodColor != 0 && !s.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
|
||||
wind_gusts_val.setTextColor(goodColor);
|
||||
}
|
||||
else if (badColor != 0) {
|
||||
wind_gusts_val.setText(badColor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
wind_gusts_val.setText("---");
|
||||
}
|
||||
|
||||
if (!s.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE) && enabledForStation.windDirection) {
|
||||
if (enabledForStation.windDirection) {
|
||||
wind_dir_val.setText(this.convertDegreesToDir(s.direction));
|
||||
|
||||
if (goodColor != 0 && !s.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
|
||||
wind_dir_val.setTextColor(goodColor);
|
||||
}
|
||||
else if (badColor != 0){
|
||||
wind_dir_val.setTextColor(badColor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
wind_dir_val.setText("---");
|
||||
}
|
||||
|
||||
if (!s.temperature_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
|
||||
temperature_val.setText(String.format("%s", s.getTemperatureStr(true, false)));
|
||||
temperature_val.setText(String.format("%s", s.getTemperatureStr(true, false)));
|
||||
|
||||
if (goodColor != 0 && !s.temperature_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
|
||||
temperature_val.setTextColor(goodColor);
|
||||
}
|
||||
else {
|
||||
temperature_val.setText("---");
|
||||
else if (badColor != 0){
|
||||
temperature_val.setTextColor(badColor);
|
||||
}
|
||||
// TODO
|
||||
if (!s.qnh_qf_native.equals(QualityFactor.NOT_AVALIABLE) && enabledForStation.qnh) {
|
||||
if (enabledForStation.qnh) {
|
||||
qnh_val.setText(String.format("%d hPa", s.qnh));
|
||||
|
||||
if (goodColor != 0 && !s.qnh_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
|
||||
qnh_val.setTextColor(goodColor);
|
||||
}
|
||||
else if (badColor != 0) {
|
||||
qnh_val.setTextColor(badColor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
qnh_val.setText("---");
|
||||
}
|
||||
|
||||
if (!s.humidity_qf_native.equals(QualityFactor.NOT_AVALIABLE) && enabledForStation.humidity) {
|
||||
if (enabledForStation.humidity) {
|
||||
humidity_val.setText(String.format("%d %%", s.humidity));
|
||||
|
||||
if (goodColor != 0 && !s.humidity_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
|
||||
humidity_val.setTextColor(goodColor);
|
||||
}
|
||||
else {
|
||||
humidity_val.setTextColor(badColor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
humidity_val.setText("---");
|
||||
|
|
|
@ -37,6 +37,9 @@ public class StationWindRoseActElements implements StationActivityElements {
|
|||
*/
|
||||
public TextView minAverage;
|
||||
|
||||
public int goodColor;
|
||||
public int badColor;
|
||||
|
||||
Activity activity;
|
||||
|
||||
public StationWindRoseActElements() {
|
||||
|
@ -126,8 +129,15 @@ public class StationWindRoseActElements implements StationActivityElements {
|
|||
}
|
||||
|
||||
// check if temperature is avaliable in input data set
|
||||
if (!no_data && !data.temperature_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
|
||||
if (!no_data) {
|
||||
temperature.setText(activity.getResources().getString(R.string.temperature_short) + '\n' + String.format("%s", data.getTemperatureStr(true, false)));
|
||||
|
||||
if (!data.temperature_qf_native.equals(QualityFactor.NOT_AVALIABLE) && goodColor != 0) {
|
||||
temperature.setTextColor(goodColor);
|
||||
}
|
||||
else if (badColor != 0) {
|
||||
temperature.setTextColor(badColor);
|
||||
}
|
||||
} else {
|
||||
temperature.setText(activity.getResources().getString(R.string.temperature_short) + '\n' + "---");
|
||||
}
|
||||
|
@ -139,6 +149,12 @@ public class StationWindRoseActElements implements StationActivityElements {
|
|||
pressure.setText(activity.getResources().getString(R.string.qnh) + ": " + String.format("%d hPa", data.qnh));
|
||||
maxGust.setText(activity.getResources().getString(R.string.max_1h_gust) + ": " + hour_max_gusts);
|
||||
minAverage.setText(activity.getResources().getString(R.string.min_1h_avg) + ": " + hour_min_avg);
|
||||
|
||||
if (goodColor != 0) {
|
||||
pressure.setTextColor(goodColor);
|
||||
maxGust.setTextColor(goodColor);
|
||||
minAverage.setTextColor(goodColor);
|
||||
}
|
||||
} else if (!no_data && old_data) {
|
||||
maxGust.setText(activity.getResources().getString(R.string.warning));
|
||||
maxGust.setTextColor(Color.RED);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package cc.pogoda.mobile.pogodacc.type.web;
|
||||
|
||||
public class AvailableParametersWeb {
|
||||
|
||||
public boolean hasWind;
|
||||
|
||||
public boolean hasQnh;
|
||||
|
||||
public boolean hasHumidity;
|
||||
|
||||
public boolean hasRain;
|
||||
|
||||
public byte telemetryVersion;
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package cc.pogoda.mobile.pogodacc.web;
|
||||
|
||||
import cc.pogoda.mobile.pogodacc.type.web.AvailableParametersWeb;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Path;
|
||||
|
||||
public interface AvailableParametersConsumer {
|
||||
|
||||
@GET("meteo_backend/station/{name}/availableParameters")
|
||||
Call<AvailableParametersWeb> getParametersForStation(@Path("name") String name);
|
||||
}
|
Ładowanie…
Reference in New Issue