From 1e359184a9f25cf47f2625ef073eeed255893b93 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 17 Mar 2018 08:12:07 +0100 Subject: [PATCH] check for null profile --- .../interfaces/InsulinInterface.java | 1 + .../InsulinFastactingProlongedPlugin.java | 1 + .../Overview/Dialogs/WizardDialog.java | 1 + .../plugins/Overview/OverviewFragment.java | 17 ++++++++-------- .../plugins/Overview/graphData/GraphData.java | 7 +------ .../plugins/ProfileNS/NSProfilePlugin.java | 20 ++++++++++--------- .../PumpDanaR/Dialogs/ProfileViewDialog.java | 6 ------ .../SensitivityAAPSPlugin.java | 9 +++++++-- .../TreatmentsTemporaryBasalsFragment.java | 9 +++++++-- .../plugins/Wear/ActionStringHandler.java | 6 +++--- .../XDripStatusline/StatuslinePlugin.java | 15 +++++--------- .../androidaps/queue/CommandQueue.java | 5 +++-- 12 files changed, 48 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java index 0114b8a48d..f7be6883e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.interfaces; import java.util.Date; import info.nightscout.androidaps.data.Iob; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.Treatment; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java index 4155a9be56..d336786f49 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java @@ -4,6 +4,7 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Iob; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 29d23050de..ac03ff2e9e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -404,6 +404,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com if (profile == null) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile)); + dismiss(); return; } 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 dedb3c4842..d347dc6b88 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 @@ -672,7 +672,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); - if (quickWizardEntry != null && actualBg != null) { + if (quickWizardEntry != null && actualBg != null && profile != null) { quickWizardButton.setVisibility(View.VISIBLE); final BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, actualBg, true); @@ -964,16 +964,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); - Profile profile = MainApp.getConfigBuilder().getProfile(); - String units = profile.getUnits(); - - if (units == null) { + final Profile profile = MainApp.getConfigBuilder().getProfile(); + if (profile == null) { pumpStatusView.setText(R.string.noprofileset); pumpStatusLayout.setVisibility(View.VISIBLE); loopStatusLayout.setVisibility(View.GONE); return; } + final String units = profile.getUnits(); final double lowLine = OverviewPlugin.getPlugin().determineLowLine(units); final double highLine = OverviewPlugin.getPlugin().determineHighLine(units); @@ -1092,12 +1091,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (activeTemp != null) { basalText = "T: " + activeTemp.toStringVeryShort(); } else { - basalText = DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + "U/h"; + basalText = DecimalFormatter.to2Decimal(profile.getBasal()) + "U/h"; } baseBasalView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - String fullText = MainApp.sResources.getString(R.string.pump_basebasalrate_label) + ": " + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + "U/h\n"; + String fullText = MainApp.sResources.getString(R.string.pump_basebasalrate_label) + ": " + DecimalFormatter.to2Decimal(profile.getBasal()) + "U/h\n"; if (activeTemp != null) { fullText += MainApp.sResources.getString(R.string.pump_tempbasal_label) + ": " + activeTemp.toStringFull(); } @@ -1110,7 +1109,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, basalText = activeTemp.toStringFull() + " "; } if (Config.NSCLIENT || Config.G5UPLOADER) - basalText += "(" + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + " U/h)"; + basalText += "(" + DecimalFormatter.to2Decimal(profile.getBasal()) + " U/h)"; else if (pump.getPumpDescription().isTempBasalCapable) { basalText += "(" + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + "U/h)"; } @@ -1373,7 +1372,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } // add target line - graphData.addTargetLine(fromTime, toTime); + graphData.addTargetLine(fromTime, toTime, profile); // **** NOW line **** graphData.addNowLine(now); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java index b13ab19219..07c6e8bf96 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java @@ -221,12 +221,7 @@ public class GraphData { addSeries(absoluteBasalsLineSeries); } - public void addTargetLine(long fromTime, long toTime) { - Profile profile = MainApp.getConfigBuilder().getProfile(); - if (profile == null) { - return; - } - + public void addTargetLine(long fromTime, long toTime, Profile profile) { LineGraphSeries targetsSeries; Scale targetsScale = new Scale(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java index 44fbadcac7..4911187db4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java @@ -120,17 +120,19 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface { profile = new ProfileStore(newProfile.getData()); storeNSProfile(); MainApp.bus().post(new EventNSProfileUpdateGUI()); - ConfigBuilderPlugin.getCommandQueue().setProfile(MainApp.getConfigBuilder().getProfile(), new Callback() { - @Override - public void run() { - if (result.enacted) { - SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class); - if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) { - smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok)); + if (MainApp.getConfigBuilder().isProfileValid("storeNewProfile")) { + ConfigBuilderPlugin.getCommandQueue().setProfile(MainApp.getConfigBuilder().getProfile(), new Callback() { + @Override + public void run() { + if (result.enacted) { + SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class); + if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) { + smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok)); + } } } - } - }); + }); + } } private void storeNSProfile() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java index 9bdc0f8b59..d8157281bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Dialogs/ProfileViewDialog.java @@ -85,12 +85,6 @@ public class ProfileViewDialog extends DialogFragment { } private void setContent() { -// if (profile == null) { -// noProfile.setVisibility(View.VISIBLE); -// return; -// } else { -// noProfile.setVisibility(View.GONE); -// } ProfileStore store = ((ProfileInterface)MainApp.getConfigBuilder().getActivePump()).getProfile(); if (store != null) { noProfile.setVisibility(View.GONE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java index ebe8ddfe31..067ecdef8f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java @@ -114,6 +114,13 @@ public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{ if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 4; int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); + Profile profile = MainApp.getConfigBuilder().getProfile(); + + if (profile == null) { + log.debug("No profile"); + return new AutosensResult(); + } + if (autosensDataTable == null || autosensDataTable.size() < 4) { log.debug("No autosens data available"); return new AutosensResult(); @@ -159,8 +166,6 @@ public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{ Double[] deviations = new Double[deviationsArray.size()]; deviations = deviationsArray.toArray(deviations); - Profile profile = MainApp.getConfigBuilder().getProfile(); - double sens = profile.getIsf(); String ratioLimit = ""; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java index 486fe3b733..8f838ee45a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java @@ -88,8 +88,13 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment { holder.duration.setText(DecimalFormatter.to0Decimal(tempBasal.durationInMinutes) + " min"); if (tempBasal.isAbsolute) { Profile profile = MainApp.getConfigBuilder().getProfile(tempBasal.date); - holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.tempBasalConvertedToAbsolute(tempBasal.date, profile)) + " U/h"); - holder.percent.setText(""); + if (profile != null) { + holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.tempBasalConvertedToAbsolute(tempBasal.date, profile)) + " U/h"); + holder.percent.setText(""); + } else { + holder.absolute.setText(MainApp.gs(R.string.noprofile)); + holder.percent.setText(""); + } } else { holder.absolute.setText(""); holder.percent.setText(DecimalFormatter.to0Decimal(tempBasal.percentRate) + "%"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index 270051fbb6..30d0060682 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -332,16 +332,16 @@ public class ActionStringHandler { private static String generateTDDMessage(List historyList, List dummies) { - ProfileInterface activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface(); + Profile profile = MainApp.getConfigBuilder().getProfile(); - if (activeProfile == null) { + if (profile == null) { return "No profile loaded :("; } DateFormat df = new SimpleDateFormat("dd.MM."); String message = ""; - double refTDD = activeProfile.getProfile().getDefaultProfile().baseBasalSum() * 2; + double refTDD = profile.baseBasalSum() * 2; int i = 0; double sum = 0d; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index 7e9619dfb3..76e8ac9e4d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -149,14 +149,13 @@ public class StatuslinePlugin implements PluginBase { private void sendStatus() { - - String status = ""; // sent once on disable - if (fragmentEnabled) { - status = buildStatusString(); - } + Profile profile = MainApp.getConfigBuilder().getProfile(); + if (fragmentEnabled && profile != null) { + status = buildStatusString(profile); + } //sendData final Bundle bundle = new Bundle(); @@ -168,7 +167,7 @@ public class StatuslinePlugin implements PluginBase { } @NonNull - private String buildStatusString() { + private String buildStatusString(Profile profile) { String status = ""; LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); @@ -200,10 +199,6 @@ public class StatuslinePlugin implements PluginBase { + DecimalFormatter.to2Decimal(bolusIob.iob) + "|" + DecimalFormatter.to2Decimal(basalIob.basaliob) + ")"; } - Profile profile = MainApp.getConfigBuilder().getProfile(); - - if (profile == null) - return status; if (!mPrefs.getBoolean("xdripstatus_showbgi", false)) { return status; diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index b41a1727b3..f5cf7e8ecc 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -403,10 +403,11 @@ public class CommandQueue { public boolean isThisProfileSet(Profile profile) { PumpInterface activePump = ConfigBuilderPlugin.getActivePump(); - if (activePump != null) { + Profile current = MainApp.getConfigBuilder().getProfile(); + if (activePump != null && current != null) { boolean result = activePump.isThisProfileSet(profile); if (!result) { - log.debug("Current profile: " + MainApp.getConfigBuilder().getProfile().getData().toString()); + log.debug("Current profile: " + current.getData().toString()); log.debug("New profile: " + profile.getData().toString()); } return result;