commit
61e6404bbe
|
@ -1,7 +1,9 @@
|
|||
package info.nightscout.androidaps.plugins.Wear;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.HandlerThread;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
|
@ -19,6 +21,7 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.CareportalEvent;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
|
@ -35,6 +38,7 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo;
|
|||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
|
@ -52,6 +56,8 @@ import info.nightscout.utils.SP;
|
|||
import info.nightscout.utils.SafeParse;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
import static info.nightscout.utils.DateUtil.now;
|
||||
|
||||
/**
|
||||
* Created by adrian on 09/02/17.
|
||||
*/
|
||||
|
@ -326,6 +332,27 @@ public class ActionStringHandler {
|
|||
}
|
||||
}
|
||||
|
||||
} else if ("ecarbs".equals(act[0])) {
|
||||
////////////////////////////////////////////// ECARBS
|
||||
int carbs = SafeParse.stringToInt(act[1]);
|
||||
int starttime = SafeParse.stringToInt(act[2]);
|
||||
int duration = SafeParse.stringToInt(act[3]);
|
||||
long starttimestamp = System.currentTimeMillis() + starttime*60*1000;
|
||||
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbs)).value();
|
||||
rMessage += MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g";
|
||||
rMessage += "\n" + MainApp.gs(R.string.time) + ": " + DateUtil.timeString(starttimestamp);
|
||||
rMessage += "\n" + MainApp.gs(R.string.duration) + ": " + duration + "h";
|
||||
|
||||
|
||||
if ( (carbsAfterConstraints - carbs != 0)) {
|
||||
rMessage += "\n" + MainApp.gs(R.string.constraintapllied);
|
||||
}
|
||||
if(carbsAfterConstraints <= 0){
|
||||
sendError("Carbs = 0! No action taken!");
|
||||
return;
|
||||
}
|
||||
rAction += "ecarbs " + carbsAfterConstraints + " " + starttimestamp + " " + duration;
|
||||
|
||||
} else return;
|
||||
|
||||
|
||||
|
@ -578,7 +605,7 @@ public class ActionStringHandler {
|
|||
high *= Constants.MMOLL_TO_MGDL;
|
||||
}
|
||||
generateTempTarget(duration, low, high);
|
||||
} else if ("wizard".equals(act[0])) {
|
||||
} else if ("wizard2".equals(act[0])) {
|
||||
//use last calculation as confirmed string matches
|
||||
|
||||
doBolus(lastBolusWizard.calculatedTotalInsulin, lastBolusWizard.carbs);
|
||||
|
@ -591,12 +618,64 @@ public class ActionStringHandler {
|
|||
int timeshift = SafeParse.stringToInt(act[1]);
|
||||
int percentage = SafeParse.stringToInt(act[2]);
|
||||
setCPP(timeshift, percentage);
|
||||
} else if ("ecarbs".equals(act[0])) {
|
||||
int carbs = SafeParse.stringToInt(act[1]);
|
||||
long starttime = SafeParse.stringToLong(act[2]);
|
||||
int duration = SafeParse.stringToInt(act[3]);
|
||||
|
||||
doECarbs(carbs, starttime, duration);
|
||||
} else if ("dismissoverviewnotification".equals(act[0])) {
|
||||
MainApp.bus().post(new EventDismissNotification(SafeParse.stringToInt(act[1])));
|
||||
}
|
||||
lastBolusWizard = null;
|
||||
}
|
||||
|
||||
private static void doECarbs(int carbs, long time, int duration) {
|
||||
if (carbs > 0) {
|
||||
if (duration == 0) {
|
||||
createCarb(carbs, time, "watch");
|
||||
} else {
|
||||
long remainingCarbs = carbs;
|
||||
int ticks = (duration * 4); //duration guaranteed to be integer greater zero
|
||||
for (int i = 0; i < ticks; i++){
|
||||
long carbTime = time + i * 15 * 60 * 1000;
|
||||
long smallCarbAmount = Math.round((1d * remainingCarbs) / (ticks-i)); //on last iteration (ticks-i) is 1 -> smallCarbAmount == remainingCarbs
|
||||
remainingCarbs -= smallCarbAmount;
|
||||
if (smallCarbAmount > 0)
|
||||
createCarb(smallCarbAmount, carbTime, "watch eCarbs");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void createCarb(long carbs, long time, @Nullable String notes) {
|
||||
DetailedBolusInfo carbInfo = new DetailedBolusInfo();
|
||||
carbInfo.date = time;
|
||||
carbInfo.eventType = CareportalEvent.CARBCORRECTION;
|
||||
carbInfo.carbs = carbs;
|
||||
carbInfo.context = MainApp.instance();
|
||||
carbInfo.source = Source.USER;
|
||||
carbInfo.notes = notes;
|
||||
if (ConfigBuilderPlugin.getActivePump().getPumpDescription().storesCarbInfo && carbInfo.date <= now()) {
|
||||
ConfigBuilderPlugin.getCommandQueue().bolus(carbInfo, new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!result.success) {
|
||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.boluserror);
|
||||
i.putExtra("status", result.comment);
|
||||
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror));
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
MainApp.instance().startActivity(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(carbInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void setCPP(int timeshift, int percentage) {
|
||||
|
||||
String msg = "";
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
android:key="wearplugin"
|
||||
android:title="@string/wear_display_settings">
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:defaultValue="false"
|
||||
android:key="wear_detailediob"
|
||||
android:summary="@string/wear_detailedIOB_summary"
|
||||
android:title="@string/wear_detailedIOB_title" />
|
||||
|
|
|
@ -208,6 +208,10 @@
|
|||
android:name=".interaction.actions.FillActivity"
|
||||
android:label="Fill">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".interaction.actions.ECarbActivity"
|
||||
android:label="Fill">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".interaction.actions.TempTargetActivity"
|
||||
android:label="TempTarget">
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
package info.nightscout.androidaps.interaction.actions;
|
||||
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.wearable.view.DotsPageIndicator;
|
||||
import android.support.wearable.view.GridPagerAdapter;
|
||||
import android.support.wearable.view.GridViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.ListenerService;
|
||||
import info.nightscout.androidaps.interaction.utils.PlusMinusEditText;
|
||||
import info.nightscout.androidaps.interaction.utils.SafeParse;
|
||||
|
||||
/**
|
||||
* Created by adrian on 04/08/18.
|
||||
*/
|
||||
|
||||
|
||||
public class ECarbActivity extends ViewSelectorActivity {
|
||||
|
||||
PlusMinusEditText editCarbs;
|
||||
PlusMinusEditText editStartTime;
|
||||
PlusMinusEditText editDuration;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.grid_layout);
|
||||
final Resources res = getResources();
|
||||
final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);
|
||||
|
||||
pager.setAdapter(new MyGridViewPagerAdapter());
|
||||
DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator);
|
||||
dotsPageIndicator.setPager(pager);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
private class MyGridViewPagerAdapter extends GridPagerAdapter {
|
||||
@Override
|
||||
public int getColumnCount(int arg0) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int row, int col) {
|
||||
|
||||
if(col == 0){
|
||||
final View view = getInflatedPlusMinusView(container);
|
||||
double def = 0;
|
||||
if (editCarbs != null){
|
||||
def = SafeParse.stringToDouble(editCarbs.editText.getText().toString());
|
||||
}
|
||||
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 150d, 1d, new DecimalFormat("0"), true);
|
||||
setLabelToPlusMinusView(view, "carbs");
|
||||
container.addView(view);
|
||||
return view;
|
||||
} else if(col == 1){
|
||||
final View view = getInflatedPlusMinusView(container);
|
||||
double def = 0;
|
||||
if (editStartTime != null){
|
||||
def = SafeParse.stringToDouble(editStartTime.editText.getText().toString());
|
||||
}
|
||||
editStartTime = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 300d, 15d, new DecimalFormat("0"), false);
|
||||
setLabelToPlusMinusView(view, "start [min]");
|
||||
container.addView(view);
|
||||
return view;
|
||||
} else if(col == 2){
|
||||
final View view = getInflatedPlusMinusView(container);
|
||||
double def = 0;
|
||||
if (editDuration != null){
|
||||
def = SafeParse.stringToDouble(editDuration.editText.getText().toString());
|
||||
}
|
||||
editDuration = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 8d, 1d, new DecimalFormat("0"), false);
|
||||
setLabelToPlusMinusView(view, "duration [h]");
|
||||
container.addView(view);
|
||||
return view;
|
||||
} else {
|
||||
|
||||
final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false);
|
||||
final ImageView confirmbutton = (ImageView) view.findViewById(R.id.confirmbutton);
|
||||
confirmbutton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
//check if it can happen that the fagment is never created that hold data?
|
||||
// (you have to swipe past them anyways - but still)
|
||||
|
||||
String actionstring = "ecarbs " +SafeParse.stringToInt(editCarbs.editText.getText().toString())
|
||||
+ " " + SafeParse.stringToInt(editStartTime.editText.getText().toString())
|
||||
+ " " + SafeParse.stringToInt(editDuration.editText.getText().toString());
|
||||
ListenerService.initiateAction(ECarbActivity.this, actionstring);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
container.addView(view);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int row, int col, Object view) {
|
||||
// Handle this to get the data before the view is destroyed?
|
||||
// Object should still be kept by this, just setup for reinit?
|
||||
container.removeView((View)view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
return view==object;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -7,10 +7,10 @@ import android.preference.PreferenceManager;
|
|||
|
||||
import java.util.Vector;
|
||||
|
||||
import info.nightscout.androidaps.BuildConfig;
|
||||
import info.nightscout.androidaps.data.ListenerService;
|
||||
import info.nightscout.androidaps.interaction.AAPSPreferences;
|
||||
import info.nightscout.androidaps.interaction.actions.BolusActivity;
|
||||
import info.nightscout.androidaps.interaction.actions.ECarbActivity;
|
||||
import info.nightscout.androidaps.interaction.actions.TempTargetActivity;
|
||||
import info.nightscout.androidaps.interaction.utils.MenuListActivity;
|
||||
import info.nightscout.androidaps.interaction.actions.WizardActivity;
|
||||
|
@ -47,6 +47,7 @@ public class MainMenuActivity extends MenuListActivity {
|
|||
Vector<String> menuitems = new Vector<String>();
|
||||
menuitems.add("TempT");
|
||||
if(showWizard) menuitems.add("Wizard");
|
||||
menuitems.add("eCarb");
|
||||
menuitems.add("Bolus");
|
||||
menuitems.add("Settings");
|
||||
menuitems.add("Status");
|
||||
|
@ -86,6 +87,10 @@ public class MainMenuActivity extends MenuListActivity {
|
|||
intent = new Intent(this, FillMenuActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
this.startActivity(intent);
|
||||
}
|
||||
} else if ("eCarb".equals(action)) {
|
||||
intent = new Intent(this, ECarbActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
this.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue