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 976ac5c607..7e8f2ef181 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -2,9 +2,13 @@ package info.nightscout.androidaps.interfaces; import org.json.JSONObject; +import java.util.List; + import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; /** * Created by mike on 04.06.2016. @@ -61,4 +65,9 @@ public interface PumpInterface { PumpEnactResult loadTDDs(); + + List getCustomActions(); + + void executeCustomAction(CustomActionType customActionType); + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java index 7ee7cf0348..91bbccc515 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java @@ -34,6 +34,7 @@ import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventNewBG; +import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginBase; @@ -175,6 +176,14 @@ public class LoopPlugin extends PluginBase { return loopSuspendedTill; } + @Subscribe + public void onStatusEvent(final EventTempTargetChange ev) { + new Thread(() -> invoke("EventTempTargetChange", true)).start(); + FabricPrivacy.getInstance().logCustom(new CustomEvent("TT_Loop_Run")); + } + + + public void suspendTo(long endTime) { loopSuspendedTill = endTime; isSuperBolus = false; 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 c456a626e7..b374c78413 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 @@ -42,6 +42,7 @@ import info.nightscout.androidaps.interfaces.SensitivityInterface; import info.nightscout.androidaps.plugins.common.SubscriberFragment; import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin; import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; + import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin; import info.nightscout.androidaps.utils.FabricPrivacy; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java index a0b6e2c1e6..02ff6e6b5c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.java @@ -3,16 +3,23 @@ package info.nightscout.androidaps.plugins.general.actions; import android.app.Activity; import android.content.Intent; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import com.crashlytics.android.answers.CustomEvent; import com.squareup.otto.Subscribe; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import info.nightscout.androidaps.Config; import info.nightscout.androidaps.activities.HistoryBrowseActivity; import info.nightscout.androidaps.MainApp; @@ -25,19 +32,22 @@ import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; import info.nightscout.androidaps.plugins.general.actions.dialogs.FillDialog; import info.nightscout.androidaps.plugins.general.actions.dialogs.NewExtendedBolusDialog; import info.nightscout.androidaps.plugins.general.actions.dialogs.NewTempBasalDialog; import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment; import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow; -import info.nightscout.androidaps.plugins.common.SubscriberFragment; -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.SingleClickButton; + /** * A simple {@link Fragment} subclass. */ @@ -49,6 +59,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL return actionsPlugin; } + View actionsFragmentView; SingleClickButton profileSwitch; SingleClickButton tempTarget; SingleClickButton extendedBolus; @@ -59,6 +70,9 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL SingleClickButton tddStats; SingleClickButton history; + private Map pumpCustomActions = new HashMap<>(); + private List pumpCustomButtons = new ArrayList<>(); + public ActionsFragment() { super(); } @@ -90,6 +104,8 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL history.setOnClickListener(this); tddStats.setOnClickListener(this); + actionsFragmentView = view; + updateGUI(); return view; } catch (Exception e) { @@ -192,13 +208,87 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL else tempTarget.setVisibility(View.VISIBLE); - if (!ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().supportsTDDs) tddStats.setVisibility(View.GONE); - else tddStats.setVisibility(View.VISIBLE); + if (!pump.getPumpDescription().supportsTDDs) + tddStats.setVisibility(View.GONE); + else + tddStats.setVisibility(View.VISIBLE); + + checkPumpCustomActions(); + } }); } + View.OnClickListener pumpCustomActionsListener = v -> { + + SingleClickButton btn = (SingleClickButton)v; + + CustomAction customAction = this.pumpCustomActions.get(btn.getText().toString()); + + ConfigBuilderPlugin.getPlugin().getActivePump().executeCustomAction(customAction.getCustomActionType()); + + }; + + + private void checkPumpCustomActions() { + + PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump(); + + removePumpCustomActions(); + + if (activePump == null) { + return; + } + + List customActions = activePump.getCustomActions(); + + if (customActions != null && customActions.size()>0) { + + LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout); + + for (CustomAction customAction : customActions) { + + SingleClickButton btn = new SingleClickButton(getContext(), null, android.R.attr.buttonStyle); + btn.setText(MainApp.gs(customAction.getName())); + + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f); + layoutParams.setMargins(20, 8, 20, 8); // 10,3,10,3 + + btn.setLayoutParams(layoutParams); + btn.setOnClickListener(pumpCustomActionsListener); + + Drawable top = getResources().getDrawable(customAction.getIconResourceId()); + btn.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null); + + ll.addView(btn); + + this.pumpCustomActions.put(MainApp.gs(customAction.getName()), customAction); + this.pumpCustomButtons.add(btn); + + } + } + + } + + + private void removePumpCustomActions() { + + if (pumpCustomActions.size()==0) + return; + + LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout); + + for (SingleClickButton customButton : pumpCustomButtons) { + ll.removeView(customButton); + } + + pumpCustomButtons.clear(); + pumpCustomActions.clear(); + } + + @Override public void onClick(View view) { FragmentManager manager = getFragmentManager(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java new file mode 100644 index 0000000000..e5e119baad --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomAction.java @@ -0,0 +1,47 @@ +package info.nightscout.androidaps.plugins.general.actions.defs; + +import info.nightscout.androidaps.R; + +/** + * Created by andy on 9/20/18. + */ + +public class CustomAction { + + private int name; + private String iconName; + private CustomActionType customActionType; + private int iconResourceId; + + + public CustomAction(int nameResourceId, CustomActionType actionType) { + this.name = nameResourceId; + this.customActionType = actionType; + this.iconResourceId = R.drawable.icon_actions_profileswitch; + } + + public CustomAction(int nameResourceId, CustomActionType actionType, int iconResourceId) { + this.name = nameResourceId; + this.customActionType = actionType; + this.iconResourceId = iconResourceId; + } + + + public int getName() { + + return name; + } + + + + + public CustomActionType getCustomActionType() { + + return customActionType; + } + + + public int getIconResourceId() { + return iconResourceId; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomActionType.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomActionType.java new file mode 100644 index 0000000000..74ecf3c0e3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/defs/CustomActionType.java @@ -0,0 +1,11 @@ +package info.nightscout.androidaps.plugins.general.actions.defs; + +/** + * Created by andy on 9/20/18. + */ + +public interface CustomActionType { + + String getKey(); + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java index 2a5f76c686..e27f27c26f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java @@ -41,6 +41,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.MidnightTime; import info.nightscout.androidaps.utils.Profiler; import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; import static info.nightscout.androidaps.utils.DateUtil.now; import static java.util.Calendar.MINUTE; @@ -61,7 +62,7 @@ public class IobCobOref1Thread extends Thread { private PowerManager.WakeLock mWakeLock; - public IobCobOref1Thread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { + IobCobOref1Thread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { super(); this.iobCobCalculatorPlugin = plugin; @@ -72,13 +73,15 @@ public class IobCobOref1Thread extends Thread { this.end = end; PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE); - mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread"); + if (powerManager != null) + mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MainApp.gs(R.string.app_name) + ":iobCobThread"); } @Override public final void run() { long start = DateUtil.now(); - mWakeLock.acquire(); + if (mWakeLock != null) + mWakeLock.acquire(T.mins(10).msecs()); try { if (L.isEnabled(L.AUTOSENS)) log.debug("AUTOSENSDATA thread started: " + from); @@ -173,7 +176,7 @@ public class IobCobOref1Thread extends Thread { double bgi = -iob.activity * sens * 5; double deviation = delta - bgi; - double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000; + double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000d; double slopeFromMaxDeviation = 0; double slopeFromMinDeviation = 999; @@ -394,7 +397,8 @@ public class IobCobOref1Thread extends Thread { MainApp.bus().post(new EventAutosensCalculationFinished(cause)); }).start(); } finally { - mWakeLock.release(); + if (mWakeLock != null) + mWakeLock.release(); MainApp.bus().post(new EventIobCalculationProgress("")); if (L.isEnabled(L.AUTOSENS)) { log.debug("AUTOSENSDATA thread ended: " + from); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java index 89bc0a6606..2970f07aca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java @@ -41,6 +41,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.MidnightTime; import info.nightscout.androidaps.utils.Profiler; import info.nightscout.androidaps.utils.SP; +import info.nightscout.androidaps.utils.T; import static info.nightscout.androidaps.utils.DateUtil.now; @@ -60,7 +61,7 @@ public class IobCobThread extends Thread { private PowerManager.WakeLock mWakeLock; - public IobCobThread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { + IobCobThread(IobCobCalculatorPlugin plugin, String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) { super(); this.iobCobCalculatorPlugin = plugin; @@ -71,13 +72,15 @@ public class IobCobThread extends Thread { this.end = end; PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE); - mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread"); + if (powerManager != null) + mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MainApp.gs(R.string.app_name) + ":iobCobThread"); } @Override public final void run() { long start = DateUtil.now(); - mWakeLock.acquire(); + if (mWakeLock != null) + mWakeLock.acquire(T.mins(10).msecs()); try { if (L.isEnabled(L.AUTOSENS)) log.debug("AUTOSENSDATA thread started: " + from); @@ -172,7 +175,7 @@ public class IobCobThread extends Thread { double bgi = -iob.activity * sens * 5; double deviation = delta - bgi; - double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000; + double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000d; double slopeFromMaxDeviation = 0; double slopeFromMinDeviation = 999; @@ -321,7 +324,8 @@ public class IobCobThread extends Thread { MainApp.bus().post(new EventAutosensCalculationFinished(cause)); }).start(); } finally { - mWakeLock.release(); + if (mWakeLock != null) + mWakeLock.release(); MainApp.bus().post(new EventIobCalculationProgress("")); if (L.isEnabled(L.AUTOSENS)) { log.debug("AUTOSENSDATA thread ended: " + from); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index c666d18699..a84e3db9a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -42,6 +42,8 @@ import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; @@ -64,7 +66,6 @@ import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.SP; - /** * Created by mike on 05.08.2016. */ @@ -1379,4 +1380,15 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint maxIob.setIfSmaller(0d, String.format(MainApp.gs(R.string.limitingmaxiob), 0d, MainApp.gs(R.string.unsafeusage)), this); return maxIob; } + + @Override + public List getCustomActions() { + return null; + } + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index dcc98bc9c0..d6f25f9c02 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -8,6 +8,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Date; +import java.util.List; import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; @@ -27,6 +28,8 @@ import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -473,4 +476,16 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte } // TODO: daily total constraint + + @Override + public List getCustomActions() { + return null; + } + + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index 681e13eb8c..d2eb132f61 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -16,6 +16,8 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; + import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -39,6 +41,8 @@ import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -813,4 +817,14 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte return loadHistory(RecordTypes.RECORD_TYPE_DAILY); } + @Override + public List getCustomActions() { + return null; + } + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java index 438142f5f1..9e3ca499d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/DanaRv2Plugin.java @@ -19,9 +19,11 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.logging.L; + import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; + import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin; import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java index 4aefd391c1..26f5180f47 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java @@ -298,4 +298,4 @@ public class LocalInsightFragment extends SubscriberFragment implements View.OnC statusItems.add(getStatusItem(label, MainApp.gs(R.string.eb_formatter, activeBolus.getRemainingAmount(), activeBolus.getInitialAmount(), activeBolus.getRemainingDuration()))); } } -} +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index 1ef940aeb9..22b329edbb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -8,6 +8,10 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; +import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.*; +import info.nightscout.androidaps.plugins.pump.insight.descriptors.*; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -69,12 +73,6 @@ import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.StartOfTBREvent; import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.TotalDailyDoseEvent; import info.nightscout.androidaps.plugins.pump.insight.app_layer.history.history_events.TubeFilledEvent; -import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfile1Block; -import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.BRProfileBlock; -import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.FactoryMinBolusAmountBlock; -import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.MaxBasalAmountBlock; -import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.MaxBolusAmountBlock; -import info.nightscout.androidaps.plugins.pump.insight.app_layer.parameter_blocks.TBROverNotificationBlock; import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.CancelBolusMessage; import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.CancelTBRMessage; import info.nightscout.androidaps.plugins.pump.insight.app_layer.remote_control.ChangeTBRMessage; @@ -98,18 +96,6 @@ import info.nightscout.androidaps.plugins.pump.insight.connection_service.Insigh import info.nightscout.androidaps.plugins.pump.insight.database.InsightBolusID; import info.nightscout.androidaps.plugins.pump.insight.database.InsightHistoryOffset; import info.nightscout.androidaps.plugins.pump.insight.database.InsightPumpID; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBasalRate; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveBolus; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.ActiveTBR; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.AlertType; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.BasalProfileBlock; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.BatteryStatus; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.BolusType; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.CartridgeStatus; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.InsightState; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.OperatingMode; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.PumpTime; -import info.nightscout.androidaps.plugins.pump.insight.descriptors.TotalDailyDose; import info.nightscout.androidaps.plugins.pump.insight.exceptions.InsightException; import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.AppLayerErrorException; import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_errors.NoActiveTBRToCanceLException; @@ -152,6 +138,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con private final Object $bolusLock = new Object[0]; private int bolusID; private boolean bolusCancelled; + private BasalProfile activeBasalProfile; private List profileBlocks; private boolean limitsFetched; private double maximumBolusAmount; @@ -345,6 +332,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } private void fetchBasalProfile() throws Exception { + activeBasalProfile = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, ActiveBRProfileBlock.class).getActiveBasalProfile(); profileBlocks = ParameterBlockUtil.readParameterBlock(connectionService, Service.CONFIGURATION, BRProfile1Block.class).getProfileBlocks(); } @@ -438,6 +426,10 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con profileBlocks.add(profileBlock); } try { + ActiveBRProfileBlock activeBRProfileBlock = new ActiveBRProfileBlock(); + activeBRProfileBlock.setActiveBasalProfile(BasalProfile.PROFILE_1); + ParameterBlockUtil.writeConfigurationBlock(connectionService, activeBRProfileBlock); + activeBasalProfile = BasalProfile.PROFILE_1; BRProfileBlock profileBlock = new BRProfile1Block(); profileBlock.setProfileBlocks(profileBlocks); ParameterBlockUtil.writeConfigurationBlock(connectionService, profileBlock); @@ -475,6 +467,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con public boolean isThisProfileSet(Profile profile) { if (!isInitialized() || profileBlocks == null) return true; if (profile.getBasalValues().length != profileBlocks.size()) return false; + if (activeBasalProfile != BasalProfile.PROFILE_1) return false; for (int i = 0; i < profileBlocks.size(); i++) { BasalProfileBlock profileBlock = profileBlocks.get(i); Profile.BasalValue basalValue = profile.getBasalValues()[i]; @@ -1068,6 +1061,16 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con return new PumpEnactResult().success(true); } + @Override + public List getCustomActions() { + return null; + } + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + private void readHistory() { try { PumpTime pumpTime = connectionService.requestMessage(new GetDateTimeMessage()).await().getPumpTime(); @@ -1566,4 +1569,4 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con Notification notification = new Notification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE, MainApp.gs(R.string.timeout_during_handshake), Notification.URGENT); new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventNewNotification(notification))); } -} +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java index b717cda71f..bdd060183b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/mdi/MDIPlugin.java @@ -5,6 +5,8 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; + import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -17,9 +19,12 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; + /** * Created by mike on 05.08.2016. */ @@ -137,14 +142,10 @@ public class MDIPlugin extends PluginBase implements PumpInterface { } @Override - public double getReservoirLevel() { - return -1; - } + public double getReservoirLevel() { return -1; } @Override - public int getBatteryLevel() { - return -1; - } + public int getBatteryLevel() { return -1; } @Override public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { @@ -249,4 +250,14 @@ public class MDIPlugin extends PluginBase implements PumpInterface { return deviceID(); } + @Override + public List getCustomActions() { + return null; + } + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.java index b03847182c..0b764f5382 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpFragment.java @@ -20,11 +20,14 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.plugins.common.SubscriberFragment; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.pump.common.defs.PumpType; import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.FabricPrivacy; + public class VirtualPumpFragment extends SubscriberFragment { private static Logger log = LoggerFactory.getLogger(VirtualPumpFragment.class); @@ -119,4 +122,6 @@ public class VirtualPumpFragment extends SubscriberFragment { } }); } + + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java index 6ede588389..e60cd78a64 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java @@ -9,6 +9,8 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.List; + import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; @@ -27,6 +29,8 @@ import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; @@ -37,6 +41,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.SP; + /** * Created by mike on 05.08.2016. */ @@ -140,6 +145,16 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return new PumpEnactResult(); } + @Override + public List getCustomActions() { + return null; + } + + @Override + public void executeCustomAction(CustomActionType customActionType) { + + } + @Override public boolean isInitialized() { return true; diff --git a/app/src/main/res/layout/actions_fragment.xml b/app/src/main/res/layout/actions_fragment.xml index d74c4b4cc2..3e809b3b02 100644 --- a/app/src/main/res/layout/actions_fragment.xml +++ b/app/src/main/res/layout/actions_fragment.xml @@ -9,6 +9,7 @@ android:layout_height="wrap_content"> diff --git a/app/src/main/res/xml/pref_insight_local.xml b/app/src/main/res/xml/pref_insight_local.xml index 19eb0e4624..4cb9fa6d18 100644 --- a/app/src/main/res/xml/pref_insight_local.xml +++ b/app/src/main/res/xml/pref_insight_local.xml @@ -1,57 +1,60 @@ - - - + - + + + - + - + - + - + - + - + - + - + + + +