split iob in wizard dialog, fixies for no data in app

This commit is contained in:
Milos Kozak 2016-06-27 23:34:33 +02:00
parent af904b24bb
commit caa4f3402e
8 changed files with 145 additions and 65 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
@ -184,12 +185,17 @@ public class MainActivity extends AppCompatActivity {
return newList;
}
@Nullable
public static PluginBase getSpecificPlugin(Class pluginClass) {
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getClass() == pluginClass)
return p;
if (pluginsList != null) {
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getClass() == pluginClass)
return p;
}
} else {
log.debug("pluginsList=null");
}
return null;
}

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.NSProfileViewer;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
@ -22,6 +23,7 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
@ -119,7 +121,7 @@ public class NSProfileViewerFragment extends Fragment implements PluginBase, Pro
private void setContent() {
if (profile == null) {
noProfile.setVisibility(View.VISIBLE);
return;
return;
} else {
noProfile.setVisibility(View.GONE);
}
@ -187,6 +189,9 @@ public class NSProfileViewerFragment extends Fragment implements PluginBase, Pro
} else {
if (Config.logPrefsChange) {
log.debug("Stored profile not found");
// force restart of nsclient to fetch profile
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
}
}
}

View file

@ -46,7 +46,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
Double insulin = SafeParse.stringToDouble(this.insulin.getText().toString());
Integer carbs = SafeParse.stringToInt(this.carbs.getText().toString());
String confirmMessage = getString(R.string.entertreatmentquestion);
String confirmMessage = getString(R.string.entertreatmentquestion) + "\n";
Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin);
Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbs);

View file

