check for null profile

This commit is contained in:
Milos Kozak 2018-03-17 08:12:07 +01:00
parent b6ce7c03c6
commit 1e359184a9
12 changed files with 48 additions and 49 deletions

View file

@ -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;
/**

View file

@ -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;

View file

@ -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;
}

View file

@ -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);

View file

@ -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<DataPoint> targetsSeries;
Scale targetsScale = new Scale();

View file

@ -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() {

View file

@ -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);

View file

@ -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 = "";

View file

@ -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) + "%");

View file

@ -332,16 +332,16 @@ public class ActionStringHandler {
private static String generateTDDMessage(List<DanaRHistoryRecord> historyList, List<DanaRHistoryRecord> 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;

View file

@ -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;

View file

@ -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;