From 79b6bc6c4323d8f395059f1f0443fb76e2b8de6f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 8 Mar 2019 23:56:35 +0100 Subject: [PATCH] SMS Plugin allow duration in basal command --- .../plugins/general/smsCommunicator/SmsAction.java | 11 +++++++++++ .../smsCommunicator/SmsCommunicatorPlugin.java | 14 ++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java index 14f03776df..d6ea031fa7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.smsCommunicator; abstract class SmsAction implements Runnable { Double aDouble; Integer anInteger; + Integer secondInteger; SmsAction() {} @@ -10,7 +11,17 @@ abstract class SmsAction implements Runnable { this.aDouble = aDouble; } + SmsAction(Double aDouble, Integer secondInteger) { + this.aDouble = aDouble; + this.secondInteger = secondInteger; + } + SmsAction(Integer anInteger) { this.anInteger = anInteger; } + + SmsAction(Integer anInteger, Integer secondInteger) { + this.anInteger = anInteger; + this.secondInteger = secondInteger; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java index 0b3f66ea97..6ff70602fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java @@ -363,6 +363,9 @@ public class SmsCommunicatorPlugin extends PluginBase { } } else if (splited[1].endsWith("%")) { int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splited[1],"%")); + int duration = 30; + if (splited.length > 2) + duration = SafeParse.stringToInt(splited[2]); Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { reply = MainApp.gs(R.string.noprofile); @@ -376,12 +379,12 @@ public class SmsCommunicatorPlugin extends PluginBase { passCode = generatePasscode(); reply = String.format(MainApp.gs(R.string.smscommunicator_basalpctreplywithcode), tempBasalPct, passCode); receivedSms.processed = true; - messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasalPct) { + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasalPct, duration) { @Override public void run() { Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile != null) - ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalPercent(anInteger, 30, true, profile, new Callback() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalPercent(anInteger, secondInteger, true, profile, new Callback() { @Override public void run() { if (result.success) { @@ -408,6 +411,9 @@ public class SmsCommunicatorPlugin extends PluginBase { } } else { Double tempBasal = SafeParse.stringToDouble(splited[1]); + int duration = 30; + if (splited.length > 2) + duration = SafeParse.stringToInt(splited[2]); Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { reply = MainApp.gs(R.string.noprofile); @@ -418,12 +424,12 @@ public class SmsCommunicatorPlugin extends PluginBase { passCode = generatePasscode(); reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, passCode); receivedSms.processed = true; - messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasal) { + messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasal, duration) { @Override public void run() { Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile != null) - ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalAbsolute(aDouble, 30, true, profile, new Callback() { + ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalAbsolute(aDouble, secondInteger, true, profile, new Callback() { @Override public void run() { if (result.success) {