SMS Plugin allow basal in %

This commit is contained in:
Milos Kozak 2019-03-08 23:48:41 +01:00
parent 95da55724e
commit 56f977df3c
2 changed files with 48 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import android.telephony.SmsMessage;
import com.squareup.otto.Subscribe;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -360,6 +361,51 @@ public class SmsCommunicatorPlugin extends PluginBase {
reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
} else if (splited[1].endsWith("%")) {
int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splited[1],"%"));
Profile profile = ProfileFunctions.getInstance().getProfile();
if (profile == null) {
reply = MainApp.gs(R.string.noprofile);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
} else if (tempBasalPct == 0 && !splited[1].equals("0%")) {
reply = MainApp.gs(R.string.wrongformat);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
} else {
tempBasalPct = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(tempBasalPct), profile).value();
if (remoteCommandsAllowed) {
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) {
@Override
public void run() {
Profile profile = ProfileFunctions.getInstance().getProfile();
if (profile != null)
ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalPercent(anInteger, 30, true, profile, new Callback() {
@Override
public void run() {
if (result.success) {
String reply;
if (result.isPercent)
reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration);
else
reply = String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration);
reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
} else {
String reply = MainApp.gs(R.string.smscommunicator_tempbasalfailed);
reply += "\n" + ConfigBuilderPlugin.getPlugin().getActivePump().shortStatus(true);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
}
});
}
});
} else {
reply = MainApp.gs(R.string.smscommunicator_remotebasalnotallowed);
sendSMS(new Sms(receivedSms.phoneNumber, reply));
}
}
} else {
Double tempBasal = SafeParse.stringToDouble(splited[1]);
Profile profile = ProfileFunctions.getInstance().getProfile();

View file

@ -369,6 +369,7 @@
<string name="smscommunicator_remotebasalnotallowed">Remote basal setting is not allowed</string>
<string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</string>
<string name="smscommunicator_basalreplywithcode">To start basal %1$.2fU/h reply with code %2$s</string>
<string name="smscommunicator_basalpctreplywithcode">To start basal %1$d%% reply with code %2$s</string>
<string name="smscommunicator_suspendreplywithcode">To suspend loop for %1$d minutes reply with code %2$s</string>
<string name="smscommunicator_tempbasalset">Temp basal %1$.2fU/h for %2$d min started successfully</string>
<string name="smscommunicator_tempbasalset_percent">Temp basal %1$d %% for %2$d min started successfully</string>
@ -1315,6 +1316,7 @@
<string name="dst_loop_disabled_warning">Dayligh Saving time change in less than 3 hours - Closed loop diabled</string>
<string name="storage">internal storage constraint</string>
<string name="diskfull">Free at least %1$d MB from internal storage! Loop disabled!</string>
<string name="wrongformat">Wrong format</string>
<plurals name="objective_days">
<item quantity="one">%1$d day</item>
<item quantity="other">%1$d days</item>