diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 18ef2d633e..5efdee1d34 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -713,28 +713,6 @@ public class OverviewFragment extends Fragment { apsModeView.setText(MainApp.sResources.getString(R.string.disabledloop)); apsModeView.setTextColor(Color.WHITE); } -/* - apsModeView.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); - if (activeloop == null) { - log.error("no active loop?"); - return true; - } else if (activeloop.isEnabled(PluginBase.LOOP)) { - activeloop.setFragmentEnabled(PluginBase.LOOP, false); - activeloop.setFragmentVisible(PluginBase.LOOP, false); - } else { - activeloop.setFragmentEnabled(PluginBase.LOOP, true); - activeloop.setFragmentVisible(PluginBase.LOOP, true); - } - MainApp.getConfigBuilder().storeSettings(); - MainApp.bus().post(new EventRefreshGui(false)); - return true; - } - }); - apsModeView.setLongClickable(true); -*/ } else { apsModeView.setVisibility(View.GONE); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java index af085d9c4a..fcaf379af2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java @@ -28,6 +28,7 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.events.EventPreferenceChange; +import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin; @@ -68,6 +69,7 @@ public class SmsCommunicatorPlugin implements PluginBase { double bolusRequested = 0d; double tempBasal = 0d; double calibrationRequested = 0d; + int duration = 0; public Sms(SmsMessage message) { phoneNumber = message.getOriginatingAddress(); @@ -100,6 +102,7 @@ public class SmsCommunicatorPlugin implements PluginBase { Sms tempBasalWaitingForConfirmation = null; Sms bolusWaitingForConfirmation = null; Sms calibrationWaitingForConfirmation = null; + Sms suspendWaitingForConfirmation = null; Date lastRemoteBolusTime = new Date(0); ArrayList messages = new ArrayList<>(); @@ -212,7 +215,9 @@ public class SmsCommunicatorPlugin implements PluginBase { String[] splited = receivedSms.text.split("\\s+"); Double amount = 0d; Double tempBasal = 0d; + int duration = 0; String passCode = ""; + boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false); if (splited.length > 0) { switch (splited[0].toUpperCase()) { @@ -250,6 +255,7 @@ public class SmsCommunicatorPlugin implements PluginBase { break; case "LOOP": switch (splited[1].toUpperCase()) { + case "DISABLE": case "STOP": LoopPlugin loopPlugin = (LoopPlugin) MainApp.getSpecificPlugin(LoopPlugin.class); if (loopPlugin != null && loopPlugin.isEnabled(PluginBase.LOOP)) { @@ -260,6 +266,7 @@ public class SmsCommunicatorPlugin implements PluginBase { receivedSms.processed = true; Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Stop")); break; + case "ENABLE": case "START": loopPlugin = (LoopPlugin) MainApp.getSpecificPlugin(LoopPlugin.class); if (loopPlugin != null && !loopPlugin.isEnabled(PluginBase.LOOP)) { @@ -274,7 +281,10 @@ public class SmsCommunicatorPlugin implements PluginBase { loopPlugin = (LoopPlugin) MainApp.getSpecificPlugin(LoopPlugin.class); if (loopPlugin != null) { if (loopPlugin.isEnabled(PluginBase.LOOP)) { - reply = MainApp.sResources.getString(R.string.smscommunicator_loopisenabled); + if (loopPlugin.isSuspended()) + reply = String.format(MainApp.sResources.getString(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend()); + else + reply = MainApp.sResources.getString(R.string.smscommunicator_loopisenabled); } else { reply = MainApp.sResources.getString(R.string.smscommunicator_loopisdisabled); } @@ -283,6 +293,35 @@ public class SmsCommunicatorPlugin implements PluginBase { receivedSms.processed = true; Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Status")); break; + case "RESUME": + final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); + activeloop.suspendTo(0); + MainApp.bus().post(new EventRefreshGui(false)); + reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_loopresumed)); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); + Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Resume")); + break; + case "SUSPEND": + if (splited.length >= 3) + duration = SafeParse.stringToInt(splited[2]); + duration = Math.max(0, duration); + duration = Math.min(180, duration); + if (duration == 0) { + reply = MainApp.sResources.getString(R.string.smscommunicator_wrongduration); + sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); + } else if (remoteCommandsAllowed) { + passCode = generatePasscode(); + reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_suspendreplywithcode), duration, passCode); + receivedSms.processed = true; + resetWaitingMessages(); + sendSMS(suspendWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); + suspendWaitingForConfirmation.duration = duration; + Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Suspend")); + } else { + reply = MainApp.sResources.getString(R.string.smscommunicator_remotecommandnotallowed); + sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); + } + break; } break; case "TREATMENTS": @@ -328,7 +367,6 @@ public class SmsCommunicatorPlugin implements PluginBase { break; case "BASAL": if (splited.length > 1) { - boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false); if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) { if (remoteCommandsAllowed) { passCode = generatePasscode(); @@ -366,7 +404,6 @@ public class SmsCommunicatorPlugin implements PluginBase { } else if (splited.length > 1) { amount = SafeParse.stringToDouble(splited[1]); amount = MainApp.getConfigBuilder().applyBolusConstraints(amount); - boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false); if (amount > 0d && remoteCommandsAllowed) { passCode = generatePasscode(); reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusreplywithcode), amount, passCode); @@ -384,7 +421,6 @@ public class SmsCommunicatorPlugin implements PluginBase { case "CAL": if (splited.length > 1) { amount = SafeParse.stringToDouble(splited[1]); - boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false); if (amount > 0d && remoteCommandsAllowed) { passCode = generatePasscode(); reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_calibrationreplywithcode), amount, passCode); @@ -409,12 +445,14 @@ public class SmsCommunicatorPlugin implements PluginBase { PumpEnactResult result = pumpInterface.deliverTreatment(bolusWaitingForConfirmation.bolusRequested, 0, null); if (result.success) { reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered); - if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true); + if (danaRPlugin != null) + reply += "\n" + danaRPlugin.shortStatus(true); lastRemoteBolusTime = new Date(); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); } else { reply = MainApp.sResources.getString(R.string.smscommunicator_bolusfailed); - if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true); + if (danaRPlugin != null) + reply += "\n" + danaRPlugin.shortStatus(true); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); } } @@ -427,11 +465,13 @@ public class SmsCommunicatorPlugin implements PluginBase { PumpEnactResult result = pumpInterface.setTempBasalAbsolute(tempBasalWaitingForConfirmation.tempBasal, 30); if (result.success) { reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_tempbasalset), result.absolute, result.duration); - if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true); + if (danaRPlugin != null) + reply += "\n" + danaRPlugin.shortStatus(true); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); } else { reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalfailed); - if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true); + if (danaRPlugin != null) + reply += "\n" + danaRPlugin.shortStatus(true); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); } } @@ -444,11 +484,13 @@ public class SmsCommunicatorPlugin implements PluginBase { PumpEnactResult result = pumpInterface.cancelTempBasal(); if (result.success) { reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_tempbasalcanceled)); - if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true); + if (danaRPlugin != null) + reply += "\n" + danaRPlugin.shortStatus(true); sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); } else { reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcancelfailed); - if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true); + if (danaRPlugin != null) + reply += "\n" + danaRPlugin.shortStatus(true); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); } } @@ -463,6 +505,14 @@ public class SmsCommunicatorPlugin implements PluginBase { reply = MainApp.sResources.getString(R.string.smscommunicator_calibrationfailed); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); } + } else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed && + suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && new Date().getTime() - suspendWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) { + suspendWaitingForConfirmation.processed = true; + final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); + activeloop.suspendTo(new Date().getTime() + suspendWaitingForConfirmation.duration * 60L * 1000); + MainApp.bus().post(new EventRefreshGui(false)); + reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_loopsuspended)); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); } else { sendSMS(new Sms(receivedSms.phoneNumber, MainApp.sResources.getString(R.string.smscommunicator_unknowncommand), new Date())); } @@ -482,7 +532,7 @@ public class SmsCommunicatorPlugin implements PluginBase { } public void sendSMSToAllNumbers(Sms sms) { - for (String number: allowedNumbers) { + for (String number : allowedNumbers) { sms.phoneNumber = number; sendSMS(sms); } @@ -517,6 +567,7 @@ public class SmsCommunicatorPlugin implements PluginBase { cancelTempBasalWaitingForConfirmation = null; bolusWaitingForConfirmation = null; calibrationWaitingForConfirmation = null; + suspendWaitingForConfirmation = null; } public static String stripAccents(String s) { diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 84c35f78e7..ed59f4f009 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -526,4 +526,9 @@ Pozastavit smyčku na 2 h Pozastavit smyčku na 3 h Zakázat smyčku + Smyčka obnovena + Smyčka pozastavena + Vzdálení příkaz není povolen + K pozastavení smyčky na %d minut odpověz SMS s kódem %s + Chybná doba trvání diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2ac856be38..719d7dc51b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -329,7 +329,9 @@ %.2f limited to %.2f Value %s is out of hard limits Remote basal setting is not allowed + Remote command is not allowed To start basal %.2fU/h reply with code %s + To suspend loop for %d minutes reply with code %s Temp basal %.2fU/h for %d min started successfully Temp basal start failed To stop temp basal reply with code %s @@ -572,4 +574,7 @@ Disconnect pump for 3 h Disconnect pump for 10 h Resume + Wrong duration + Loop suspended + Loop resumed