Skip to content

Commit

Permalink
More automated forecast update fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbunny2008 committed Jan 5, 2019
1 parent 9859185 commit 3f0f697
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.odiousapps.weewxweather"
minSdkVersion 19
targetSdkVersion 28
versionCode 8019
versionName "0.8.19"
versionCode 8020
versionName "0.8.20"
}
buildTypes {
release {
Expand Down
40 changes: 24 additions & 16 deletions app/src/main/java/com/odiousapps/weewxweather/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ String[] processDarkSky(String data, boolean showHeader)
boolean metric = GetBoolPref("metric", true);
String desc;

long timestamp = (long) GetIntPref("rssCheck", 0) * 1000;
long timestamp = GetLongPref("rssCheck", 0) * 1000;
List<Day> days = new ArrayList<>();

try
Expand Down Expand Up @@ -926,7 +926,7 @@ String[] processMET(String data, boolean showHeader)

boolean metric = GetBoolPref("metric", true);
boolean use_icons = GetBoolPref("use_icons", false);
long timestamp = (long)GetIntPref("rssCheck", 0) * 1000;
long timestamp = GetLongPref("rssCheck", 0) * 1000;
String desc;
List<Day> days = new ArrayList<>();

Expand Down Expand Up @@ -2106,7 +2106,7 @@ String[] processOWM(String data, boolean showHeader)
String desc;

boolean metric = GetBoolPref("metric", true);
long timestamp = (long)GetIntPref("rssCheck", 0) * 1000;
long timestamp = GetLongPref("rssCheck", 0) * 1000;

try
{
Expand Down Expand Up @@ -2180,7 +2180,7 @@ String[] processYR(String data, boolean showHeader)
JSONObject location = jobj.getJSONObject("location");
desc = location.getString("name") + ", " + location.getString("country");

timestamp = (long)GetIntPref("rssCheck", 0) * 1000;
timestamp = GetLongPref("rssCheck", 0) * 1000;

JSONArray jarr = jobj.getJSONObject("forecast")
.getJSONObject("tabular")
Expand Down Expand Up @@ -3391,6 +3391,21 @@ void getForecast(boolean force)
return;
}

final long curtime = round(System.currentTimeMillis() / 1000);

if(GetStringPref("forecastData", "").equals("") || GetLongPref("rssCheck", 0) + 7190 < curtime)
{
LogMessage("no forecast data or cache is more than 2 hour old");
} else {
LogMessage("cache isn't more than 2 hour old");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
String date = sdf.format(GetLongPref("rssCheck", 0) * 1000);
LogMessage("rsscheck == " + date);
date = sdf.format(curtime * 1000);
LogMessage("curtime == " + date);
return;
}

LogMessage("forecast checking: " + forecast_url);

Thread t = new Thread(new Runnable()
Expand All @@ -3400,19 +3415,12 @@ public void run()
{
try
{
int curtime = round(System.currentTimeMillis() / 1000);

if(GetStringPref("forecastData", "").equals("") || GetIntPref("rssCheck", 0) + 7190 < curtime)
String tmp = downloadForecast();
if(tmp != null)
{
LogMessage("no forecast data or cache is more than 2 hour old");

String tmp = downloadForecast();
if(tmp != null)
{
LogMessage("updating rss cache");
SetIntPref("rssCheck", curtime);
SetStringPref("forecastData", tmp);
}
LogMessage("updating rss cache");
SetLongPref("rssCheck", curtime);
SetStringPref("forecastData", tmp);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/odiousapps/weewxweather/Forecast.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ public void onScrollChanged()
if(!common.GetStringPref("RADAR_URL", "").equals("") && f2.lastModified() + period[0] < System.currentTimeMillis())
reloadWebView(false);

int curtime = Math.round(System.currentTimeMillis() / 1000);
if(!common.GetBoolPref("radarforecast", true) && common.GetIntPref("rssCheck", 0) + 7190 < curtime)
long curtime = Math.round(System.currentTimeMillis() / 1000);
if(!common.GetBoolPref("radarforecast", true) && common.GetLongPref("rssCheck", 0) + 7190 < curtime)
getForecast(false);

return rootView;
Expand Down Expand Up @@ -478,16 +478,16 @@ public void run()
{
try
{
int curtime = Math.round(System.currentTimeMillis() / 1000);
long curtime = Math.round(System.currentTimeMillis() / 1000);

if(common.GetStringPref("forecastData", "").equals("") || common.GetIntPref("rssCheck", 0) + 7190 < curtime)
if(common.GetStringPref("forecastData", "").equals("") || common.GetLongPref("rssCheck", 0) + 7190 < curtime)
{
Common.LogMessage("no forecast data or cache is more than 2 hour old");

String tmp = common.downloadForecast();

Common.LogMessage("updating rss cache");
common.SetIntPref("rssCheck", curtime);
common.SetLongPref("rssCheck", curtime);
common.SetStringPref("forecastData", tmp);
handlerDone.sendEmptyMessage(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public void run()
Switch use_icons = findViewById(R.id.use_icons);

RadioButton showRadar = findViewById(R.id.showRadar);
int curtime = Math.round(System.currentTimeMillis() / 1000);
long curtime = Math.round(System.currentTimeMillis() / 1000);

if(use_icons.isChecked() && (common.GetLongPref("icon_version", 0) < Common.icon_version || !common.checkForImages()))
{
Expand Down Expand Up @@ -805,7 +805,7 @@ public void run()
{
validURL3 = true;
Common.LogMessage("updating rss cache");
common.SetIntPref("rssCheck", curtime);
common.SetLongPref("rssCheck", curtime);
common.SetStringPref("forecastData", tmp);
}
} catch (Exception e) {
Expand Down Expand Up @@ -876,7 +876,7 @@ public void run()

if(forecast.equals(""))
{
common.SetIntPref("rssCheck", 0);
common.SetLongPref("rssCheck", 0);
common.SetStringPref("forecastData", "");
}

Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/odiousapps/weewxweather/Weather.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ public boolean onConsoleMessage(ConsoleMessage cm)
if(!common.GetStringPref("RADAR_URL", "").equals("") && f2.lastModified() + period[0] < System.currentTimeMillis())
reloadWebView(false);

int curtime = round(System.currentTimeMillis() / 1000);
if(!common.GetBoolPref("radarforecast", true) && common.GetIntPref("rssCheck", 0) + 7190 < curtime)
long curtime = round(System.currentTimeMillis() / 1000);
if(!common.GetBoolPref("radarforecast", true) && common.GetLongPref("rssCheck", 0) + 7190 < curtime)
reloadForecast(false);

return updateFields();
Expand Down Expand Up @@ -910,17 +910,17 @@ public void run()
{
try
{
int curtime = round(System.currentTimeMillis() / 1000);
long curtime = round(System.currentTimeMillis() / 1000);

if(common.GetStringPref("forecastData", "").equals("") || common.GetIntPref("rssCheck", 0) + 7190 < curtime)
if(common.GetStringPref("forecastData", "").equals("") || common.GetLongPref("rssCheck", 0) + 7190 < curtime)
{
Common.LogMessage("no forecast data or cache is more than 2 hour old");

String tmp = common.downloadForecast();
if(tmp != null)
{
Common.LogMessage("updating rss cache");
common.SetIntPref("rssCheck", curtime);
common.SetLongPref("rssCheck", curtime);
common.SetStringPref("forecastData", tmp);

handlerDone.sendEmptyMessage(0);
Expand Down

0 comments on commit 3f0f697

Please sign in to comment.