diff --git a/CHANGELOG.md b/CHANGELOG.md index a7c5f96d2..143ababd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ####Version 0.11.0 * Pebble: new App Manager (keeps track of installed apps and allows app sorting on FW 3.x) * Pebble: call dismissal with canned SMS (FW 3.x) +* Pebble: watchapp configuration presets * Pebble: fix regression with FW 2.x (almost everything was broken in 0.10.2) ####Version 0.10.2 diff --git a/app/src/main/assets/app_config/configure.html b/app/src/main/assets/app_config/configure.html index e606d466a..8ab733cdd 100644 --- a/app/src/main/assets/app_config/configure.html +++ b/app/src/main/assets/app_config/configure.html @@ -60,6 +60,11 @@ +

App presets:

+

In case of "network error" after saving settings in the watchhapp, copy the "network error" @@ -75,5 +80,11 @@ +

App Presets:

+ +

Existing presets will be deleted.

diff --git a/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js b/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js index b37d5089a..81cf1548b 100644 --- a/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js +++ b/app/src/main/assets/app_config/js/gadgetbridge_boilerplate.js @@ -91,6 +91,23 @@ function gbPebble() { GBjs.closeActivity(); } + this.savePreset = function() { + GBjs.saveAppStoredPreset(self.configurationValues); + } + + this.loadPreset = function() { + showStep("step2"); + var presetElements = document.getElementsByClassName("store_presets"); + for (var i = 0; i < presetElements.length; i ++) { + presetElements[i].style.display = 'none'; + } + var json_string = GBjs.getAppStoredPreset(); + var t = new Object(); + t.response = json_string; + if (json_string != '') + Pebble.parseconfig(t); + } + //needs to be called like this because of original Pebble function name this.openURL = function(url) { if (url.lastIndexOf("http", 0) === 0) { @@ -111,7 +128,7 @@ function gbPebble() { this.sendAppMessage = function (dict, callbackAck, callbackNack){ try { self.configurationValues = JSON.stringify(dict); - document.getElementById("jsondata").innerHTML=this.configurationValues; + document.getElementById("jsondata").innerHTML=self.configurationValues; return callbackAck; } catch (e) { @@ -162,6 +179,8 @@ function gbPebble() { var Pebble = new gbPebble(); var jsConfigFile = GBjs.getAppConfigurationFile(); +var storedPreset = GBjs.getAppStoredPreset(); + document.addEventListener('DOMContentLoaded', function(){ if (jsConfigFile != null) { loadScript(jsConfigFile, function() { @@ -173,6 +192,12 @@ if (jsConfigFile != null) { if (json_string != '') Pebble.parseconfig(t); } else { + if (storedPreset === undefined) { + var presetElements = document.getElementsByClassName("load_presets"); + for (var i = 0; i < presetElements.length; i ++) { + presetElements[i].style.display = 'none'; + } + } Pebble.ready(); Pebble.showConfiguration(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java index 200c03288..1a68138eb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ExternalPebbleJSActivity.java @@ -20,8 +20,11 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.BufferedWriter; import java.io.File; +import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import java.util.Iterator; import java.util.Scanner; import java.util.UUID; @@ -233,6 +236,38 @@ public class ExternalPebbleJSActivity extends GBActivity { return null; } + @JavascriptInterface + public String getAppStoredPreset() { + try { + File destDir = new File(FileUtils.getExternalFilesDir() + "/pbw-cache"); + File configurationFile = new File(destDir, appUuid.toString() + "_preset.json"); + if (configurationFile.exists()) { + return FileUtils.getStringFromFile(configurationFile); + } + } catch (IOException e) { + GB.toast("Error reading presets", Toast.LENGTH_LONG, GB.ERROR); + e.printStackTrace(); + } + return null; + } + + @JavascriptInterface + public void saveAppStoredPreset(String msg) { + Writer writer; + + try { + File destDir = new File(FileUtils.getExternalFilesDir() + "/pbw-cache"); + File presetsFile = new File(destDir, appUuid.toString() + "_preset.json"); + writer = new BufferedWriter(new FileWriter(presetsFile)); + writer.write(msg); + writer.close(); + GB.toast("Presets stored", Toast.LENGTH_SHORT, GB.INFO); + } catch (IOException e) { + GB.toast("Error storing presets", Toast.LENGTH_LONG, GB.ERROR); + e.printStackTrace(); + } + } + @JavascriptInterface public String getAppUUID() { return appUuid.toString(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java index eff9df8fa..8247dcd3d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/appmanager/AbstractAppManagerFragment.java @@ -312,7 +312,7 @@ public abstract class AbstractAppManagerFragment extends Fragment { return true; } - String[] suffixToDelete = new String[]{".pbw", ".json", "_config.js"}; + String[] suffixToDelete = new String[]{".pbw", ".json", "_config.js", "_preset.json"}; for (String suffix : suffixToDelete) { File fileToDelete = new File(baseName + suffix); diff --git a/app/src/main/res/xml/changelog_master.xml b/app/src/main/res/xml/changelog_master.xml index e58cf2258..9e499d931 100644 --- a/app/src/main/res/xml/changelog_master.xml +++ b/app/src/main/res/xml/changelog_master.xml @@ -3,6 +3,7 @@ Pebble: new App Manager (keeps track of installed apps and allows app sorting on FW 3.x) Pebble: call dismissal with canned SMS (FW 3.x) + Pebble: watchapp configuration presets Pebble: fix regression with FW 2.x (almost everything was broken in 0.10.2)