Skip to content

Commit

Permalink
Squished some more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbunny2008 committed Dec 3, 2018
1 parent d486894 commit 39fa4b8
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 95 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 6012
versionName "0.6.12"
versionCode 6013
versionName "0.6.13"
}
buildTypes {
release {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/odiousapps/weewxweather/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,7 @@ String downloadForecast(String fctype, String forecast, String bomtown) throws E
private String downloadString(String fromURL) throws Exception
{
Uri uri = Uri.parse(fromURL);
Common.LogMessage("inigo-settings.txt == " + fromURL);
Common.LogMessage("fromURL == " + fromURL);
if (uri.getUserInfo() != null && uri.getUserInfo().contains(":"))
{
final String[] UC = uri.getUserInfo().split(":");
Expand Down Expand Up @@ -2285,7 +2285,7 @@ protected PasswordAuthentication getPasswordAuthentication()
private File downloadBinary(File f, String fromURL) throws Exception
{
Uri uri = Uri.parse(fromURL);
Common.LogMessage("inigo-settings.txt == " + fromURL);
Common.LogMessage("fromURL == " + fromURL);
if (uri.getUserInfo() != null && uri.getUserInfo().contains(":"))
{
final String[] UC = uri.getUserInfo().split(":");
Expand Down
164 changes: 80 additions & 84 deletions app/src/main/java/com/odiousapps/weewxweather/Forecast.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public boolean onLongClick(View v)
Vibrator vibrator = (Vibrator) common.context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null)
vibrator.vibrate(250);
swipeLayout.setRefreshing(true);
Common.LogMessage("rootview long press");
reloadWebView(true);
getForecast(true);
Expand Down Expand Up @@ -112,6 +113,7 @@ public boolean onLongClick(View v)
Vibrator vibrator = (Vibrator) common.context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null)
vibrator.vibrate(250);
swipeLayout.setRefreshing(true);
Common.LogMessage("webview long press");
reloadWebView(true);
getForecast(true);
Expand Down Expand Up @@ -177,6 +179,7 @@ public boolean onLongClick(View v)
Vibrator vibrator = (Vibrator) common.context.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null)
vibrator.vibrate(250);
swipeLayout.setRefreshing(true);
Common.LogMessage("webview long press");
reloadWebView(true);
getForecast(true);
Expand Down Expand Up @@ -211,75 +214,61 @@ public void onScrollChanged()
forecast = rootView.findViewById(R.id.forecast);
im = rootView.findViewById(R.id.logo);

if (common.GetBoolPref("radarforecast", true))
{
Common.LogMessage("Displaying forecast");
getForecast(false);
rl.setVisibility(View.GONE);
wv2.setVisibility(View.VISIBLE);
forecast.setVisibility(View.VISIBLE);
im.setVisibility(View.VISIBLE);
} else {
Common.LogMessage("Displaying radar");
loadWebView();
rl.setVisibility(View.VISIBLE);
wv2.setVisibility(View.GONE);

forecast.setVisibility(View.GONE);
im.setVisibility(View.GONE);
}
updateScreen();

return rootView;
}

private void loadWebView()
{
if(common.GetBoolPref("radarforecast", true))
{
if (common.GetStringPref("radtype", "image").equals("image"))
{
rl.setVisibility(View.VISIBLE);
String radar = common.context.getFilesDir() + "/radar.gif";
return;

if (radar.equals("") || !new File(radar).exists() || common.GetStringPref("RADAR_URL", "").equals(""))
{
String html = "<html>";
if (dark_theme)
html += "<head><style>body{color: #fff; background-color: #000;}</style></head>";
html += "<body>Radar URL not set or is still downloading. You can go to settings to change.</body></html>";
wv1.loadDataWithBaseURL("file:///android_res/drawable/", html, "text/html", "utf-8", null);
return;
}
swipeLayout.setRefreshing(true);

int height = Math.round((float) Resources.getSystem().getDisplayMetrics().widthPixels / Resources.getSystem().getDisplayMetrics().scaledDensity * 0.955f);
int width = Math.round((float) Resources.getSystem().getDisplayMetrics().heightPixels / Resources.getSystem().getDisplayMetrics().scaledDensity * 0.955f);
if (common.GetStringPref("radtype", "image").equals("image"))
{
rl.setVisibility(View.VISIBLE);
String radar = common.context.getFilesDir() + "/radar.gif";

String html = "<!DOCTYPE html>\n" +
"<html>\n" +
" <head>\n" +
" <meta charset='utf-8'>\n" +
" <meta name='viewport' content='width=device-width, initial-scale=1.0'>\n";
if (radar.equals("") || !new File(radar).exists() || common.GetStringPref("RADAR_URL", "").equals(""))
{
String html = "<html>";
if (dark_theme)
html += "<style>body{color: #fff; background-color: #000;}</style>";
html += " </head>\n" +
" <body>\n" +
"\t<div style='text-align:center;'>\n" +
"\t<img style='margin:0px;padding:0px;border:0px;text-align:center;max-height:" + height + "px;max-width:" + width + "px;width:auto;height:auto;'\n" +
"\tsrc='file://" + radar + "'>\n" +
"\t</div>\n" +
" </body>\n" +
"</html>";
html += "<head><style>body{color: #fff; background-color: #000;}</style></head>";
html += "<body>Radar URL not set or is still downloading. You can go to settings to change.</body></html>";
wv1.loadDataWithBaseURL("file:///android_res/drawable/", html, "text/html", "utf-8", null);
rl.setVisibility(View.VISIBLE);
wv2.setVisibility(View.GONE);
} else if (common.GetStringPref("radtype", "image").equals("webpage") && !common.GetStringPref("RADAR_URL", "").equals("")) {
wv2.loadUrl(common.GetStringPref("RADAR_URL", ""));
rl.setVisibility(View.GONE);
wv2.setVisibility(View.VISIBLE);
return;
}
} else {
generateForecast();

int height = Math.round((float) Resources.getSystem().getDisplayMetrics().widthPixels / Resources.getSystem().getDisplayMetrics().scaledDensity * 0.955f);
int width = Math.round((float) Resources.getSystem().getDisplayMetrics().heightPixels / Resources.getSystem().getDisplayMetrics().scaledDensity * 0.955f);

String html = "<!DOCTYPE html>\n" +
"<html>\n" +
" <head>\n" +
" <meta charset='utf-8'>\n" +
" <meta name='viewport' content='width=device-width, initial-scale=1.0'>\n";
if (dark_theme)
html += "<style>body{color: #fff; background-color: #000;}</style>";
html += " </head>\n" +
" <body>\n" +
"\t<div style='text-align:center;'>\n" +
"\t<img style='margin:0px;padding:0px;border:0px;text-align:center;max-height:" + height + "px;max-width:" + width + "px;width:auto;height:auto;'\n" +
"\tsrc='file://" + radar + "'>\n" +
"\t</div>\n" +
" </body>\n" +
"</html>";
wv1.loadDataWithBaseURL("file:///android_res/drawable/", html, "text/html", "utf-8", null);
rl.setVisibility(View.VISIBLE);
wv2.setVisibility(View.GONE);
} else if (common.GetStringPref("radtype", "image").equals("webpage") && !common.GetStringPref("RADAR_URL", "").equals("")) {
wv2.loadUrl(common.GetStringPref("RADAR_URL", ""));
rl.setVisibility(View.GONE);
wv2.setVisibility(View.VISIBLE);
}

swipeLayout.setRefreshing(false);
}

@SuppressWarnings("SameParameterValue")
Expand All @@ -300,13 +289,11 @@ private void reloadWebView(boolean force)
if(!common.checkWifiOnAndConnected() && !force)
{
Common.LogMessage("Not on wifi and not a forced refresh");
if(swipeLayout.isRefreshing())
swipeLayout.setRefreshing(false);
swipeLayout.setRefreshing(false);
return;
}

if(!swipeLayout.isRefreshing())
swipeLayout.setRefreshing(true);
swipeLayout.setRefreshing(true);

Thread t = new Thread(new Runnable()
{
Expand All @@ -322,6 +309,8 @@ public void run()
} catch (Exception e) {
e.printStackTrace();
}

swipeLayout.setRefreshing(false);
}
});

Expand Down Expand Up @@ -349,38 +338,42 @@ void doPause()
Common.LogMessage("forecast.java -- unregisterReceiver");
}

private void updateScreen()
{
if (common.GetBoolPref("radarforecast", true))
{
Common.LogMessage("Displaying forecast");
getForecast(false);
forecast.setVisibility(View.VISIBLE);
im.setVisibility(View.VISIBLE);
rl.setVisibility(View.GONE);
wv2.setVisibility(View.VISIBLE);
} else {
Common.LogMessage("Displaying radar");
loadWebView();
forecast.setVisibility(View.GONE);
im.setVisibility(View.GONE);
rl.setVisibility(View.VISIBLE);
wv2.setVisibility(View.GONE);
}
}

private final BroadcastReceiver serviceReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
try
try
{
Common.LogMessage("Weather() We have a hit, so we should probably update the screen.");
String action = intent.getAction();
if(action != null && action.equals(Common.UPDATE_INTENT))
{
dark_theme = common.GetBoolPref("dark_theme", false);

if (common.GetBoolPref("radarforecast", true))
{
Common.LogMessage("Displaying forecast");
getForecast(false);
forecast.setVisibility(View.VISIBLE);
im.setVisibility(View.VISIBLE);
rl.setVisibility(View.GONE);
wv2.setVisibility(View.VISIBLE);
} else {
Common.LogMessage("Displaying radar");
loadWebView();
forecast.setVisibility(View.GONE);
im.setVisibility(View.GONE);
rl.setVisibility(View.VISIBLE);
wv2.setVisibility(View.GONE);
}
updateScreen();
} else if(action != null && action.equals(Common.REFRESH_INTENT)) {
getForecast(false);
loadWebView();
dark_theme = common.GetBoolPref("dark_theme", false);
updateScreen();
} else if(action != null && action.equals(Common.EXIT_INTENT)) {
doPause();
}
Expand All @@ -392,6 +385,7 @@ public void onReceive(Context context, Intent intent)

private void getForecast(boolean force)
{
swipeLayout.setRefreshing(true);
if(!common.GetBoolPref("radarforecast", true))
return;

Expand All @@ -415,13 +409,11 @@ public void run()
if(!common.checkWifiOnAndConnected() && !force)
{
Common.LogMessage("Not on wifi and not a forced refresh");
if(swipeLayout.isRefreshing())
swipeLayout.setRefreshing(false);
swipeLayout.setRefreshing(false);
return;
}

if(!swipeLayout.isRefreshing())
swipeLayout.setRefreshing(true);
swipeLayout.setRefreshing(true);

if(!common.GetStringPref("forecastData", "").equals(""))
generateForecast();
Expand Down Expand Up @@ -449,6 +441,8 @@ public void run()
} catch (Exception e) {
e.printStackTrace();
}

swipeLayout.setRefreshing(false);
}
});

Expand All @@ -468,7 +462,9 @@ public void handleMessage(Message msg)

private void generateForecast()
{
Common.LogMessage("getting json data");
swipeLayout.setRefreshing(true);

Common.LogMessage("getting json data");
String data;
String fctype = common.GetStringPref("fctype", "Yahoo");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ public void run()
@Override
public void run()
{
//swipeLayout.setRefreshing(false);
new AlertDialog
.Builder(common.context)
.setTitle("An error occurred while attempting to update usage")
Expand Down
Loading

0 comments on commit 39fa4b8

Please sign in to comment.