diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index b088c25adf..0934e68ec3 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -98,6 +98,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre addPreferencesFromResource(R.xml.pref_mm640g); if (Config.SMSCOMMUNICATORENABLED) addPreferencesFromResource(R.xml.pref_smscommunicator); + addPreferencesFromResource(R.xml.pref_others); initSummary(getPreferenceScreen()); } diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index c9159e6177..2b413fbe43 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -16,6 +16,8 @@ import info.nightscout.client.data.NSProfile; */ public interface PumpInterface { + boolean isInitialized(); + boolean isTempBasalInProgress(); boolean isExtendedBoluslInProgress(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java index 2317c59983..a170ea0e02 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java @@ -2,9 +2,11 @@ package info.nightscout.androidaps.plugins.Actions.dialogs; import android.content.Context; import android.content.DialogInterface; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; +import android.preference.PreferenceManager; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; @@ -24,6 +26,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; @@ -32,6 +35,10 @@ public class FillDialog extends DialogFragment implements OnClickListener { Button deliverButton; TextView insulin; + double amount1 = 0d; + double amount2 = 0d; + double amount3 = 0d; + PlusMinusEditText editInsulin; Handler mHandler; @@ -59,6 +66,42 @@ public class FillDialog extends DialogFragment implements OnClickListener { editInsulin = new PlusMinusEditText(view, R.id.treatments_newtreatment_insulinamount, R.id.treatments_newtreatment_insulinamount_plus, R.id.treatments_newtreatment_insulinamount_minus, 0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false); + //setup preset buttons + Button button1 = (Button) view.findViewById(R.id.fill_preset_button1); + Button button2 = (Button) view.findViewById(R.id.fill_preset_button2); + Button button3 = (Button) view.findViewById(R.id.fill_preset_button3); + View divider = view.findViewById(R.id.fill_preset_divider); + + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); + amount1 = SafeParse.stringToDouble(DecimalFormatter.to2Decimal(SafeParse.stringToDouble(sp.getString("fill_button1", "0.3")))); + amount2 = SafeParse.stringToDouble(DecimalFormatter.to2Decimal(SafeParse.stringToDouble(sp.getString("fill_button2", "0")))); + amount3 = SafeParse.stringToDouble(DecimalFormatter.to2Decimal(SafeParse.stringToDouble(sp.getString("fill_button3", "0")))); + + if(amount1 >0) { + button1.setVisibility(View.VISIBLE); + button1.setText(DecimalFormatter.to2Decimal(amount1) + "U"); + button1.setOnClickListener(this); + } else { + button1.setVisibility(View.GONE); + } + if(amount2 >0) { + button2.setVisibility(View.VISIBLE); + button2.setText(DecimalFormatter.to2Decimal(amount2) + "U"); + button2.setOnClickListener(this); + } else { + button2.setVisibility(View.GONE); + } + if(amount3 >0) { + button3.setVisibility(View.VISIBLE); + button3.setText(DecimalFormatter.to2Decimal(amount3) + "U"); + button3.setOnClickListener(this); + } else { + button3.setVisibility(View.GONE); + } + + if (button1.getVisibility() == View.GONE && button2.getVisibility() == View.GONE && button3.getVisibility() == View.GONE ) { + divider.setVisibility(View.GONE); + } return view; } @@ -73,53 +116,65 @@ public class FillDialog extends DialogFragment implements OnClickListener { public void onClick(View view) { switch (view.getId()) { case R.id.treatments_newtreatment_deliverbutton: - - try { - Double insulin = SafeParse.stringToDouble(this.insulin.getText().toString()); - - String confirmMessage = getString(R.string.fillwarning) + "\n"; - - Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin); - confirmMessage += getString(R.string.bolus) + ": " + insulinAfterConstraints + "U"; - if (insulinAfterConstraints - insulin != 0) - confirmMessage += "\n" + getString(R.string.constraintapllied); - - final Double finalInsulinAfterConstraints = insulinAfterConstraints; - - final Context context = getContext(); - AlertDialog.Builder builder = new AlertDialog.Builder(context); - - builder.setTitle(this.getContext().getString(R.string.confirmation)); - builder.setMessage(confirmMessage); - builder.setPositiveButton(getString(R.string.primefill), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - if (finalInsulinAfterConstraints > 0) { - final ConfigBuilderPlugin pump = MainApp.getConfigBuilder(); - mHandler.post(new Runnable() { - @Override - public void run() { - PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, 0, context, false); - if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); - builder.setMessage(result.comment); - builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); - builder.show(); - } - } - }); - } - } - }); - builder.setNegativeButton(getString(R.string.cancel), null); - builder.show(); - dismiss(); - } catch (Exception e) { - e.printStackTrace(); - } + Double insulin = SafeParse.stringToDouble(this.insulin.getText().toString()); + confirmAndDeliver(insulin); + break; + case R.id.fill_preset_button1: + confirmAndDeliver(amount1); + break; + case R.id.fill_preset_button2: + confirmAndDeliver(amount2); + break; + case R.id.fill_preset_button3: + confirmAndDeliver(amount3); break; } } + private void confirmAndDeliver(Double insulin) { + try { + + String confirmMessage = getString(R.string.fillwarning) + "\n"; + + Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin); + confirmMessage += getString(R.string.bolus) + ": " + insulinAfterConstraints + "U"; + if (insulinAfterConstraints - insulin != 0) + confirmMessage += "\n" + getString(R.string.constraintapllied); + + final Double finalInsulinAfterConstraints = insulinAfterConstraints; + + final Context context = getContext(); + AlertDialog.Builder builder = new AlertDialog.Builder(context); + + builder.setTitle(this.getContext().getString(R.string.confirmation)); + builder.setMessage(confirmMessage); + builder.setPositiveButton(getString(R.string.primefill), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + if (finalInsulinAfterConstraints > 0) { + final ConfigBuilderPlugin pump = MainApp.getConfigBuilder(); + mHandler.post(new Runnable() { + @Override + public void run() { + PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, 0, context, false); + if (!result.success) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); + builder.setMessage(result.comment); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); + builder.show(); + } + } + }); + } + } + }); + builder.setNegativeButton(getString(R.string.cancel), null); + builder.show(); + dismiss(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 2e0696c228..65660492be 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -294,10 +294,15 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } /* - * Pump interface - * - * Config builder return itself as a pump and check constraints before it passes command to pump driver - */ + * Pump interface + * + * Config builder return itself as a pump and check constraints before it passes command to pump driver + */ + @Override + public boolean isInitialized() { + return activePump.isInitialized(); + } + @Override public boolean isTempBasalInProgress() { return activePump.isTempBasalInProgress(); @@ -533,9 +538,16 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain request.rate = applyBasalConstraints(request.rate); PumpEnactResult result; + if (!isInitialized()) { + result = new PumpEnactResult(); + result.comment = MainApp.sResources.getString(R.string.pumpNotInitialized); + result.enacted = false; + result.success = false; + } + if (Config.logCongigBuilderActions) log.debug("applyAPSRequest: " + request.toString()); - if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - getBaseBasalRate()) < 0.1) { + if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - getBaseBasalRate()) < 0.05) { if (isTempBasalInProgress()) { if (Config.logCongigBuilderActions) log.debug("applyAPSRequest: cancelTempBasal()"); @@ -550,7 +562,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain if (Config.logCongigBuilderActions) log.debug("applyAPSRequest: Basal set correctly"); } - } else if (isTempBasalInProgress() && Math.abs(request.rate - getTempBasalAbsoluteRate()) < 0.1) { + } else if (isTempBasalInProgress() && Math.abs(request.rate - getTempBasalAbsoluteRate()) < 0.05) { result = new PumpEnactResult(); result.absolute = getTempBasalAbsoluteRate(); result.duration = activePump.getTempBasal().getPlannedRemainingMinutes(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java index d5d7966a56..5501319e99 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java @@ -150,6 +150,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf this.fragmentPumpVisible = fragmentVisible; } + @Override + public boolean isInitialized() { + return getDanaRPump().lastConnection.getTime() > 0; + } + // Pump interface @Override public boolean isTempBasalInProgress() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/MM640g/MM640gPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/MM640g/MM640gPlugin.java index 6fd3ea5493..7361054a3e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/MM640g/MM640gPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/MM640g/MM640gPlugin.java @@ -94,6 +94,11 @@ public class MM640gPlugin implements PluginBase, PumpInterface, BgSourceInterfac * Pump Interface */ + @Override + public boolean isInitialized() { + return false; + } + @Override public boolean isTempBasalInProgress() { return false; 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 e255c54ace..7cff64a3da 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 @@ -486,7 +486,10 @@ public class OverviewFragment extends Fragment { runningTempView.setVisibility(View.GONE); } baseBasalView.setText(DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + " U/h"); - activeProfileView.setText(profile.getActiveProfile()); + + if (profile != null && profile.getActiveProfile() != null) + activeProfileView.setText(profile.getActiveProfile()); + activeProfileView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java index a5f05acbc6..99508d2c7e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpPlugin.java @@ -77,6 +77,11 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { return PluginBase.PUMP; } + @Override + public boolean isInitialized() { + return true; + } + @Override public boolean isTempBasalInProgress() { return getTempBasal() != null; diff --git a/app/src/main/res/layout/actions_fill_dialog.xml b/app/src/main/res/layout/actions_fill_dialog.xml index 6394ccf304..e6fb0b05ee 100644 --- a/app/src/main/res/layout/actions_fill_dialog.xml +++ b/app/src/main/res/layout/actions_fill_dialog.xml @@ -73,5 +73,52 @@ + + + + +