From 2f16c9b998b012b532ee51ec509fa0b45b7d368f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 26 Jun 2016 11:43:26 +0200 Subject: [PATCH] open loop mode & notification --- .../info/nightscout/androidaps/Config.java | 2 +- .../info/nightscout/androidaps/Constants.java | 4 + .../androidaps/PreferencesActivity.java | 2 + .../events/EventRefreshOpenLoop.java | 7 ++ .../interfaces/ConstraintsInterface.java | 3 +- .../ConfigBuilder/ConfigBuilderFragment.java | 17 +-- .../androidaps/plugins/Loop/LoopFragment.java | 113 +++++++++++------- .../Objectives/ObjectivesFragment.java | 8 +- .../Overview/Dialogs/WizardDialog.java | 2 +- .../plugins/Overview/OverviewFragment.java | 111 ++++++++++++++++- .../SafetyFragment/SafetyFragment.java | 11 +- app/src/main/res/drawable/loopmodeborder.xml | 7 ++ app/src/main/res/layout/overview_fragment.xml | 68 ++++++++--- app/src/main/res/values/arrays.xml | 12 ++ app/src/main/res/values/colors.xml | 3 +- app/src/main/res/values/strings.xml | 9 +- app/src/main/res/xml/pref_closedmode.xml | 15 +++ 17 files changed, 296 insertions(+), 98 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/events/EventRefreshOpenLoop.java create mode 100644 app/src/main/res/drawable/loopmodeborder.xml create mode 100644 app/src/main/res/values/arrays.xml create mode 100644 app/src/main/res/xml/pref_closedmode.xml diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index 61a2d9ae1e..356c4285d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -25,5 +25,5 @@ public class Config { // Developing mode only - never turn on // TODO: remove fakeGlucoseData - public static final boolean fakeGlucoseData = false; + public static final boolean fakeGlucoseData = true; } diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index d3f23decb1..247ce3caea 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps; +import com.j256.ormlite.stmt.query.In; + /** * Created by mike on 07.06.2016. */ @@ -13,5 +15,7 @@ public class Constants { public static final double basalAbsoluteOnlyForCheckLimit = 10101010d; public static final Integer basalPercentOnlyForCheckLimit = 10101010; + public static final Integer notificationID = 556677; + public static final int hoursToKeepInDatabase = 24; } diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index d8d638af92..f71067c705 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -27,6 +27,8 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_treatments); + if (Config.APS) + addPreferencesFromResource(R.xml.pref_closedmode); if (Config.OPENAPSMAENABLED) addPreferencesFromResource(R.xml.pref_openapsma); if (Config.LOWSUSPEDENABLED) diff --git a/app/src/main/java/info/nightscout/androidaps/events/EventRefreshOpenLoop.java b/app/src/main/java/info/nightscout/androidaps/events/EventRefreshOpenLoop.java new file mode 100644 index 0000000000..bc33375fd3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/events/EventRefreshOpenLoop.java @@ -0,0 +1,7 @@ +package info.nightscout.androidaps.events; + +/** + * Created by mike on 25.06.2016. + */ +public class EventRefreshOpenLoop { +} diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java index 105f79e7c9..73a91065f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/ConstraintsInterface.java @@ -7,8 +7,7 @@ import info.nightscout.androidaps.plugins.APSResult; */ public interface ConstraintsInterface { - boolean isAutomaticProcessingEnabled(); - boolean manualConfirmationNeeded(); + boolean isClosedModeEnabled(); APSResult applyBasalConstraints(APSResult request); Double applyBasalConstraints(Double absoluteRate); Integer applyBasalConstraints(Integer percentRate); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java index fd3c8edc40..643e077c11 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java @@ -709,27 +709,14 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI * Constraints interface **/ @Override - public boolean isAutomaticProcessingEnabled() { + public boolean isClosedModeEnabled() { boolean result = true; ArrayList constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; if (!p.isEnabled()) continue; - result = result && constrain.isAutomaticProcessingEnabled(); - } - return result; - } - - @Override - public boolean manualConfirmationNeeded() { - boolean result = false; - - ArrayList constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS); - for (PluginBase p : constraintsPlugins) { - ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled()) continue; - result = result || constrain.manualConfirmationNeeded(); + result = result && constrain.isClosedModeEnabled(); } return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java index ccd96e0398..4dbf8414ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java @@ -2,10 +2,17 @@ package info.nightscout.androidaps.plugins.Loop; import android.app.Activity; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.app.TaskStackBuilder; +import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.support.v4.app.Fragment; +import android.support.v7.app.NotificationCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -20,11 +27,13 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Date; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventNewBG; +import info.nightscout.androidaps.events.EventRefreshOpenLoop; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface; @@ -43,8 +52,6 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug TextView constraintsProcessedView; TextView setByPumpView; - boolean confirmed; - public class LastRun implements Parcelable { public APSResult request = null; public APSResult constraintsProcessed = null; @@ -52,6 +59,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug public String source = null; public Date lastAPSRun = null; public Date lastEnact = null; + public Date lastOpenModeAccept = null; @Override public int describeContents() { @@ -65,7 +73,8 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug dest.writeParcelable(setByPump, 0); dest.writeString(source); dest.writeLong(lastAPSRun.getTime()); - dest.writeLong(lastEnact!= null ? lastEnact.getTime(): 0l); + dest.writeLong(lastEnact != null ? lastEnact.getTime() : 0l); + dest.writeLong(lastOpenModeAccept != null ? lastOpenModeAccept.getTime() : 0l); } public final Parcelable.Creator CREATOR = new Parcelable.Creator() { @@ -85,6 +94,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug source = in.readString(); lastAPSRun = new Date(in.readLong()); lastEnact = new Date(in.readLong()); + lastOpenModeAccept = new Date(in.readLong()); } public LastRun() { @@ -186,7 +196,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug public void onClick(View view) { switch (view.getId()) { case R.id.loop_run: - invoke(); + invoke(true); break; } @@ -195,22 +205,15 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug @Subscribe public void onStatusEvent(final EventTreatmentChange ev) { ConstraintsInterface constraintsInterface = MainApp.getConfigBuilder(); - if (constraintsInterface.isAutomaticProcessingEnabled()) { - invoke(); - updateGUI(); - } + invoke(true); } @Subscribe public void onStatusEvent(final EventNewBG ev) { - ConstraintsInterface constraintsInterface = MainApp.getConfigBuilder(); - if (constraintsInterface.isAutomaticProcessingEnabled()) { - invoke(); - updateGUI(); - } + invoke(true); } - private void invoke() { + public void invoke(boolean allowNotification) { ConstraintsInterface constraintsInterface = MainApp.getConfigBuilder(); PumpInterface pumpInterface = MainApp.getConfigBuilder().getActivePump(); APSResult result = null; @@ -247,39 +250,63 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug return; } - confirmed = false; - if (constraintsInterface.manualConfirmationNeeded()) { - // TODO: user notification here - confirmed = true; - } else { - confirmed = true; - } - // check rate for constrais APSResult resultAfterConstraints = result.clone(); + constraintsInterface.applyBasalConstraints(resultAfterConstraints); - if (result.changeRequested) { - constraintsInterface.applyBasalConstraints(resultAfterConstraints); - PumpEnactResult applyResult = pumpInterface.applyAPSRequest(resultAfterConstraints); - Date lastEnact = lastRun != null ? lastRun.lastEnact : new Date(0, 0, 0); - lastRun = new LastRun(); - lastRun.request = result; - lastRun.constraintsProcessed = resultAfterConstraints; - lastRun.setByPump = applyResult; - lastRun.source = ((PluginBase) usedAPS).getName(); - lastRun.lastAPSRun = new Date(); - if (applyResult.enacted) - lastRun.lastEnact = lastRun.lastAPSRun; - else - lastRun.lastEnact = lastEnact; + if (lastRun == null) lastRun = new LastRun(); + lastRun.request = result; + lastRun.constraintsProcessed = resultAfterConstraints; + lastRun.lastAPSRun = new Date(); + lastRun.source = usedAPS != null ? ((PluginBase) usedAPS).getName() : ""; + lastRun.setByPump = null; + + if (constraintsInterface.isClosedModeEnabled()) { + if (result.changeRequested) { + PumpEnactResult applyResult = pumpInterface.applyAPSRequest(resultAfterConstraints); + if (applyResult.enacted) { + lastRun.setByPump = applyResult; + lastRun.lastEnact = lastRun.lastAPSRun; + } + } else { + lastRun.setByPump = null; + lastRun.source = null; + } } else { - if (lastRun == null) lastRun = new LastRun(); - lastRun.request = result; - lastRun.constraintsProcessed = resultAfterConstraints; - lastRun.setByPump = null; - lastRun.source = null; - lastRun.lastAPSRun = new Date(); + if (result.changeRequested && allowNotification) { + NotificationCompat.Builder builder = + new NotificationCompat.Builder(MainApp.instance().getApplicationContext()); + builder.setSmallIcon(R.drawable.notification_icon) + .setContentTitle(MainApp.resources.getString(R.string.openloop_newsuggestion)) + .setContentText(resultAfterConstraints.toString()) + .setAutoCancel(true) + .setPriority(Notification.PRIORITY_HIGH) + .setCategory(Notification.CATEGORY_ALARM) + .setVisibility(Notification.VISIBILITY_PUBLIC); + + // Creates an explicit intent for an Activity in your app + Intent resultIntent = new Intent(MainApp.instance().getApplicationContext(), MainActivity.class); + + // The stack builder object will contain an artificial back stack for the + // started Activity. + // This ensures that navigating backward from the Activity leads out of + // your application to the Home screen. + TaskStackBuilder stackBuilder = TaskStackBuilder.create(MainApp.instance().getApplicationContext()); + stackBuilder.addParentStack(MainActivity.class); + // Adds the Intent that starts the Activity to the top of the stack + stackBuilder.addNextIntent(resultIntent); + PendingIntent resultPendingIntent = + stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); + builder.setContentIntent(resultPendingIntent); + builder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}); + NotificationManager mNotificationManager = + (NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE); + // mId allows you to update the notification later on. + mNotificationManager.notify(Constants.notificationID, builder.build()); + MainApp.bus().post(new EventRefreshOpenLoop()); + } } + updateGUI(); MainApp.getConfigBuilder().uploadDeviceStatus(); } @@ -296,7 +323,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug setByPumpView.setText(lastRun.setByPump != null ? lastRun.setByPump.toString() : ""); sourceView.setText(lastRun.source != null ? lastRun.source.toString() : ""); lastRunView.setText(lastRun.lastAPSRun != null && lastRun.lastAPSRun.getTime() != 0 ? lastRun.lastAPSRun.toLocaleString() : ""); - lastEnactView.setText(lastRun.lastEnact!= null && lastRun.lastEnact.getTime() != 0 ? lastRun.lastEnact.toLocaleString() : ""); + lastEnactView.setText(lastRun.lastEnact != null && lastRun.lastEnact.getTime() != 0 ? lastRun.lastEnact.toLocaleString() : ""); } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java index b5fa60adf4..35e9981230 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java @@ -317,17 +317,11 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener * Constraints interface **/ @Override - public boolean isAutomaticProcessingEnabled() { + public boolean isClosedModeEnabled() { return true; // TODO: revert back //return objectives.get(3).started.getTime() > 0; } - @Override - public boolean manualConfirmationNeeded() { - return false; // TODO: revert back - //return objectives.get(3).started.getTime() < 0; - } - @Override public APSResult applyBasalConstraints(APSResult result) { return result; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 44b519347b..a51124029b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -171,9 +171,9 @@ public class WizardDialog extends DialogFragment implements OnClickListener { // Set BG if not old BgReading lastBg = MainApp.getDbHelper().lastBg(); - Double lastBgValue = lastBg.valueToUnits(units); 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()); 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 0db413d72b..3363353dc5 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 @@ -1,14 +1,15 @@ package info.nightscout.androidaps.plugins.Overview; import android.app.Activity; +import android.content.DialogInterface; import android.graphics.Color; import android.graphics.DashPathEffect; import android.graphics.Paint; import android.os.Bundle; import android.os.Handler; -import android.provider.ContactsContract; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; +import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -34,18 +35,23 @@ import java.util.Date; import java.util.Iterator; import java.util.List; +import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; -import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.events.EventNewBG; +import info.nightscout.androidaps.events.EventPreferenceChange; +import info.nightscout.androidaps.events.EventRefreshGui; +import info.nightscout.androidaps.events.EventRefreshOpenLoop; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.Loop.LoopFragment; import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTempBasalDialog; @@ -63,15 +69,18 @@ public class OverviewFragment extends Fragment implements PluginBase { TextView deltaView; TextView runningTempView; TextView iobView; + TextView apsModeView; GraphView bgGraph; LinearLayout cancelTempLayout; LinearLayout setTempLayout; + LinearLayout acceptTempLayout; Button cancelTempButton; Button treatmentButton; Button wizardButton; Button setTempButton; Button setExtenedButton; + Button acceptTempButton; boolean visibleNow = false; Handler loopHandler = new Handler(); @@ -155,6 +164,7 @@ public class OverviewFragment extends Fragment implements PluginBase { deltaView = (TextView) view.findViewById(R.id.overview_delta); runningTempView = (TextView) view.findViewById(R.id.overview_runningtemp); iobView = (TextView) view.findViewById(R.id.overview_iob); + apsModeView = (TextView) view.findViewById(R.id.overview_apsmode); bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); cancelTempButton = (Button) view.findViewById(R.id.overview_canceltemp); treatmentButton = (Button) view.findViewById(R.id.overview_treatment); @@ -164,6 +174,8 @@ public class OverviewFragment extends Fragment implements PluginBase { cancelTempButton = (Button) view.findViewById(R.id.overview_canceltemp); setTempLayout = (LinearLayout) view.findViewById(R.id.overview_settemplayout); cancelTempLayout = (LinearLayout) view.findViewById(R.id.overview_canceltemplayout); + acceptTempButton = (Button) view.findViewById(R.id.overview_accepttempbutton); + acceptTempLayout = (LinearLayout) view.findViewById(R.id.overview_accepttemplayout); treatmentButton.setOnClickListener(new View.OnClickListener() { @Override @@ -212,6 +224,34 @@ public class OverviewFragment extends Fragment implements PluginBase { } }); + acceptTempButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + MainApp.getConfigBuilder().getActiveLoop().invoke(false); + final LoopFragment.LastRun finalLastRun = MainApp.getConfigBuilder().getActiveLoop().lastRun; + if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.changeRequested) { + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setTitle(getContext().getString(R.string.dialog)); + builder.setMessage(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed); + builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + PumpEnactResult applyResult = MainApp.getConfigBuilder().getActivePump().applyAPSRequest(finalLastRun.constraintsProcessed); + if (applyResult.enacted) { + finalLastRun.setByPump = applyResult; + finalLastRun.lastEnact = new Date(); + finalLastRun.lastOpenModeAccept = new Date(); + MainApp.getConfigBuilder().uploadDeviceStatus(); + } + updateGUI(); + } + }); + builder.setNegativeButton(getContext().getString(R.string.cancel), null); + builder.show(); + } + updateGUI(); + } + }); + updateGUI(); return view; } @@ -225,6 +265,34 @@ public class OverviewFragment extends Fragment implements PluginBase { MainApp.bus().register(this); } + @Subscribe + public void onStatusEvent(final EventPreferenceChange ev) { + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + updateGUI(); + } + }); + else + log.debug("EventPreferenceChange: Activity is null"); + } + + @Subscribe + public void onStatusEvent(final EventRefreshGui ev) { + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + updateGUI(); + } + }); + else + log.debug("EventRefreshGui: Activity is null"); + } + @Subscribe public void onStatusEvent(final EventTreatmentChange ev) { Activity activity = getActivity(); @@ -267,6 +335,20 @@ public class OverviewFragment extends Fragment implements PluginBase { log.debug("EventNewBG: Activity is null"); } + @Subscribe + public void onStatusEvent(final EventRefreshOpenLoop ev) { + Activity activity = getActivity(); + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + updateGUI(); + } + }); + else + log.debug("EventNewBG: Activity is null"); + } + @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); @@ -295,6 +377,30 @@ public class OverviewFragment extends Fragment implements PluginBase { if (bgGraph == null) return; + // open loop mode + final LoopFragment.LastRun finalLastRun = MainApp.getConfigBuilder().getActiveLoop().lastRun; + if (Config.APS) { + apsModeView.setVisibility(View.VISIBLE); + if (MainApp.getConfigBuilder().isClosedModeEnabled()) + apsModeView.setText(MainApp.resources.getString(R.string.closedloop)); + else apsModeView.setText(MainApp.resources.getString(R.string.openloop)); + } else { + apsModeView.setVisibility(View.GONE); + } + + boolean showAcceptButton = true; + showAcceptButton = showAcceptButton && !MainApp.getConfigBuilder().isClosedModeEnabled(); // Open mode needed + showAcceptButton = showAcceptButton && finalLastRun != null && finalLastRun.lastAPSRun != null; // aps result must exist + showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result + showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.changeRequested; // change is requested + + if (showAcceptButton) { + acceptTempLayout.setVisibility(View.VISIBLE); + acceptTempButton.setText(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed); + } else { + acceptTempLayout.setVisibility(View.GONE); + } + // **** Temp button **** PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); @@ -379,6 +485,7 @@ public class OverviewFragment extends Fragment implements PluginBase { super(x, y); this.isTempBasal = isTempBasal; } + public boolean isTempBasal = false; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyFragment.java index 06f4342ee2..9143686875 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyFragment.java @@ -66,13 +66,10 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI * Constraints interface **/ @Override - public boolean isAutomaticProcessingEnabled() { - return true; - } - - @Override - public boolean manualConfirmationNeeded() { - return false; + public boolean isClosedModeEnabled() { + SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); + String mode = SP.getString("aps_mode", "open"); + return mode.equals("closed"); } @Override diff --git a/app/src/main/res/drawable/loopmodeborder.xml b/app/src/main/res/drawable/loopmodeborder.xml new file mode 100644 index 0000000000..86d49ae55d --- /dev/null +++ b/app/src/main/res/drawable/loopmodeborder.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index eacda11f70..548bf5c0fa 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -30,12 +30,32 @@ android:layout_marginTop="10dp" android:orientation="vertical"> - + + + + + + + + + +