more fixing of handling http errors during updating favourites list

fix/get-all-stations-hangout 0.14
Mateusz Lubecki 2022-05-03 19:56:00 +02:00
rodzic 1c7c805d58
commit 6bcdf9fdbb
10 zmienionych plików z 74 dodań i 22 usunięć

Wyświetl plik

@ -12,8 +12,8 @@ android {
applicationId "cc.pogoda.mobile.meteosystem"
minSdkVersion 24
targetSdkVersion 30
versionCode 13
versionName "0.13-beta"
versionCode 14
versionName "0.14-beta"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Wyświetl plik

@ -2,8 +2,6 @@ package cc.pogoda.mobile.meteosystem;
import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import com.jakewharton.threetenabp.AndroidThreeTen;
@ -17,10 +15,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import cc.pogoda.mobile.meteosystem.activity.updater.FavouritesStationSummaryUpdater;
import cc.pogoda.mobile.meteosystem.config.AppConfiguration;
import cc.pogoda.mobile.meteosystem.dao.AllStationsDao;
import cc.pogoda.mobile.meteosystem.file.ConfigurationFile;
import cc.pogoda.mobile.meteosystem.file.FavouritiesFile;
@ -68,7 +64,7 @@ public class Main extends Application {
/**
* This map stores summary for all favourites station
*/
private HashMap<String, Summary> stationSystemNameToSummary = null;
private HashMap<String, Summary> hashmapStationSystemNameToSummary = null;
public File getDirectory() {
return directory;
@ -82,8 +78,8 @@ public class Main extends Application {
return confFile;
}
public HashMap<String, Summary> getStationSystemNameToSummary() {
return stationSystemNameToSummary;
public HashMap<String, Summary> getHashmapStationSystemNameToSummary() {
return hashmapStationSystemNameToSummary;
}
@Override
@ -119,7 +115,7 @@ public class Main extends Application {
confFile.restoreFromFile();
stationSystemNameToSummary = new HashMap<>();
hashmapStationSystemNameToSummary = new HashMap<>();
fileNames = new FileNames(ctx);
@ -133,7 +129,7 @@ public class Main extends Application {
// recreate list of favorites
recreateListOfFavs();
favsSummaryUpdater = new FavouritesStationSummaryUpdater(stationSystemNameToSummary);
favsSummaryUpdater = new FavouritesStationSummaryUpdater(hashmapStationSystemNameToSummary);
favsSummaryUpdater.start(100);
@ -194,7 +190,7 @@ public class Main extends Application {
// as a list does not make a copy of the object. It (ArrayList) keeps
// only a reference to an object
stationSystemNameToSummary.put(fromAllStations.getSystemName(), null);
hashmapStationSystemNameToSummary.put(fromAllStations.getSystemName(), null);
}
}

Wyświetl plik

@ -101,7 +101,7 @@ public class StationDetailsSummaryActivity extends AppCompatActivity {
boolean onFavs = main.checkIsOnFavsList(station.getSystemName());
if (onFavs) {
valuesFromSummaryUpdater = new StationDetailsValuesOnActivityFromSummaryUpdater(elems, handler, station, main.getStationSystemNameToSummary());
valuesFromSummaryUpdater = new StationDetailsValuesOnActivityFromSummaryUpdater(elems, handler, station, main.getHashmapStationSystemNameToSummary());
if (handler != null && valuesFromSummaryUpdater != null) {
handler.post(valuesFromSummaryUpdater);

Wyświetl plik

@ -76,7 +76,7 @@ public class StationDetailsWindRoseActivity extends AppCompatActivity {
boolean onFavs = main.checkIsOnFavsList(station.getSystemName());
if (onFavs) {
fromSummaryUpdater = new StationDetailsValuesOnActivityFromSummaryUpdater(elements, handler, station, main.getStationSystemNameToSummary());
fromSummaryUpdater = new StationDetailsValuesOnActivityFromSummaryUpdater(elements, handler, station, main.getHashmapStationSystemNameToSummary());
if (handler != null && fromSummaryUpdater != null) {
handler.post(fromSummaryUpdater);

Wyświetl plik

@ -74,6 +74,8 @@ public class FavouritesStationDetailsOnListUpdater implements Runnable {
@Override
public void run() {
int nextExecutionDelay = 45000;
if (stationNameSummary != null && enabled && stationsToUpdate != null && stationsToUpdate.size() > 0) {
// get a set of all elements stored in the map
@ -137,10 +139,11 @@ public class FavouritesStationDetailsOnListUpdater implements Runnable {
}
else {
Logger.error("[FavouritesStationDetailsOnListUpdater][run][summary object is null!! Maybe the API responds exeptionally slow?]");
nextExecutionDelay = 3000;
}
}
handler.postDelayed(this, 3000);
handler.postDelayed(this, nextExecutionDelay);
}
}
}

Wyświetl plik

@ -51,6 +51,8 @@ public class FavouritesStationSummaryUpdater implements Runnable {
// check if map was set so something
if (map != null && map.size() > 0) {
Logger.debug("[FavouritesStationSummaryUpdater][run][map.size() = " + map.size() +"]");
// get a set of all stations from favourites
Set<Map.Entry<String, Summary>> _set_of_stations_names = map.entrySet();
@ -66,10 +68,13 @@ public class FavouritesStationSummaryUpdater implements Runnable {
Summary summary = summaryDao.getStationSummary(station_name);
Logger.debug("[FavouritesStationSummaryUpdater][run][station_name = " + station_name +"][summary.last_timestamp = " + summary.last_timestamp +"]");
// check if summary was returned (as it will not in case on HTTP 500 or something else)
if (summary != null) {
Logger.debug("[FavouritesStationSummaryUpdater][run][station_name = " + station_name + "][summary.last_timestamp = " + summary.last_timestamp + "]");
// put the summary back into the map
map.put(station_name, summary);
// put the summary back into the map
map.put(station_name, summary);
}
}

Wyświetl plik

@ -141,7 +141,7 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter<AllS
}
handler = new Handler(Looper.getMainLooper());
favsUpdater = new FavouritesStationDetailsOnListUpdater(handler, main.getStationSystemNameToSummary());
favsUpdater = new FavouritesStationDetailsOnListUpdater(handler, main.getHashmapStationSystemNameToSummary());
handler.postDelayed(favsUpdater, 100);
favsUpdater.setEnabled(true);

Wyświetl plik

@ -2,6 +2,8 @@ package cc.pogoda.mobile.meteosystem.dao;
import org.tinylog.Logger;
import java.io.IOException;
import cc.pogoda.mobile.meteosystem.type.web.AvailableParametersWeb;
import cc.pogoda.mobile.meteosystem.web.AvailableParametersConsumer;
import cc.pogoda.mobile.meteosystem.web.RestClientConfig;
@ -25,11 +27,27 @@ public class AvailableParametersDao {
try {
response = consumer.getParametersForStation(stationName).execute();
} catch (Exception e) {
} catch (IOException e) {
Logger.error("[AvailableParametersDao][Worker][IOException][e = " + e.getLocalizedMessage() +"]");
e.printStackTrace();
} catch (RuntimeException e) {
Logger.error("[AvailableParametersDao][Worker][RuntimeException][e = " + e.getLocalizedMessage() +"]");
e.printStackTrace();
}
catch (Exception e) {
Logger.error("[AvailableParametersDao][Worker][Exception][e = " + e.getLocalizedMessage() +"]");
e.printStackTrace();
}
if (response == null) {
Logger.error("[AvailableParametersDao][Worker][worker is done, response is null]");
}
else {
Logger.debug("[AvailableParametersDao][Worker][worker is done][response.code() = " + response.code() +"]");
}
}
}

Wyświetl plik

@ -32,12 +32,30 @@ public class SummaryDao {
SummaryConsumer consumer = restClient.getWeatherStationClient().create(SummaryConsumer.class);
try {
Logger.debug("[SummaryDao][Worker][station = " + station +"]");
response = consumer.getSummaryForStation(station).execute();
} catch (IOException e) {
Logger.error("[SummaryDao][Worker][IOException][e = " + e.getLocalizedMessage() +"]");
e.printStackTrace();
} catch (RuntimeException e) {
Logger.error("[SummaryDao][Worker][RuntimeException][e = " + e.getLocalizedMessage() +"]");
e.printStackTrace();
}
catch (Exception e) {
Logger.error("[SummaryDao][Worker][Exception][e = " + e.getLocalizedMessage() +"]");
e.printStackTrace();
}
if (response == null) {
Logger.error("[SummaryDao][Worker][worker is done, response is null]");
}
else {
Logger.debug("[SummaryDao][Worker][worker is done][response.code() = " + response.code() +"]");
}
}
}
@ -53,7 +71,7 @@ public class SummaryDao {
try {
// wait for the web service response
worker.join();
worker.join(11000);
// check if web service returned anything
if (response != null) {
@ -67,9 +85,17 @@ public class SummaryDao {
out.humidity_qf_native = QualityFactor.valueOf(out.humidity_qf);
out.qnh_qf_native = QualityFactor.valueOf(out.qnh_qf);
}
else {
Logger.error("[SummaryDao][getStationSummary][station = " + station +"][response.code() = " + response.code() +"][response body is nulll, probably HTTP error" +
"]");
}
}
else {
Logger.error("[SummaryDao][getStationSummary][station = " + station +"][response is null!!]");
}
} catch (InterruptedException e) {
e.printStackTrace();
Logger.error("[SummaryDao][getStationSummary][station = " + station +"][InterruptedException]");
}
return out;

Wyświetl plik

@ -8,6 +8,7 @@ import java.util.concurrent.TimeUnit;
import cc.pogoda.mobile.meteosystem.type.CustomLocalDateTime;
import cc.pogoda.mobile.meteosystem.web.deserializer.CustomLocalDateTimeDeserializer;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
@ -25,7 +26,10 @@ public class RestClientConfig {
builder.connectTimeout(20, TimeUnit.SECONDS);
builder.callTimeout(20, TimeUnit.SECONDS);
OkHttpClient client = builder.build();//new OkHttpClient(builder);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
OkHttpClient client = builder.addInterceptor(loggingInterceptor).build();//new OkHttpClient(builder);
out = new Retrofit.Builder().baseUrl("http://pogoda.cc:8080/").addConverterFactory(GsonConverterFactory.create(gson)).client(client).build();