From 39fa4b88b5b3a5378f7a5791b1a22623fac0d2a1 Mon Sep 17 00:00:00 2001 From: evilbunny2008 <34211365+evilbunny2008@users.noreply.github.com> Date: Mon, 3 Dec 2018 20:57:12 +1100 Subject: [PATCH] Squished some more bugs --- app/build.gradle | 4 +- .../com/odiousapps/weewxweather/Common.java | 4 +- .../com/odiousapps/weewxweather/Forecast.java | 164 +++++++++--------- .../odiousapps/weewxweather/MainActivity.java | 1 - .../com/odiousapps/weewxweather/Weather.java | 22 ++- 5 files changed, 100 insertions(+), 95 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0b33020..712a953 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/app/src/main/java/com/odiousapps/weewxweather/Common.java b/app/src/main/java/com/odiousapps/weewxweather/Common.java index 5e5fe02..01cf7d6 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Common.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Common.java @@ -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(":"); @@ -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(":"); diff --git a/app/src/main/java/com/odiousapps/weewxweather/Forecast.java b/app/src/main/java/com/odiousapps/weewxweather/Forecast.java index 30a6fd8..73f0ed9 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Forecast.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Forecast.java @@ -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); @@ -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); @@ -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); @@ -211,23 +214,7 @@ 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; } @@ -235,51 +222,53 @@ public void onScrollChanged() 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 = ""; - if (dark_theme) - html += ""; - html += "Radar URL not set or is still downloading. You can go to settings to change."; - 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 = "\n" + - "\n" + - " \n" + - " \n" + - " \n"; + if (radar.equals("") || !new File(radar).exists() || common.GetStringPref("RADAR_URL", "").equals("")) + { + String html = ""; if (dark_theme) - html += ""; - html += " \n" + - " \n" + - "\t
\n" + - "\t\n" + - "\t
\n" + - " \n" + - ""; + html += ""; + html += "Radar URL not set or is still downloading. You can go to settings to change."; 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 = "\n" + + "\n" + + " \n" + + " \n" + + " \n"; + if (dark_theme) + html += ""; + html += " \n" + + " \n" + + "\t
\n" + + "\t\n" + + "\t
\n" + + " \n" + + ""; + 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") @@ -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() { @@ -322,6 +309,8 @@ public void run() } catch (Exception e) { e.printStackTrace(); } + + swipeLayout.setRefreshing(false); } }); @@ -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(); } @@ -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; @@ -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(); @@ -449,6 +441,8 @@ public void run() } catch (Exception e) { e.printStackTrace(); } + + swipeLayout.setRefreshing(false); } }); @@ -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"); diff --git a/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java b/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java index 8f7a5b8..a60a386 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java +++ b/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java @@ -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") diff --git a/app/src/main/java/com/odiousapps/weewxweather/Weather.java b/app/src/main/java/com/odiousapps/weewxweather/Weather.java index 539535c..930d339 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Weather.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Weather.java @@ -192,6 +192,7 @@ public boolean onLongClick(View v) if(vibrator != null) vibrator.vibrate(250); Common.LogMessage("rootview long press"); + swipeLayout.setRefreshing(true); forceRefresh(); reloadWebView(true); return true; @@ -223,6 +224,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("wv long press"); forceRefresh(); reloadWebView(true); @@ -274,14 +276,17 @@ public boolean onConsoleMessage(ConsoleMessage cm) private void forceRefresh() { - common.getWeather(); + swipeLayout.setRefreshing(true); + common.getWeather(); wipeForecast(); reloadWebView(true); } private void loadWebView() { - if(common.GetBoolPref("radarforecast", true)) + swipeLayout.setRefreshing(true); + + if(common.GetBoolPref("radarforecast", true)) { switch (common.GetStringPref("radtype", "image")) { @@ -303,6 +308,7 @@ public void run() wv.loadDataWithBaseURL(null, html, "text/html", "utf-8", null); } }); + swipeLayout.setRefreshing(false); return; } @@ -375,7 +381,7 @@ public void run() wv.loadDataWithBaseURL(null, shtml, "text/html", "utf-8", null); } }); - + swipeLayout.setRefreshing(false); return; } @@ -619,6 +625,8 @@ public void run() } } } + + swipeLayout.setRefreshing(false); } private void wipeForecast() @@ -690,6 +698,8 @@ public void run() } catch (Exception e) { e.printStackTrace(); } + + swipeLayout.setRefreshing(false); } }); @@ -713,8 +723,7 @@ 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; } @@ -735,6 +744,8 @@ public void run() } catch (Exception e) { e.printStackTrace(); } + + swipeLayout.setRefreshing(false); } }); @@ -748,7 +759,6 @@ public void run() public void handleMessage(Message msg) { common.SendRefresh(); - swipeLayout.setRefreshing(false); } };