diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java index 787f241612..7c59790e35 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java @@ -219,7 +219,7 @@ public class DanaRFragment extends Fragment implements FragmentBase { Long agoMsec = new Date().getTime() - pump.lastBolusTime.getTime(); double agoHours = agoMsec / 60d / 60d / 1000d; if (agoHours < 6) // max 6h back - lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(getPlugin().getDanaRPump().lastBolusAmount) + " U"); + lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " + DecimalFormatter.to2Decimal(getPlugin().getDanaRPump().lastBolusAmount) + " U"); else lastBolusView.setText(""); } @@ -242,7 +242,7 @@ public class DanaRFragment extends Fragment implements FragmentBase { SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d); iobView.setText(pump.iob + " U"); if (pump.isNewPump) { - firmwareView.setText(String.format(getString(R.string.danar_model), pump.model, pump.protocol, pump.productCode)); + firmwareView.setText(String.format(MainApp.sResources.getString(R.string.danar_model), pump.model, pump.protocol, pump.productCode)); } else { firmwareView.setText("OLD"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java index 577e1d3bcf..f2fa7909c7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java @@ -258,6 +258,8 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (!isInitialized()) return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS DanaRPump pump = getDanaRPump(); + if (pump.pumpProfiles == null) + return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS int basalValues = pump.basal48Enable ? 48 : 24; int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60; for (int h = 0; h < basalValues; h++) { @@ -290,17 +292,19 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf @Override public double getTempBasalAbsoluteRate() { - if (isRealTempBasalInProgress()) { - if (getRealTempBasal().isAbsolute) { - return getRealTempBasal().absolute; + TempBasal tb = getRealTempBasal(); + if (tb != null) { + if (tb.isAbsolute) { + return tb.absolute; } else { Double baseRate = getBaseBasalRate(); - Double tempRate = baseRate * (getRealTempBasal().percent / 100d); + Double tempRate = baseRate * (tb.percent / 100d); return tempRate; } } - if (isExtendedBoluslInProgress() && useExtendedBoluses) { - return getBaseBasalRate() + getExtendedBolus().absolute; + TempBasal eb = getExtendedBolus(); + if (eb != null && useExtendedBoluses) { + return getBaseBasalRate() + eb.absolute; } return 0; } @@ -707,11 +711,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf extended.put("PumpIOB", getDanaRPump().iob); extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); - if (isTempBasalInProgress()) { + TempBasal tb = getTempBasal(); + if (tb != null) { extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); - extended.put("TempBasalStart", getTempBasal().timeStart.toLocaleString()); - extended.put("TempBasalRemaining", getTempBasal().getPlannedRemainingMinutes()); - extended.put("IsExtended", getTempBasal().isExtended); + extended.put("TempBasalStart", tb.timeStart.toLocaleString()); + extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); + extended.put("IsExtended", tb.isExtended); } extended.put("BaseBasalRate", getBaseBasalRate()); try { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRStatsActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRStatsActivity.java index 4e75c4c999..1ded51f982 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRStatsActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/History/DanaRStatsActivity.java @@ -56,6 +56,7 @@ import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; public class DanaRStatsActivity extends Activity { @@ -366,7 +367,7 @@ public class DanaRStatsActivity extends Activity { return; } else { - magicNumber = Double.parseDouble(TBB); + magicNumber = SafeParse.stringToDouble(TBB); } magicNumber *=2; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java index f6778ed5f6..4142b43ff6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanFragment.java @@ -240,7 +240,7 @@ public class DanaRKoreanFragment extends Fragment implements FragmentBase { SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d); iobView.setText(pump.iob + " U"); if (pump.isNewPump) { - firmwareView.setText(String.format(getString(R.string.danar_model), pump.model, pump.protocol, pump.productCode)); + firmwareView.setText(String.format(MainApp.sResources.getString(R.string.danar_model), pump.model, pump.protocol, pump.productCode)); } else { firmwareView.setText("OLD"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java index e5b40a60a5..1b3aced79e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/DanaRKoreanPlugin.java @@ -258,6 +258,8 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints if (!isInitialized()) return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS DanaRKoreanPump pump = getDanaRPump(); + if (pump.pumpProfiles == null) + return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS int basalValues = pump.basal48Enable ? 48 : 24; int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60; for (int h = 0; h < basalValues; h++) { @@ -290,17 +292,19 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints @Override public double getTempBasalAbsoluteRate() { - if (isRealTempBasalInProgress()) { - if (getRealTempBasal().isAbsolute) { - return getRealTempBasal().absolute; + TempBasal tb = getRealTempBasal(); + if (tb != null) { + if (tb.isAbsolute) { + return tb.absolute; } else { Double baseRate = getBaseBasalRate(); - Double tempRate = baseRate * (getRealTempBasal().percent / 100d); + Double tempRate = baseRate * (tb.percent / 100d); return tempRate; } } - if (isExtendedBoluslInProgress() && useExtendedBoluses) { - return getBaseBasalRate() + getExtendedBolus().absolute; + TempBasal eb = getExtendedBolus(); + if (eb != null && useExtendedBoluses) { + return getBaseBasalRate() + eb.absolute; } return 0; } @@ -707,11 +711,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints extended.put("PumpIOB", getDanaRPump().iob); // extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); // extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); - if (isTempBasalInProgress()) { + TempBasal tb = getTempBasal(); + if (tb != null) { extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); - extended.put("TempBasalStart", getTempBasal().timeStart.toLocaleString()); - extended.put("TempBasalRemaining", getTempBasal().getPlannedRemainingMinutes()); - extended.put("IsExtended", getTempBasal().isExtended); + extended.put("TempBasalStart", tb.timeStart.toLocaleString()); + extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); + extended.put("IsExtended", tb.isExtended); } extended.put("BaseBasalRate", getBaseBasalRate()); try { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/History/DanaRStatsActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/History/DanaRStatsActivity.java index bf7a7c4321..995924b9c7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/History/DanaRStatsActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaRKorean/History/DanaRStatsActivity.java @@ -56,6 +56,7 @@ import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatu import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus; import info.nightscout.androidaps.plugins.DanaRKorean.Services.ExecutionService; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; public class DanaRStatsActivity extends Activity { @@ -366,7 +367,7 @@ public class DanaRStatsActivity extends Activity { return; } else { - magicNumber = Double.parseDouble(TBB); + magicNumber = SafeParse.stringToDouble(TBB); } magicNumber *=2; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index 537613b9e2..2078e5e2e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -124,7 +124,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL @Override public void run() { if (c.sStatus == c.CONNECTING) { - statusView.setText(String.format(getString(R.string.danar_history_connectingfor), c.sSecondsElapsed)); + statusView.setText(String.format(MainApp.sResources.getString(R.string.danar_history_connectingfor), c.sSecondsElapsed)); } else if (c.sStatus == c.CONNECTED) { statusView.setText(MainApp.sResources.getString(R.string.connected)); } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java index daa882bd8f..8a7a9b00ae 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java @@ -21,6 +21,7 @@ public class Notification { public static final int FAILED_UDPATE_PROFILE = 6; public static final int BASAL_VALUE_BELOW_MINIMUM = 7; public static final int OLD_NSCLIENT = 8; + public static final int INVALID_PHONE_NUMBER = 9; public int id; public Date date; 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 e36bac93b7..2c80489033 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 @@ -237,7 +237,7 @@ public class OverviewFragment extends Fragment { acceptTempButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - MainApp.getConfigBuilder().getActiveLoop().invoke("Accept temp button", false); + ConfigBuilderPlugin.getActiveLoop().invoke("Accept temp button", false); final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.changeRequested) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); @@ -564,7 +564,7 @@ public class OverviewFragment extends Fragment { showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.changeRequested; // change is requested - if (showAcceptButton && pump.isInitialized()) { + if (showAcceptButton && pump.isInitialized() && ConfigBuilderPlugin.getActiveLoop() != null) { acceptTempLayout.setVisibility(View.VISIBLE); acceptTempButton.setText(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed); } else { 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 21e66a37aa..c072c88b59 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 @@ -31,6 +31,8 @@ import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.data.IobTotal; +import info.nightscout.androidaps.plugins.Overview.Notification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS; import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui; import info.nightscout.client.data.NSProfile; @@ -446,8 +448,13 @@ public class SmsCommunicatorPlugin implements PluginBase { SmsManager smsManager = SmsManager.getDefault(); sms.text = stripAccents(sms.text); if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139); - smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null); - messages.add(sms); + try { + smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null); + messages.add(sms); + } catch (IllegalArgumentException e) { + Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.sResources.getString(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL); + MainApp.bus().post(new EventNewNotification(notification)); + } } private String generatePasscode() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java index 54b4070bed..31e369889d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java @@ -113,14 +113,14 @@ public class PersistentNotificationPlugin implements PluginBase{ if(profile != null && lastBG != null) { line1 = lastBG.valueToUnitsToString(profile.getUnits()); - } - if (glucoseStatus != null) { - line1 += " Δ" + deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, profile.getUnits()) - + " avgΔ" + deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, profile.getUnits()); - } else { - line1 += " " + - ctx.getString(R.string.old_data) + - " "; + if (glucoseStatus != null) { + line1 += " Δ" + deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, profile.getUnits()) + + " avgΔ" + deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, profile.getUnits()); + } else { + line1 += " " + + ctx.getString(R.string.old_data) + + " "; + } } PumpInterface pump = MainApp.getConfigBuilder(); diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 231091bed4..8571acf6cc 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -439,4 +439,6 @@ Profil Krátké názvy modulů Firmware: + Špatné telefonní číslo + Chyba nastavování dočasného bazálu diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3bca14fdcc..8769253001 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -475,4 +475,5 @@ Only numeric digits within the range %1$s - %2$s are allowed. The field must not be empty Phone number not valid + Invalid SMS phone number