Merge pull request #324 from AdrianLxM/wear-wizard-percentage
wear wizard percentage
This commit is contained in:
commit
39d41e8e7d
|
@ -189,6 +189,7 @@ public class ActionStringHandler {
|
|||
boolean useBG = Boolean.parseBoolean(act[2]);
|
||||
boolean useBolusIOB = Boolean.parseBoolean(act[3]);
|
||||
boolean useBasalIOB = Boolean.parseBoolean(act[4]);
|
||||
int percentage = Integer.parseInt(act[5]);
|
||||
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
if (profile == null) {
|
||||
|
@ -203,7 +204,7 @@ public class ActionStringHandler {
|
|||
}
|
||||
DecimalFormat format = new DecimalFormat("0.00");
|
||||
BolusWizard bolusWizard = new BolusWizard();
|
||||
bolusWizard.doCalc(profile, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, useBolusIOB, useBasalIOB, false, false);
|
||||
bolusWizard.doCalc(profile, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, percentage, useBolusIOB, useBasalIOB, false, false);
|
||||
|
||||
Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(bolusWizard.calculatedTotalInsulin);
|
||||
if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) {
|
||||
|
@ -233,6 +234,9 @@ public class ActionStringHandler {
|
|||
rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U";
|
||||
if (useBasalIOB)
|
||||
rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U";
|
||||
if(percentage != 100){
|
||||
rMessage += "\nPercentage: " +format.format(bolusWizard.totalBeforePercentageAdjustment) + "U * " + percentage + "% -> ~" + format.format(bolusWizard.calculatedTotalInsulin) + "U";
|
||||
}
|
||||
|
||||
lastBolusWizard = bolusWizard;
|
||||
|
||||
|
|
|
@ -47,9 +47,14 @@ public class BolusWizard {
|
|||
|
||||
// Result
|
||||
public Double calculatedTotalInsulin = 0d;
|
||||
public Double totalBeforePercentageAdjustment = 0d;
|
||||
public Double carbsEquivalent = 0d;
|
||||
|
||||
public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) {
|
||||
return doCalc(specificProfile, carbs, cob, bg, correction, 100d, includeBolusIOB, includeBasalIOB, superBolus, trend);
|
||||
}
|
||||
|
||||
public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, double percentageCorrection, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) {
|
||||
this.specificProfile = specificProfile;
|
||||
this.carbs = carbs;
|
||||
this.bg = bg;
|
||||
|
@ -103,7 +108,13 @@ public class BolusWizard {
|
|||
}
|
||||
|
||||
// Total
|
||||
calculatedTotalInsulin = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB;
|
||||
calculatedTotalInsulin = totalBeforePercentageAdjustment = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB;
|
||||
|
||||
//percentage
|
||||
if(totalBeforePercentageAdjustment > 0){
|
||||
calculatedTotalInsulin = totalBeforePercentageAdjustment*percentageCorrection/100d;
|
||||
}
|
||||
|
||||
|
||||
if (calculatedTotalInsulin < 0) {
|
||||
carbsEquivalent = -calculatedTotalInsulin * ic;
|
||||
|
|
|
@ -2,8 +2,10 @@ package info.nightscout.androidaps.interaction.actions;
|
|||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.wearable.view.DotsPageIndicator;
|
||||
import android.support.wearable.view.GridPagerAdapter;
|
||||
import android.support.wearable.view.GridViewPager;
|
||||
|
@ -28,10 +30,13 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
|
|||
public class WizardActivity extends ViewSelectorActivity {
|
||||
|
||||
PlusMinusEditText editCarbs;
|
||||
PlusMinusEditText editPercentage;
|
||||
|
||||
boolean useBG;
|
||||
boolean includeBolusIOB;
|
||||
boolean includeBasalIOB;
|
||||
boolean hasPercentage;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -43,6 +48,8 @@ public class WizardActivity extends ViewSelectorActivity {
|
|||
pager.setAdapter(new MyGridViewPagerAdapter());
|
||||
DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator);
|
||||
dotsPageIndicator.setPager(pager);
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
hasPercentage = sp.getBoolean("wizardpercentage", false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,7 +63,7 @@ public class WizardActivity extends ViewSelectorActivity {
|
|||
private class MyGridViewPagerAdapter extends GridPagerAdapter {
|
||||
@Override
|
||||
public int getColumnCount(int arg0) {
|
||||
return 5;
|
||||
return hasPercentage?6:5;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -151,6 +158,17 @@ public class WizardActivity extends ViewSelectorActivity {
|
|||
});
|
||||
container.addView(view);
|
||||
return view;
|
||||
} else if(col == 4 && hasPercentage){
|
||||
final View view = getInflatedPlusMinusView(container);
|
||||
if (editPercentage == null) {
|
||||
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 100d, 50d, 150d, 1d, new DecimalFormat("0"), false);
|
||||
} else {
|
||||
double def = SafeParse.stringToDouble(editPercentage.editText.getText().toString());
|
||||
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50d, 150d, 1d, new DecimalFormat("0"), false);
|
||||
}
|
||||
setLabelToPlusMinusView(view, "percentage");
|
||||
container.addView(view);
|
||||
return view;
|
||||
} else {
|
||||
|
||||
final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false);
|
||||
|
@ -162,10 +180,15 @@ public class WizardActivity extends ViewSelectorActivity {
|
|||
//check if it can happen that the fagment is never created that hold data?
|
||||
// (you have to swipe past them anyways - but still)
|
||||
|
||||
int percentage = 100;
|
||||
|
||||
if (editPercentage != null) percentage = SafeParse.stringToInt(editPercentage.editText.getText().toString());
|
||||
|
||||
String actionstring = "wizard " + SafeParse.stringToInt(editCarbs.editText.getText().toString())
|
||||
+ " " + useBG
|
||||
+ " " + includeBolusIOB
|
||||
+ " " + includeBasalIOB;
|
||||
+ " " + includeBasalIOB
|
||||
+ " " + percentage;
|
||||
ListenerService.initiateAction(WizardActivity.this, actionstring);
|
||||
finish();
|
||||
}
|
||||
|
|
|
@ -142,4 +142,11 @@
|
|||
android:title="Single Target"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on"/>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="wizardpercentage"
|
||||
android:summary="Percentage correction."
|
||||
android:title="Wizard Percentage"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
app:wear_iconOn="@drawable/settings_on"/>
|
||||
</PreferenceScreen>
|
||||
|
|
Loading…
Reference in a new issue