@ -35,8 +35,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
TextView bg, bgInsulin, bgUnits;
CheckBox bgCheckbox;
TextView carbs, carbsInsulin;
TextView iob, iobInsulin;
CheckBox iobCheckbox;
TextView bolusIobInsulin;
TextView basalIobInsulin;
CheckBox bolusIobCheckbox;
CheckBox basalIobCheckbox;
TextView correctionInsulin;
TextView total, totalInsulin;
@ -48,20 +50,22 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
final private TextWatcher textWatcher = new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {}
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,int before, int count) {
public void onTextChanged(CharSequence s, int start, int before, int count) {
calculateInsulin();
}
};
final CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener()
{
final CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
calculateInsulin();
}
};
@ -76,29 +80,31 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
correctionInput = (TextView)view.findViewById(R.id.treatments_wizard_correctioninput);
carbsInput = (TextView)view.findViewById(R.id.treatments_wizard_carbsinput);
bgInput = (TextView)view.findViewById(R.id.treatments_wizard_bginput);
correctionInput = (TextView) view.findViewById(R.id.treatments_wizard_correctioninput);
carbsInput = (TextView) view.findViewById(R.id.treatments_wizard_carbsinput);
bgInput = (TextView) view.findViewById(R.id.treatments_wizard_bginput);
correctionInput.addTextChangedListener(textWatcher);
carbsInput.addTextChangedListener(textWatcher);
bgInput.addTextChangedListener(textWatcher);
bg = (TextView)view.findViewById(R.id.treatments_wizard_bg);
bgInsulin = (TextView)view.findViewById(R.id.treatments_wizard_bginsulin);
bgUnits = (TextView)view.findViewById(R.id.treatments_wizard_bgunits);
bg = (TextView) view.findViewById(R.id.treatments_wizard_bg);
bgInsulin = (TextView) view.findViewById(R.id.treatments_wizard_bginsulin);
bgUnits = (TextView) view.findViewById(R.id.treatments_wizard_bgunits);
bgCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgcheckbox);
carbs = (TextView)view.findViewById(R.id.treatments_wizard_carbs);
carbsInsulin = (TextView)view.findViewById(R.id.treatments_wizard_carbsinsulin);
iob = (TextView)view.findViewById(R.id.treatments_wizard_iob);
iobInsulin = (TextView)view.findViewById(R.id.treatments_wizard_iobinsulin);
iobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_iobcheckbox);
correctionInsulin = (TextView)view.findViewById(R.id.treatments_wizard_correctioninsulin);
total = (TextView)view.findViewById(R.id.treatments_wizard_total);
totalInsulin = (TextView)view.findViewById(R.id.treatments_wizard_totalinsulin);
carbs = (TextView) view.findViewById(R.id.treatments_wizard_carbs);
carbsInsulin = (TextView) view.findViewById(R.id.treatments_wizard_carbsinsulin);
bolusIobInsulin = (TextView) view.findViewById(R.id.treatments_wizard_bolusiobinsulin);
basalIobInsulin = (TextView) view.findViewById(R.id.treatments_wizard_basaliobinsulin);
bolusIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bolusiobcheckbox);
basalIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_basaliobcheckbox);
correctionInsulin = (TextView) view.findViewById(R.id.treatments_wizard_correctioninsulin);
total = (TextView) view.findViewById(R.id.treatments_wizard_total);
totalInsulin = (TextView) view.findViewById(R.id.treatments_wizard_totalinsulin);
bgCheckbox.setOnCheckedChangeListener(onCheckedChangeListener);
iobCheckbox.setOnCheckedChangeListener(onCheckedChangeListener);
basalIobCheckbox.setOnCheckedChangeListener(onCheckedChangeListener);
bolusIobCheckbox.setOnCheckedChangeListener(onCheckedChangeListener);
initDialog();
return view;
@ -108,7 +114,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
public void onClick(View view) {
switch (view.getId()) {
case R.id.treatments_wizard_deliverButton:
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d){
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) {
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
String confirmMessage = getString(R.string.entertreatmentquestion);
@ -118,7 +124,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
confirmMessage += "\n" + getString(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U";
confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g";
if (insulinAfterConstraints != calculatedTotalInsulin || carbsAfterConstraints != calculatedCarbs) {
if (insulinAfterConstraints - calculatedTotalInsulin != 0 || carbsAfterConstraints != calculatedCarbs) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror));
builder.setMessage(getString(R.string.constraints_violation) + "\n" + getString(R.string.changeyourinput));
@ -162,7 +168,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
if (profile == null) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), "No profile loaded from NS yet");
dismiss();
return;
}
@ -175,8 +180,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
if (lastBg != null) {
Double lastBgValue = lastBg.valueToUnits(units);
Double sens = profile.getIsf(NSProfile.secondsFromMidnight());
Double targetBGLow = profile.getTargetLow(NSProfile.secondsFromMidnight());
Double targetBGHigh = profile.getTargetHigh(NSProfile.secondsFromMidnight());
Double targetBGLow = profile.getTargetLow(NSProfile.secondsFromMidnight());
Double targetBGHigh = profile.getTargetHigh(NSProfile.secondsFromMidnight());
Double bgDiff;
if (lastBgValue <= targetBGLow) {
bgDiff = lastBgValue - targetBGLow;
@ -186,11 +191,15 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
bg.setText(lastBg.valueToUnitsToString(units) + " ISF: " + intFormat.format(sens));
bgInsulin.setText(numberFormat.format(bgDiff / sens) + "U");
bgInput.removeTextChangedListener(textWatcher);
bgInput.setText(lastBg.valueToUnitsToString(units));
bgInput.addTextChangedListener(textWatcher);
} else {
bg.setText("");
bgInsulin.setText("");
bgInput.removeTextChangedListener(textWatcher);
bgInput.setText("");
bgInput.addTextChangedListener(textWatcher);
}
// IOB calculation
@ -201,8 +210,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
IobTotal bolusIob = treatments.getLastCalculation();
IobTotal basalIob = tempBasals.getLastCalculation();
Double iobTotal = bolusIob.iob + basalIob.iob;
iobInsulin.setText("-" + numberFormat.format(iobTotal) + "U");
bolusIobInsulin.setText("-" + numberFormat.format(bolusIob.iob) + "U");
basalIobInsulin.setText("-" + numberFormat.format(basalIob.basaliob) + "U");
totalInsulin.setText("");
wizardDialogDeliverButton.setVisibility(Button.GONE);
@ -216,29 +225,37 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
Double c_bg = SafeParse.stringToDouble(this.bgInput.getText().toString());
Integer c_carbs = SafeParse.stringToInt(this.carbsInput.getText().toString());
Double c_correction = SafeParse.stringToDouble(this.correctionInput.getText().toString());
if(c_correction != MainApp.getConfigBuilder().applyBolusConstraints(c_correction)) {
this.correctionInput.setText("");
wizardDialogDeliverButton.setVisibility(Button.GONE);
Double corrAfterConstraint = MainApp.getConfigBuilder().applyBolusConstraints(c_correction);
if (c_correction - corrAfterConstraint != 0) { // c_correction != corrAfterConstraint doesn't work
correctionInput.removeTextChangedListener(textWatcher);
correctionInput.setText("");
correctionInput.addTextChangedListener(textWatcher);
//wizardDialogDeliverButton.setVisibility(Button.GONE);
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.bolusconstraintapplied));
return;
}
if(c_carbs != MainApp.getConfigBuilder().applyCarbsConstraints(c_carbs)) {
this.carbsInput.setText("");
wizardDialogDeliverButton.setVisibility(Button.GONE);
Integer carbsAfterConstraint = MainApp.getConfigBuilder().applyCarbsConstraints(c_carbs);
if (c_carbs != carbsAfterConstraint) {
carbsInput.removeTextChangedListener(textWatcher);
carbsInput.setText("");
carbsInput.addTextChangedListener(textWatcher);
//wizardDialogDeliverButton.setVisibility(Button.GONE);
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.carbsconstraintapplied));
return;
}
// Insulin from BG
Double sens = profile.getIsf(NSProfile.secondsFromMidnight());
Double targetBGLow = profile.getTargetLow(NSProfile.secondsFromMidnight());
Double targetBGHigh = profile.getTargetHigh(NSProfile.secondsFromMidnight());
Double targetBGLow = profile.getTargetLow(NSProfile.secondsFromMidnight());
Double targetBGHigh = profile.getTargetHigh(NSProfile.secondsFromMidnight());
Double bgDiff;
if (c_bg <= targetBGLow) {
bgDiff = c_bg - targetBGLow;
} else {
bgDiff = c_bg - targetBGHigh;
}
Double insulinFromBG = (bgCheckbox.isChecked() && c_bg != 0d) ? bgDiff /sens : 0d;
Double insulinFromBG = (bgCheckbox.isChecked() && c_bg != 0d) ? bgDiff / sens : 0d;
bg.setText(c_bg + " ISF: " + intFormat.format(sens));
bgInsulin.setText(numberFormat.format(insulinFromBG) + "U");
@ -256,16 +273,17 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
IobTotal bolusIob = treatments.getLastCalculation();
IobTotal basalIob = tempBasals.getLastCalculation();
Double iobTotal = bolusIob.iob + basalIob.iob;
Double insulingFromIOB = iobCheckbox.isChecked() ? iobTotal : 0d;
iobInsulin.setText("-" + numberFormat.format(insulingFromIOB) + "U");
Double insulingFromBolusIOB = bolusIobCheckbox.isChecked() ? -bolusIob.iob : 0d;
Double insulingFromBasalsIOB = basalIobCheckbox.isChecked() ? -basalIob.basaliob : 0d;
bolusIobInsulin.setText(numberFormat.format(insulingFromBolusIOB) + "U");
basalIobInsulin.setText(numberFormat.format(insulingFromBasalsIOB) + "U");
// Insulin from correction
Double insulinFromCorrection = c_correction;
Double insulinFromCorrection = corrAfterConstraint;
correctionInsulin.setText(numberFormat.format(insulinFromCorrection) + "U");
// Total
calculatedTotalInsulin = insulinFromBG + insulinFromCarbs - insulingFromIOB + insulinFromCorrection;
calculatedTotalInsulin = insulinFromBG + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection;
if (calculatedTotalInsulin < 0) {
Double carbsEquivalent = -calculatedTotalInsulin * ic;

View file

@ -377,11 +377,6 @@ public class OverviewFragment extends Fragment implements PluginBase {
BgReading lastBG = MainApp.getDbHelper().lastBg();
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null) // app not initialized yet
return;
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
if (profile == null)
return;
String units = profile.getUnits();
// Skip if not initialized yet
if (bgGraph == null)
@ -412,6 +407,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
}
// **** Temp button ****
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
if (pump.isTempBasalInProgress()) {
@ -427,6 +423,22 @@ public class OverviewFragment extends Fragment implements PluginBase {
runningTempView.setText(formatNumber2decimalplaces.format(currentBasal) + " U/h");
}
if (profile == null) {
// disable all treatment buttons because we are not able to check constraints without profile
setExtenedButton.setVisibility(View.INVISIBLE);
setTempLayout.setVisibility(View.INVISIBLE);
wizardButton.setVisibility(View.INVISIBLE);
treatmentButton.setVisibility(View.INVISIBLE);
return;
} else {
setExtenedButton.setVisibility(View.VISIBLE);
setTempLayout.setVisibility(View.VISIBLE);
wizardButton.setVisibility(View.VISIBLE);
treatmentButton.setVisibility(View.VISIBLE);
}
String units = profile.getUnits();
// **** BG value ****
if (profile != null && lastBG != null && bgView != null) {
bgView.setText(lastBG.valueToUnitsToString(profile.getUnits()));

View file

@ -204,28 +204,64 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="32dp"
android:id="@+id/treatments_wizard_iobcheckbox"
android:id="@+id/treatments_wizard_bolusiobcheckbox"
android:checked="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/treatments_wizard_iob_label"
android:width="50dp" />
android:text="@string/treatments_wizard_bolusiob_label"
android:width="100dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:width="100dp"
android:id="@+id/treatments_wizard_iob" />
android:width="50dp"
android:id="@+id/treatments_wizard_bolusiob" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/treatments_wizard_iobinsulin"
android:id="@+id/treatments_wizard_bolusiobinsulin"
android:width="50dp"
android:gravity="end" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="32dp"
android:id="@+id/treatments_wizard_basaliobcheckbox"
android:checked="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/treatments_wizard_basaliob_label"
android:width="100dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:width="50dp"
android:id="@+id/treatments_wizard_basaliob" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/treatments_wizard_basaliobinsulin"
android:width="50dp"
android:gravity="end" />
</LinearLayout>

View file

@ -47,7 +47,7 @@
<string name="treatments_wizard_carbs_label">Carbs</string>
<string name="treatments_wizard_correction_label">Corr</string>
<string name="treatments_wizard_unit_label">U</string>
<string name="treatments_wizard_iob_label">IOB</string>
<string name="treatments_wizard_bolusiob_label">Bolus IOB</string>
<string name="treatments_wizard_total_label">TOTAL</string>
<string name="openapsma_run">Run now</string>
<string name="vitualpump_label">VIRTUAL PUMP</string>
@ -156,5 +156,8 @@
<string name="loopdisabled">LOOP DISABLED BY CONSTRAINTS</string>
<string name="cs_lang">Czech language</string>
<string name="en_lang">English language</string>
<string name="treatments_wizard_basaliob_label">Basal IOB</string>
<string name="bolusconstraintapplied">Bolus constraint applied</string>
<string name="carbsconstraintapplied">Carbs constraint applied</string>
</resources>