Skip to content

Commit

Permalink
Fixed the app from crashing when it tried to update the screen from a…
Browse files Browse the repository at this point in the history
… thread
  • Loading branch information
evilbunny2008 committed Dec 7, 2018
1 parent 93f0f84 commit 6c5c7aa
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 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 6020
versionName "0.6.20"
versionCode 6021
versionName "0.6.21"
}
buildTypes {
release {
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/odiousapps/weewxweather/Forecast.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ private void loadWebView()

if(wv2.getOriginalUrl() == null)
{
wv2.post(new Runnable()
Handler mHandler = new Handler(Looper.getMainLooper());
mHandler.post(new Runnable()
{
@Override
public void run()
Expand Down Expand Up @@ -426,7 +427,9 @@ private void getForecast(boolean force)
if(forecast_url.equals(""))
{
final String html = "<html><body>Forecast URL not set. Edit inigo-settings.txt to change.</body></html>";
wv2.post(new Runnable()

Handler mHandler = new Handler(Looper.getMainLooper());
mHandler.post(new Runnable()
{
@Override
public void run()
Expand Down Expand Up @@ -636,7 +639,8 @@ public void run()

final String fc = tmpfc;

wv2.post(new Runnable()
Handler mHandler = new Handler(Looper.getMainLooper());
mHandler.post(new Runnable()
{
@Override
public void run()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/odiousapps/weewxweather/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public void run()
public void run()
{
wv.loadDataWithBaseURL("file:///android_res/drawable/", sb.toString(), "text/html", "utf-8", null);
swipeLayout.setRefreshing(true);
swipeLayout.setRefreshing(false);
}
});
}
Expand Down
62 changes: 60 additions & 2 deletions app/src/main/java/com/odiousapps/weewxweather/Weather.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,11 @@ public void run()
{
String[] content = common.processYahoo(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='purple.png' height='29px'/><br/>";
sb.append("<html>");
if (dark_theme)
Expand All @@ -430,7 +434,10 @@ public void run()
{
String[] content = common.processWZ(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='wz.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -444,7 +451,10 @@ public void run()
{
String[] content = common.processYR(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='yrno.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -458,7 +468,10 @@ public void run()
{
String[] content = common.processBOM(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='bom.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -472,7 +485,10 @@ public void run()
{
String[] content = common.processWMO(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='wmo.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -486,7 +502,10 @@ public void run()
{
String[] content = common.processWGOV(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='wgov.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -500,7 +519,10 @@ public void run()
{
String[] content = common.processWCA(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='wca.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -514,7 +536,10 @@ public void run()
{
String[] content = common.processWCAF(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='wca.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -528,7 +553,10 @@ public void run()
{
String[] content = common.processMET(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='met.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -542,7 +570,10 @@ public void run()
{
String[] content = common.processBOM2(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='bom.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -556,7 +587,10 @@ public void run()
{
String[] content = common.processAEMET(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='aemet.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -570,7 +604,10 @@ public void run()
{
String[] content = common.processDWD(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='dwd.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -584,7 +621,10 @@ public void run()
{
String[] content = common.processMetService(data);
if (content == null || content.length <= 0)
{
stopRefreshing();
return;
}

String logo = "<img src='metservice.png' height='29px'/><br/>";
sb.append("<html>");
Expand All @@ -603,31 +643,49 @@ public void run()
public void run()
{
wv.loadDataWithBaseURL("file:///android_res/drawable/", sb.toString(), "text/html", "utf-8", null);
swipeLayout.setRefreshing(false);
}
});
swipeLayout.setRefreshing(false);
}
});

t.start();
}

private void stopRefreshing()
{
Handler mHandler = new Handler(Looper.getMainLooper());
mHandler.post(new Runnable()
{
@Override
public void run()
{
swipeLayout.setRefreshing(false);
}
});
}

private void reloadForecast(boolean force)
{
if(common.GetBoolPref("radarforecast", true))
{
stopRefreshing();
return;
}

final String forecast_url = common.GetStringPref("FORECAST_URL", "");

if(forecast_url.equals(""))
{
final String html = "<html><body>Forecast URL not set. Edit inigo-settings.txt to change.</body></html>";
wv.post(new Runnable()
Handler mHandler = new Handler(Looper.getMainLooper());
mHandler.post(new Runnable()
{
@Override
public void run()
{
wv.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
swipeLayout.setRefreshing(false);
}
});

Expand Down

0 comments on commit 6c5c7aa

Please sign in to comment.