diff --git a/app/build.gradle b/app/build.gradle
index b026db7..e364680 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -6,8 +6,8 @@ android {
applicationId "com.odiousapps.weewxweather"
minSdkVersion 19
targetSdkVersion 28
- versionCode 6002
- versionName "0.6.2"
+ versionCode 6003
+ versionName "0.6.3"
}
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 15aee40..066e196 100644
--- a/app/src/main/java/com/odiousapps/weewxweather/Common.java
+++ b/app/src/main/java/com/odiousapps/weewxweather/Common.java
@@ -21,6 +21,7 @@
import android.widget.RemoteViews;
import org.json.JSONArray;
+import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
@@ -321,6 +322,97 @@ RemoteViews buildUpdate(Context context)
return views;
}
+ String[] processWMO(String data)
+ {
+ return processWMO(data, false);
+ }
+
+ String[] processWMO(String data, boolean showHeader)
+ {
+ if(data == null || data.equals(""))
+ return null;
+
+ String desc = "";
+ StringBuilder out = new StringBuilder();
+ boolean metric = GetBoolPref("metric", true);
+
+ try
+ {
+ JSONObject jobj = new JSONObject(data);
+
+ desc = jobj.getJSONObject("city").getString("cityName") + ", " + jobj.getJSONObject("city").getJSONObject("member").getString("memName");
+ String tmp = jobj.getJSONObject("city").getJSONObject("forecast").getString("issueDate");
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
+ long mdate = sdf.parse(tmp).getTime();
+ sdf = new SimpleDateFormat("dd MMM yyyy HH:mm", Locale.getDefault());
+ String date = sdf.format(mdate);
+
+ tmp = "
" + date + "
";
+ out.append(tmp);
+ tmp = "\n";
+ out.append(tmp);
+
+ JSONArray jarr = jobj.getJSONObject("city").getJSONObject("forecast").getJSONArray("forecastDay");
+ for(int i = 0; i < jarr.length(); i++)
+ {
+ JSONObject j = jarr.getJSONObject(i);
+
+ date = j.getString("forecastDate").trim();
+ sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
+ mdate = sdf.parse(date).getTime();
+ sdf = new SimpleDateFormat("EEEE", Locale.getDefault());
+ date = sdf.format(mdate);
+
+ String text = j.getString("weather");
+ String max = j.getString("maxTemp") + "°C";
+ String min = j.getString("minTemp") + "°C";
+ if(!metric)
+ {
+ max = j.getString("maxTempF") + "°F";
+ min = j.getString("minTempF") + "°F";
+ }
+
+ String code = j.getString("weatherIcon");
+ code = code.substring(0, 2);
+
+ tmp = "" + " | ";
+ out.append(tmp);
+
+ tmp = "" + date + " | ";
+ out.append(tmp);
+
+ if(!max.equals(""))
+ tmp = "" + max + " |
";
+ else
+ tmp = " | ";
+ out.append(tmp);
+
+ tmp = "" + text + " | ";
+ out.append(tmp);
+
+ if(!min.equals(""))
+ tmp = "" + min + " |
";
+ else
+ tmp = " | ";
+ out.append(tmp);
+
+ if(showHeader)
+ {
+ tmp = " |
";
+ out.append(tmp);
+ }
+ }
+
+ out.append("
");
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ return new String[]{out.toString(), desc};
+ }
+
String[] processBOM(String data)
{
return processBOM(data, false);
@@ -337,7 +429,7 @@ String[] processBOM(String data, boolean showHeader)
try
{
JSONObject jobj = new JSONObject(data);
- desc = jobj.getString("description");
+ desc = jobj.getString("description") + ", Australia";
String tmp = jobj.getString("content");
tmp = tmp.substring(0, tmp.length() - 6);
@@ -368,16 +460,22 @@ String[] processBOM(String data, boolean showHeader)
}
}
- for(int x = 0; x < j.getJSONArray("element").length(); x++)
+ try
{
- if(j.getJSONArray("element").getJSONObject(x).getString("type").equals("forecast_icon_code"))
- code = j.getJSONArray("element").getJSONObject(x).getString("content");
+ JSONArray jarr2 = j.getJSONArray("element");
+ for (int x = 0; x < jarr2.length(); x++)
+ {
+ if (jarr2.getJSONObject(x).getString("type").equals("forecast_icon_code"))
+ code = jarr2.getJSONObject(x).getString("content");
- if(j.getJSONArray("element").getJSONObject(x).getString("type").equals("air_temperature_minimum"))
- min = j.getJSONArray("element").getJSONObject(x).getString("content");
+ if (jarr2.getJSONObject(x).getString("type").equals("air_temperature_minimum"))
+ min = jarr2.getJSONObject(x).getString("content");
- if(j.getJSONArray("element").getJSONObject(x).getString("type").equals("air_temperature_maximum"))
- max = j.getJSONArray("element").getJSONObject(x).getString("content");
+ if (jarr2.getJSONObject(x).getString("type").equals("air_temperature_maximum"))
+ max = jarr2.getJSONObject(x).getString("content");
+ }
+ } catch (JSONException e) {
+ code = j.getJSONObject("element").getString("content");
}
date = j.getString("start-time-local").trim();
diff --git a/app/src/main/java/com/odiousapps/weewxweather/Forecast.java b/app/src/main/java/com/odiousapps/weewxweather/Forecast.java
index 55bcea8..6f85bd3 100644
--- a/app/src/main/java/com/odiousapps/weewxweather/Forecast.java
+++ b/app/src/main/java/com/odiousapps/weewxweather/Forecast.java
@@ -23,6 +23,9 @@
import com.github.rongi.rotate_layout.layout.RotateLayout;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
@@ -32,6 +35,8 @@
import java.net.URL;
import java.net.URLConnection;
+import fr.arnaudguyon.xmltojsonlib.XmlToJson;
+
class Forecast
{
private Common common;
@@ -492,9 +497,36 @@ public void run()
}
in.close();
+ String tmp = sb.toString().trim();
+ if(common.GetStringPref("fctype", "Yahoo").equals("bom.gov.au"))
+ {
+ try
+ {
+ JSONObject jobj = new XmlToJson.Builder(tmp).build().toJson();
+ if(jobj == null)
+ return;
+
+ jobj = jobj.getJSONObject("product");
+ String content = jobj.getJSONObject("amoc").getJSONObject("issue-time-local").getString("content");
+ JSONArray area = jobj.getJSONObject("forecast").getJSONArray("area");
+ for (int i = 0; i < area.length(); i++)
+ {
+ JSONObject o = area.getJSONObject(i);
+ if (o.getString("description").equals(common.GetStringPref("bomtown", "")))
+ {
+ o.put("content", content);
+ tmp = o.toString();
+ break;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
Common.LogMessage("updating rss cache");
common.SetIntPref("rssCheck", curtime);
- common.SetStringPref("forecastData", sb.toString().trim());
+ common.SetStringPref("forecastData", tmp);
}
} catch (Exception e) {
e.printStackTrace();
@@ -573,6 +605,13 @@ private void generateForecast()
updateForecast(content[0], content[1]);
break;
}
+ case "wmo.int":
+ {
+ String[] content = common.processWMO(data, true);
+ if(content != null && content.length >= 2)
+ updateForecast(content[0], content[1]);
+ break;
+ }
}
}
@@ -606,6 +645,9 @@ public void run()
case "bom.gov.au":
im.setImageResource(R.drawable.bom);
break;
+ case "wmo.int":
+ im.setImageResource(R.drawable.wmo);
+ break;
}
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java b/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java
index eb6eca2..c6b4158 100644
--- a/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java
+++ b/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java
@@ -305,7 +305,8 @@ public void onFocusChange(View v, boolean hasFocus)
"Weather Icons from FlatIcon and " +
"is licensed under CC 3.0 BY
" +
"Forecasts supplied by Yahoo!, weatherzone and " +
- "yr.no
" +
+ "yr.no" +
+ "Bureau of Meteorology
" +
"weeWX Weather App v" + common.getAppversion() + " is by OdiousApps." + wmo + content[0] + "