From fe57d4a61da9df2ff4c45949b91cf2a9cbc8a46a Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Mon, 24 Jul 2017 02:02:54 +0200 Subject: [PATCH] nsclient mbg local --- app/src/main/AndroidManifest.xml | 1 - .../java/info/nightscout/androidaps/MainApp.java | 2 ++ .../broadcasts/BroadcastMbgs.java | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fa3e1501e1..df95cda596 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -57,7 +57,6 @@ android:exported="true"> - diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 7e7d0ea030..c0d517673f 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -175,6 +175,8 @@ public class MainApp extends Application { lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_STATUS)); + lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_MBG)); + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java index f45ade6b32..f857166f7d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONArray; import org.slf4j.Logger; @@ -11,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -22,14 +24,22 @@ public class BroadcastMbgs { public static void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) { - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("mbgs", mbgs.toString()); bundle.putBoolean("delta", isDelta); Intent intent = new Intent(Intents.ACTION_NEW_MBG); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean("nsclient_localbroadcasts", true)) { + bundle = new Bundle(); + bundle.putString("mbgs", mbgs.toString()); + bundle.putBoolean("delta", isDelta); + intent = new Intent(Intents.ACTION_NEW_MBG); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } }