MeteoSystem/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/StationDetailsSummaryActivi...

163 wiersze
5.3 KiB
Java
Czysty Zwykły widok Historia

2021-12-10 10:21:06 +00:00
package cc.pogoda.mobile.meteosystem.activity;
2020-12-16 19:26:53 +00:00
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
2020-12-16 19:26:53 +00:00
2022-01-06 21:06:53 +00:00
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
2020-12-16 19:26:53 +00:00
import android.os.Bundle;
import android.os.Handler;
2021-11-26 23:20:53 +00:00
import android.util.TypedValue;
2020-12-16 19:26:53 +00:00
2022-01-06 21:06:53 +00:00
import org.tinylog.Logger;
import java.util.Locale;
import cc.pogoda.mobile.meteosystem.Main;
2021-12-10 10:21:06 +00:00
import cc.pogoda.mobile.meteosystem.R;
import cc.pogoda.mobile.meteosystem.activity.updater.StationDetailsValuesOnActivityFromFavsUpdater;
import cc.pogoda.mobile.meteosystem.activity.updater.StationDetailsValuesOnActivityUpdater;
import cc.pogoda.mobile.meteosystem.activity.updater.thread.StationSummaryUpdaterThread;
2022-01-06 21:06:53 +00:00
import cc.pogoda.mobile.meteosystem.config.AppConfiguration;
2021-12-10 10:21:06 +00:00
import cc.pogoda.mobile.meteosystem.dao.SummaryDao;
import cc.pogoda.mobile.meteosystem.type.StationSummaryActElements;
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
import cc.pogoda.mobile.meteosystem.type.web.Summary;
2020-12-16 19:26:53 +00:00
public class StationDetailsSummaryActivity extends AppCompatActivity {
StationSummaryActElements elems = null;
WeatherStation station = null;
StationSummaryUpdaterThread updaterThread = null;
StationDetailsValuesOnActivityUpdater valuesOnActUpdater = null;
StationDetailsValuesOnActivityFromFavsUpdater valuesFromFavsSummaryUpdater = null;
2020-12-16 19:26:53 +00:00
Handler handler = null;
Main main = null;
2020-12-16 19:26:53 +00:00
@Override
protected void onCreate(Bundle savedInstanceState) {
main = (Main)getApplication();
2020-12-16 19:26:53 +00:00
elems = new StationSummaryActElements();
int color = ContextCompat.getColor(this, android.R.color.secondary_text_light);
2020-12-16 19:26:53 +00:00
Summary summary = null;
SummaryDao summary_dao = new SummaryDao();
super.onCreate(savedInstanceState);
station = (WeatherStation) getIntent().getSerializableExtra("station");
Logger.info("[station.getSystemName() = " + station.getSystemName() +"]");
2022-01-06 21:06:53 +00:00
if (AppConfiguration.locale != null && !AppConfiguration.locale.equals("default") ) {
Logger.debug("[AppConfiguration.locale = " + AppConfiguration.locale + "]");
2022-01-06 21:06:53 +00:00
Locale locale = new Locale(AppConfiguration.locale);
Locale.setDefault(locale);
Resources resources = this.getResources();
Configuration config = resources.getConfiguration();
config.setLocale(locale);
resources.updateConfiguration(config, resources.getDisplayMetrics());
}
setContentView(R.layout.activity_station_details_summary);
2020-12-16 19:26:53 +00:00
elems.title = findViewById(R.id.textViewStationDetailsSummaryTitle);
elems.title.setText(station.getDisplayedName());
2021-11-26 23:20:53 +00:00
if (station.getDisplayedName().length() < 18) {
elems.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 38);
}
else {
elems.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
}
2020-12-16 19:26:53 +00:00
elems.wind_dir_val = findViewById(R.id.textViewWinddirValue);
elems.wind_gusts_val = findViewById(R.id.textViewWindGustsValue);
elems.wind_speed_val = findViewById(R.id.textViewWindSpeedValue);
elems.temperature_val = findViewById(R.id.textViewTemperatureValue);
elems.qnh_val = findViewById(R.id.textViewQnhVaue);
elems.humidity_val = findViewById(R.id.textViewHumidityValue);
elems.message = findViewById(R.id.textViewSummaryMessage);
2020-12-16 19:26:53 +00:00
elems.goodColor = color;
elems.badColor = Color.RED;
// create a handler to update station data in background
2020-12-16 19:26:53 +00:00
handler = new Handler();
// check if this station is on favourites list
boolean onFavs = main.checkIsOnFavsList(station.getSystemName());
2020-12-16 19:26:53 +00:00
if (onFavs) {
valuesFromFavsSummaryUpdater = new StationDetailsValuesOnActivityFromFavsUpdater(elems, handler, station, main.getHashmapFavStationSystemNameToSummary());
if (handler != null && valuesFromFavsSummaryUpdater != null) {
handler.post(valuesFromFavsSummaryUpdater);
}
2020-12-16 19:26:53 +00:00
}
else {
updaterThread = new StationSummaryUpdaterThread(station.getSystemName());
// create a copy of updater class for this station
valuesOnActUpdater = new StationDetailsValuesOnActivityUpdater(elems, handler, updaterThread, station);
if (handler != null && valuesOnActUpdater != null) {
updaterThread.start(50);
handler.postDelayed(valuesOnActUpdater, 500);
}
}
}
@Override
protected void onPause() {
super.onPause();
if (updaterThread != null) {
updaterThread.stop();
}
}
2020-12-16 19:26:53 +00:00
@Override
protected void onResume() {
super.onResume();
2020-12-16 19:26:53 +00:00
if (updaterThread != null) {
updaterThread.start(50);
}
2020-12-16 19:26:53 +00:00
}
@Override
protected void onStop() {
if (handler != null && valuesOnActUpdater != null) {
handler.removeCallbacks(valuesOnActUpdater);
2020-12-16 19:26:53 +00:00
}
if (updaterThread != null) {
updaterThread.stop();
}
2020-12-16 19:26:53 +00:00
super.onStop();
}
@Override
protected void onDestroy() {
if (updaterThread != null) {
updaterThread.stop();
}
super.onDestroy();
}
2020-12-16 19:26:53 +00:00
}