From 961cdd437f1b0cee1097fe65fcd57ced27efe4ea Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Mon, 23 May 2022 17:08:10 +0100 Subject: [PATCH] Make app loader page more reliable, and allow a custom app loader URL to be specified --- .../DeviceSettingsPreferenceConst.java | 1 + .../banglejs/AppsManagementActivity.java | 23 +++++++++++++++---- .../banglejs/BangleJSDeviceSupport.java | 2 ++ app/src/main/res/values/strings.xml | 2 ++ .../main/res/xml/devicesettings_banglejs.xml | 6 +++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java index 495a92f7c..d2ff3f607 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java @@ -45,6 +45,7 @@ public class DeviceSettingsPreferenceConst { public static final String PREF_DEVICE_INTENTS = "device_intents"; public static final String PREF_BANGLEJS_TEXT_BITMAP = "banglejs_text_bitmap"; + public static final String PREF_BANGLEJS_WEBVIEW_URL = "banglejs_webview_url"; public static final String PREF_DISCONNECT_NOTIFICATION = "disconnect_notification"; public static final String PREF_DISCONNECT_NOTIFICATION_START = "disconnect_notification_start"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/AppsManagementActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/AppsManagementActivity.java index 3a918b5b9..7e9e8105c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/AppsManagementActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/banglejs/AppsManagementActivity.java @@ -1,5 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.devices.banglejs; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_INTERNET_ACCESS; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -42,6 +44,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.banglejs.BangleJSDev import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.GB; +import nodomain.freeyourgadget.gadgetbridge.util.Prefs; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BANGLEJS_WEBVIEW_URL; public class AppsManagementActivity extends AbstractGBActivity { private static final Logger LOG = LoggerFactory.getLogger(AppsManagementActivity.class); @@ -49,6 +53,8 @@ public class AppsManagementActivity extends AbstractGBActivity { private WebView webView; private GBDevice mGBDevice; private DeviceCoordinator mCoordinator; + /// It seems we can get duplicate broadcasts sometimes - so this helps to avoid that + private int deviceRxSeq = -1; public AppsManagementActivity() { } @@ -88,7 +94,6 @@ public class AppsManagementActivity extends AbstractGBActivity { commandFilter.addAction(GBDevice.ACTION_DEVICE_CHANGED); commandFilter.addAction(BangleJSDeviceSupport.BANGLEJS_COMMAND_RX); LocalBroadcastManager.getInstance(this).registerReceiver(deviceUpdateReceiver, commandFilter); - initViews(); } @@ -98,8 +103,14 @@ public class AppsManagementActivity extends AbstractGBActivity { switch (intent.getAction()) { case BangleJSDeviceSupport.BANGLEJS_COMMAND_RX: { String data = String.valueOf(intent.getExtras().get("DATA")); - LOG.info("WebView TX: " + data); - bangleRxData(data); + int seq = intent.getIntExtra("SEQ",0); + LOG.info("WebView TX: " + data + "("+seq+")"); + if (seq==deviceRxSeq) { + LOG.info("WebView TX DUPLICATE AND IGNORED"); + } else { + deviceRxSeq = seq; + bangleRxData(data); + } break; } } @@ -162,7 +173,11 @@ public class AppsManagementActivity extends AbstractGBActivity { settings.setDatabasePath(databasePath); webView.addJavascriptInterface(new WebViewInterface(this), "Android"); webView.setWebContentsDebuggingEnabled(true); // FIXME - webView.loadUrl("https://banglejs.com/apps/android.html"); + + Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(mGBDevice.getAddress())); + String url = devicePrefs.getString(PREF_BANGLEJS_WEBVIEW_URL, "").trim(); + if (url.isEmpty()) url = "https://banglejs.com/apps/android.html"; + webView.loadUrl(url); webView.setWebViewClient(new WebViewClient(){ public void onPageFinished(WebView view, String weburl){ diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java index 96482f5a9..289cb1b3d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java @@ -119,6 +119,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport { // Local Intents - for app manager communication public static final String BANGLEJS_COMMAND_TX = "banglejs_command_tx"; public static final String BANGLEJS_COMMAND_RX = "banglejs_command_rx"; + int bangleCommandSeq = 0; // to attempt to stop duplicate packets // Global Intents private static final String BANGLE_ACTION_UART_TX = "com.banglejs.uart.tx"; @@ -553,6 +554,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport { // Send an intent with new data Intent intent = new Intent(BangleJSDeviceSupport.BANGLEJS_COMMAND_RX); intent.putExtra("DATA", packetStr); + intent.putExtra("SEQ", bangleCommandSeq++); LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent); } return false; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bfc343204..4d34f8367 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -182,6 +182,8 @@ Enable this if your device has no support for your language\'s font Text as Bitmaps If a word cannot be rendered with the watch\'s font, render it to a bitmap in Gadgetbridge and display the bitmap on the watch + App loader URL + If you want a custom app loader put your https://…/android.html URL here. Otherwise leave blank for https://banglejs.com/apps Right-To-Left Enable this if your device can not show right-to-left languages Right-To-Left Max Line Length diff --git a/app/src/main/res/xml/devicesettings_banglejs.xml b/app/src/main/res/xml/devicesettings_banglejs.xml index 9270f8baf..eed82ff08 100644 --- a/app/src/main/res/xml/devicesettings_banglejs.xml +++ b/app/src/main/res/xml/devicesettings_banglejs.xml @@ -6,4 +6,10 @@ android:key="banglejs_text_bitmap" android:summary="@string/pref_summary_banglejs_text_bitmap" android:title="@string/pref_title_banglejs_text_bitmap" /> + \ No newline at end of file