mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-12 01:51:58 +01:00
Pebble: some more fixes to the webview
- add back support for clay that was mistakenly removed - timestamps are in milliseconds in JS as well - intercept the whole URL path instead of the last part
This commit is contained in:
parent
868593cfd3
commit
25e6af81a4
@ -176,7 +176,7 @@ public class WebViewSingleton {
|
|||||||
this.longitude = prefs.getFloat("location_longitude", 0);
|
this.longitude = prefs.getFloat("location_longitude", 0);
|
||||||
LOG.info("got longitude/latitude from preferences: " + latitude + "/" + longitude);
|
LOG.info("got longitude/latitude from preferences: " + latitude + "/" + longitude);
|
||||||
|
|
||||||
this.timestamp = (System.currentTimeMillis() / 1000) - 86400; //let accessor know this value is really old
|
this.timestamp = System.currentTimeMillis() - 86400000; //let accessor know this value is really old
|
||||||
|
|
||||||
if (ActivityCompat.checkSelfPermission(GBApplication.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
|
if (ActivityCompat.checkSelfPermission(GBApplication.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
|
||||||
prefs.getBoolean("use_updated_location_if_available", false)) {
|
prefs.getBoolean("use_updated_location_if_available", false)) {
|
||||||
@ -245,7 +245,7 @@ public class WebViewSingleton {
|
|||||||
try {
|
try {
|
||||||
JSONObject resp;
|
JSONObject resp;
|
||||||
|
|
||||||
if ("weather".equals(type) && Weather.getInstance().getWeather2().reconstructedWeather != null) {
|
if ("/data/2.5/weather".equals(type) && Weather.getInstance().getWeather2().reconstructedWeather != null) {
|
||||||
resp = new JSONObject(Weather.getInstance().getWeather2().reconstructedWeather.toString());
|
resp = new JSONObject(Weather.getInstance().getWeather2().reconstructedWeather.toString());
|
||||||
|
|
||||||
JSONObject main = resp.getJSONObject("main");
|
JSONObject main = resp.getJSONObject("main");
|
||||||
@ -255,7 +255,7 @@ public class WebViewSingleton {
|
|||||||
resp.put("cod", 200);
|
resp.put("cod", 200);
|
||||||
resp.put("coord", coordObject(currentPosition));
|
resp.put("coord", coordObject(currentPosition));
|
||||||
resp.put("sys", sysObject(currentPosition));
|
resp.put("sys", sysObject(currentPosition));
|
||||||
} else if ("forecast".equals(type) && Weather.getInstance().getWeather2().reconstructedForecast != null) {
|
} else if ("/data/2.5/forecast".equals(type) && Weather.getInstance().getWeather2().reconstructedForecast != null) { //this is wrong, as we only have daily data. Unfortunately it looks like daily forecasts cannot be reconstructed
|
||||||
resp = new JSONObject(Weather.getInstance().getWeather2().reconstructedForecast.toString());
|
resp = new JSONObject(Weather.getInstance().getWeather2().reconstructedForecast.toString());
|
||||||
|
|
||||||
JSONObject city = resp.getJSONObject("city");
|
JSONObject city = resp.getJSONObject("city");
|
||||||
@ -337,9 +337,9 @@ public class WebViewSingleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private WebResourceResponse mimicReply(Uri requestedUri) {
|
private WebResourceResponse mimicReply(Uri requestedUri) {
|
||||||
if (requestedUri.getHost().contains("openweathermap.org")) {
|
if (requestedUri.getHost() != null && requestedUri.getHost().contains("openweathermap.org")) {
|
||||||
LOG.debug("WEBVIEW request to openweathermap.org detected of type: " + requestedUri.getLastPathSegment() + " params: " + requestedUri.getQuery());
|
LOG.debug("WEBVIEW request to openweathermap.org detected of type: " + requestedUri.getPath() + " params: " + requestedUri.getQuery());
|
||||||
return mimicOpenWeatherMapResponse(requestedUri.getLastPathSegment(), requestedUri.getQueryParameter("units"));
|
return mimicOpenWeatherMapResponse(requestedUri.getPath(), requestedUri.getQueryParameter("units"));
|
||||||
} else {
|
} else {
|
||||||
LOG.debug("WEBVIEW request:" + requestedUri.toString() + " not intercepted");
|
LOG.debug("WEBVIEW request:" + requestedUri.toString() + " not intercepted");
|
||||||
}
|
}
|
||||||
@ -357,6 +357,8 @@ public class WebViewSingleton {
|
|||||||
} else if (parsedUri.getScheme().startsWith("pebblejs")) {
|
} else if (parsedUri.getScheme().startsWith("pebblejs")) {
|
||||||
url = url.replaceFirst("^pebblejs://close#", "file:///android_asset/app_config/configure.html?config=true&json=");
|
url = url.replaceFirst("^pebblejs://close#", "file:///android_asset/app_config/configure.html?config=true&json=");
|
||||||
view.loadUrl(url);
|
view.loadUrl(url);
|
||||||
|
} else if (parsedUri.getScheme().equals("data")) { //clay
|
||||||
|
view.loadUrl(url);
|
||||||
} else {
|
} else {
|
||||||
LOG.debug("WEBVIEW Ignoring unhandled scheme: " + parsedUri.getScheme());
|
LOG.debug("WEBVIEW Ignoring unhandled scheme: " + parsedUri.getScheme());
|
||||||
}
|
}
|
||||||
@ -481,7 +483,7 @@ public class WebViewSingleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
LOG.info("WEBV:" + out.toString());
|
LOG.info("WEBVIEW message to pebble: " + out.toString());
|
||||||
GBApplication.deviceService().onAppConfiguration(this.mUuid, out.toString());
|
GBApplication.deviceService().onAppConfiguration(this.mUuid, out.toString());
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user