diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java index 8837494c4d..f4c654f8ce 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java @@ -240,6 +240,8 @@ public synchronized void Snooze(Context ctx, int repeatTime) { && Pref.getBooleanDefaultFalse("pref_amazfit_BG_alert_enable_key")) { Amazfitservice.start("xDrip_AlarmCancel"); } + + BroadcastEntry.cancelAlert(); } public synchronized void Snooze(Context ctx, int repeatTime, boolean from_interactive) { diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastEntry.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastEntry.java index cc2663c999..9919194551 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastEntry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastEntry.java @@ -24,6 +24,12 @@ public static void sendLatestBG() { } } + public static void cancelAlert() { + if (isEnabled()) { + JoH.startService(BroadcastService.class, Const.INTENT_FUNCTION_KEY, Const.CMD_CANCEL_ALERT); + } + } + public static void sendAlert(String type, String message) { if (isEnabled()) { Inevitable.task("broadcast-service-send-alert", 100, () -> JoH.startService(BroadcastService.class, diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java index b284bec904..2ba4d6ead5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java @@ -32,6 +32,8 @@ import com.eveningoutpost.dexdrip.UtilityModels.Pref; import com.eveningoutpost.dexdrip.UtilityModels.PumpStatus; import com.eveningoutpost.dexdrip.stats.StatsResult; +import com.eveningoutpost.dexdrip.store.FastStore; +import com.eveningoutpost.dexdrip.store.KeyStore; import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; import com.eveningoutpost.dexdrip.services.broadcastservice.models.BroadcastModel; import com.eveningoutpost.dexdrip.services.broadcastservice.models.GraphLine; @@ -45,6 +47,10 @@ import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DAY_IN_MS; +// External status line from AAPS added +import static com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService.getLastStatusLine; +import static com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService.getLastStatusLineTime; + /** * Broadcast API which provides common data like, bg values, graph info, statistic info. * Also it can handle different alarms, save HR data, steps and treatments. @@ -76,6 +82,8 @@ public class BroadcastService extends Service { protected String TAG = this.getClass().getSimpleName(); protected Map broadcastEntities; + protected KeyStore keyStore = FastStore.getInstance(); + /** * The receiver listening {@link ACTION_WATCH_COMMUNICATION_RECEIVER} action. * Every Receiver command requires {@link Const.INTENT_PACKAGE_KEY} @@ -209,7 +217,6 @@ public void onReceive(Context context, Intent intent) { } }; - @Override public IBinder onBind(Intent intent) { return null; @@ -227,6 +234,7 @@ public void onCreate() { registerReceiver(broadcastReceiver, new IntentFilter(ACTION_WATCH_COMMUNICATION_RECEIVER)); JoH.startService(BroadcastService.class, Const.INTENT_FUNCTION_KEY, Const.CMD_START); + super.onCreate(); } @@ -294,6 +302,9 @@ private void handleCommand(String function, Intent intent) { bundle.putString("message", intent.getStringExtra("message")); sendBroadcast(function, receiver, bundle); break; + case Const.CMD_CANCEL_ALERT: + sendBroadcast(function, receiver, bundle); + break; } } @@ -318,6 +329,9 @@ private void handleCommand(String function, Intent intent) { broadcastModel = broadcastEntities.get(receiver); bundle = prepareBgBundle(broadcastModel); break; + case Const.CMD_CANCEL_ALERT: + receiver = null; //broadcast + break; case Const.CMD_SNOOZE_ALERT: String alertName = ""; String replyMsg = ""; @@ -513,7 +527,7 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) { bundle.putDouble("lowMark", JoH.tolerantParseDouble(prefs.getString("lowValue", "70"), 70)); BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(xdrip.getAppContext(), start, end); - bgGraphBuilder.defaultLines(true); // simple mode + bgGraphBuilder.defaultLines(false); // not simple mode in order to receive simulated data bundle.putParcelable("graph.lowLine", new GraphLine(bgGraphBuilder.lowLine())); bundle.putParcelable("graph.highLine", new GraphLine(bgGraphBuilder.highLine())); @@ -530,7 +544,25 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) { bundle.putParcelable("graph.cob", new GraphLine(treatments[6])); //cobValues bundle.putParcelable("graph.polyBg", new GraphLine(treatments[7])); //poly predict ; } + + String last_iob = keyStore.getS("last_iob"); + if ( last_iob != null){ + bundle.putString("predict.IOB", last_iob); + bundle.putLong("predict.IOB.timeStamp", keyStore.getL("last_iob_timestamp")); + } + + String last_bwp = keyStore.getS("last_bwp"); + if ( last_bwp != null){ + bundle.putString("predict.BWP", last_bwp); + bundle.putLong("predict.BWP.timeStamp", keyStore.getL("last_bwp_timestamp")); + } + + // External status line from AAPS added + bundle.putString("external.statusLine", getLastStatusLine()); + bundle.putLong("external.timeStamp", getLastStatusLineTime()); + } return bundle; } + } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/Const.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/Const.java index 41c05c4698..81120aa647 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/Const.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/Const.java @@ -19,6 +19,7 @@ public class Const { public static final String CMD_SET_SETTINGS = "set_settings"; public static final String CMD_UPDATE_BG_FORCE = "update_bg_force"; public static final String CMD_ALERT = "alarm"; + public static final String CMD_CANCEL_ALERT = "cancel_alarm"; public static final String CMD_SNOOZE_ALERT = "snooze_alarm"; public static final String CMD_ADD_STEPS = "add_steps"; public static final String CMD_ADD_HR = "add_hrs";