From 48e4a041f8d3bd977e510c091e9df3e29c4adbca Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Thu, 20 Sep 2018 17:23:36 +0100 Subject: [PATCH 1/8] - First changes for CustomActions - changed PumpInterface to add CustomActions - added class CustomActions and CustomActionType - changed all PumpImplementations to use new methods - started changing ActionsFragment (most should be done) --- .../androidaps/interfaces/PumpInterface.java | 9 ++ .../plugins/Actions/ActionsFragment.java | 121 ++++++++++++++++++ .../plugins/Actions/defs/CustomAction.java | 43 +++++++ .../Actions/defs/CustomActionType.java | 11 ++ .../plugins/PumpCombo/ComboPlugin.java | 13 ++ .../PumpDanaR/AbstractDanaRPlugin.java | 14 ++ .../plugins/PumpDanaRS/DanaRSPlugin.java | 14 ++ .../plugins/PumpInsight/InsightPlugin.java | 12 ++ .../androidaps/plugins/PumpMDI/MDIPlugin.java | 14 ++ .../PumpVirtual/VirtualPumpPlugin.java | 14 ++ app/src/main/res/layout/actions_fragment.xml | 1 + 11 files changed, 266 insertions(+) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Actions/defs/CustomAction.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Actions/defs/CustomActionType.java 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 614c6033d3..2f8e92dcc7 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.Actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType; /** * Created by mike on 04.06.2016. @@ -57,4 +61,9 @@ public interface PumpInterface { PumpEnactResult loadTDDs(); + + List getCustomActions(); + + PumpEnactResult executeCustomAction(CustomActionType customActionType); + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index ea17a30218..6a8422b2dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -9,10 +9,16 @@ 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,6 +31,8 @@ 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.Actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog; import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog; import info.nightscout.androidaps.plugins.Actions.dialogs.NewTempBasalDialog; @@ -49,6 +57,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL return actionsPlugin; } + View actionsFragmentView; SingleClickButton profileSwitch; SingleClickButton tempTarget; SingleClickButton extendedBolus; @@ -90,6 +99,8 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL history.setOnClickListener(this); tddStats.setOnClickListener(this); + actionsFragmentView = view; + updateGUI(); return view; } catch (Exception e) { @@ -194,11 +205,121 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().supportsTDDs) tddStats.setVisibility(View.GONE); else tddStats.setVisibility(View.VISIBLE); + + checkCustomActions(); + } }); } + private String activePumpName; + private Map currentCustomActions = new HashMap<>(); + private List customButtons = new ArrayList<>(); + + View.OnClickListener customActionsListener = v -> { + + SingleClickButton btn = (SingleClickButton)v; + + CustomAction customAction = this.currentCustomActions.get(btn.getText().toString()); + + ConfigBuilderPlugin.getActivePump().executeCustomAction(customAction.getCustomActionType()); + + }; + + + + private void checkCustomActions() { + + PumpInterface activePump = ConfigBuilderPlugin.getActivePump(); + + if (activePump==null) { + removeCustomActions(); + return; + } + + String newPump = activePump.getClass().getSimpleName(); + + if (newPump.equals(activePumpName)) + return; + + removeCustomActions(); + + // add new actions + List customActions = activePump.getCustomActions(); + + if (customActions!=null) + { + + LinearLayout ll = (LinearLayout)actionsFragmentView.findViewById(R.id.action_buttons_layout); + + for (CustomAction customAction : customActions) { + // TODO + + + SingleClickButton btn = new SingleClickButton(MainApp.instance().getApplicationContext()); + btn.setText(customAction.getName()); + + //btn.setTextAppearance(R.style.buttonStyle); + + + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f); + layoutParams.setMargins(10, 3, 10, 3); + + btn.setLayoutParams(layoutParams); + btn.setOnClickListener(customActionsListener); + + + ll.addView(btn); + + this.currentCustomActions.put(customAction.getName(), customAction); + this.customButtons.add(btn); + + + // TODO add to map + + +// + + + + + + } + } + + activePumpName = newPump; + } + + private void removeCustomActions() { + + if (currentCustomActions.size()==0) + return; + + LinearLayout ll = (LinearLayout)actionsFragmentView.findViewById(R.id.action_buttons_layout); + + for (SingleClickButton customButton : customButtons) { + ll.removeView(customButton); + } + + customButtons.clear(); + currentCustomActions.clear(); + } + + @Override public void onClick(View view) { FragmentManager manager = getFragmentManager(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/defs/CustomAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/defs/CustomAction.java new file mode 100644 index 0000000000..f32959cc33 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/defs/CustomAction.java @@ -0,0 +1,43 @@ +package info.nightscout.androidaps.plugins.Actions.defs; + +/** + * Created by andy on 9/20/18. + */ + +public class CustomAction { + + private String name; + private String iconName; + private CustomActionType customActionType; + + + public String getName() { + + return name; + } + + public void setName(String name) { + + this.name = name; + } + + public String getIconName() { + + return iconName; + } + + public void setIconName(String iconName) { + + this.iconName = iconName; + } + + public CustomActionType getCustomActionType() { + + return customActionType; + } + + public void setCustomActionType(CustomActionType customActionType) { + + this.customActionType = customActionType; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/defs/CustomActionType.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/defs/CustomActionType.java new file mode 100644 index 0000000000..640371bf9c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/defs/CustomActionType.java @@ -0,0 +1,11 @@ +package info.nightscout.androidaps.plugins.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/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index f6f1de2ad0..54d6a6d621 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -39,6 +39,8 @@ 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.Actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; @@ -1374,4 +1376,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 PumpEnactResult executeCustomAction(CustomActionType customActionType) { + return null; + } + } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java index c50e635eb8..31cb635fec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/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.Actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; @@ -467,4 +470,15 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte } // TODO: daily total constraint + + @Override + public List getCustomActions() { + return null; + } + + @Override + public PumpEnactResult executeCustomAction(CustomActionType customActionType) { + return null; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index e3c8f9de94..9610a07e75 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/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; @@ -36,6 +38,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.Actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; @@ -806,4 +810,14 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte return loadHistory(RecordTypes.RECORD_TYPE_DAILY); } + @Override + public List getCustomActions() { + return null; + } + + @Override + public PumpEnactResult executeCustomAction(CustomActionType customActionType) { + return null; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java index c72da31fdf..b1ac8a065b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java @@ -32,6 +32,8 @@ 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.Actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; @@ -932,4 +934,14 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai return insulin; } + @Override + public List getCustomActions() { + return null; + } + + @Override + public PumpEnactResult executeCustomAction(CustomActionType customActionType) { + return null; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java index 27651a7cfb..b40c40acca 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/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,6 +19,8 @@ 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.Actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; @@ -239,4 +243,14 @@ public class MDIPlugin extends PluginBase implements PumpInterface { return deviceID(); } + @Override + public List getCustomActions() { + return null; + } + + @Override + public PumpEnactResult executeCustomAction(CustomActionType customActionType) { + return null; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index a21b1ca22b..670ee2397b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/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; @@ -26,6 +28,8 @@ 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.Actions.defs.CustomAction; +import info.nightscout.androidaps.plugins.Actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; @@ -140,6 +144,16 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { return new PumpEnactResult(); } + @Override + public List getCustomActions() { + return null; + } + + @Override + public PumpEnactResult executeCustomAction(CustomActionType customActionType) { + return null; + } + @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 3b322b26dd..04f2a9e5d3 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"> From e2ddb484983d44b1cf500e8ae258ee1ab14f3c2a Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Thu, 20 Sep 2018 18:04:06 +0100 Subject: [PATCH 2/8] Some extension on VirtualPump for testing. --- .../plugins/Actions/ActionsFragment.java | 9 +++--- .../plugins/Actions/defs/CustomAction.java | 16 ++++++---- .../PumpVirtual/VirtualPumpFragment.java | 30 +++++++++++++++++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index 6a8422b2dd..dd48054738 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -254,15 +254,15 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL LinearLayout ll = (LinearLayout)actionsFragmentView.findViewById(R.id.action_buttons_layout); for (CustomAction customAction : customActions) { - // TODO - SingleClickButton btn = new SingleClickButton(MainApp.instance().getApplicationContext()); - btn.setText(customAction.getName()); + btn.setText(MainApp.gs(customAction.getName())); + // TODO style and drawableTop //btn.setTextAppearance(R.style.buttonStyle); + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f); layoutParams.setMargins(10, 3, 10, 3); @@ -273,11 +273,10 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL ll.addView(btn); - this.currentCustomActions.put(customAction.getName(), customAction); + this.currentCustomActions.put(MainApp.gs(customAction.getName()), customAction); this.customButtons.add(btn); - // TODO add to map // Date: Wed, 20 Feb 2019 22:57:31 +0000 Subject: [PATCH 3/8] First implementation --- .../androidaps/interfaces/PumpInterface.java | 2 +- .../plugins/Actions/ActionsFragment.java | 93 +++++++------------ .../plugins/PumpCombo/ComboPlugin.java | 4 +- .../PumpDanaR/AbstractDanaRPlugin.java | 5 +- .../plugins/PumpDanaRS/DanaRSPlugin.java | 4 +- .../plugins/PumpInsight/InsightPlugin.java | 4 +- .../androidaps/plugins/PumpMDI/MDIPlugin.java | 4 +- .../PumpVirtual/VirtualPumpPlugin.java | 4 +- 8 files changed, 45 insertions(+), 75 deletions(-) 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 2f8e92dcc7..777ae113c4 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -64,6 +64,6 @@ public interface PumpInterface { List getCustomActions(); - PumpEnactResult executeCustomAction(CustomActionType customActionType); + void executeCustomAction(CustomActionType customActionType); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index dd48054738..69fd805dec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.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; @@ -68,6 +69,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(); } @@ -203,119 +207,84 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL else tempTarget.setVisibility(View.VISIBLE); - if (!ConfigBuilderPlugin.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); - checkCustomActions(); + checkPumpCustomActions(); } }); } - private String activePumpName; - private Map currentCustomActions = new HashMap<>(); - private List customButtons = new ArrayList<>(); - - View.OnClickListener customActionsListener = v -> { + View.OnClickListener pumpCustomActionsListener = v -> { SingleClickButton btn = (SingleClickButton)v; - CustomAction customAction = this.currentCustomActions.get(btn.getText().toString()); + CustomAction customAction = this.pumpCustomActions.get(btn.getText().toString()); ConfigBuilderPlugin.getActivePump().executeCustomAction(customAction.getCustomActionType()); }; + private void checkPumpCustomActions() { - private void checkCustomActions() { + PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump(); - PumpInterface activePump = ConfigBuilderPlugin.getActivePump(); + removePumpCustomActions(); - if (activePump==null) { - removeCustomActions(); + if (activePump == null) { return; } - String newPump = activePump.getClass().getSimpleName(); - - if (newPump.equals(activePumpName)) - return; - - removeCustomActions(); - - // add new actions List customActions = activePump.getCustomActions(); - if (customActions!=null) - { + if (customActions != null && customActions.size()>0) { - LinearLayout ll = (LinearLayout)actionsFragmentView.findViewById(R.id.action_buttons_layout); + LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout); for (CustomAction customAction : customActions) { - SingleClickButton btn = new SingleClickButton(MainApp.instance().getApplicationContext()); + SingleClickButton btn = new SingleClickButton(getContext(), null, android.R.attr.buttonStyle); btn.setText(MainApp.gs(customAction.getName())); - // TODO style and drawableTop - //btn.setTextAppearance(R.style.buttonStyle); - - - LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f); - layoutParams.setMargins(10, 3, 10, 3); + layoutParams.setMargins(20, 8, 20, 8); // 10,3,10,3 btn.setLayoutParams(layoutParams); - btn.setOnClickListener(customActionsListener); + btn.setOnClickListener(pumpCustomActionsListener); + Drawable top = getResources().getDrawable(R.drawable.icon_actions_profileswitch); + btn.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null); ll.addView(btn); - this.currentCustomActions.put(MainApp.gs(customAction.getName()), customAction); - this.customButtons.add(btn); - - - - -// - - - - + this.pumpCustomActions.put(MainApp.gs(customAction.getName()), customAction); + this.pumpCustomButtons.add(btn); } } - activePumpName = newPump; } - private void removeCustomActions() { - if (currentCustomActions.size()==0) + private void removePumpCustomActions() { + + if (pumpCustomActions.size()==0) return; - LinearLayout ll = (LinearLayout)actionsFragmentView.findViewById(R.id.action_buttons_layout); + LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout); - for (SingleClickButton customButton : customButtons) { + for (SingleClickButton customButton : pumpCustomButtons) { ll.removeView(customButton); } - customButtons.clear(); - currentCustomActions.clear(); + pumpCustomButtons.clear(); + pumpCustomActions.clear(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 54d6a6d621..34882bc14c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -1383,8 +1383,8 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint } @Override - public PumpEnactResult executeCustomAction(CustomActionType customActionType) { - return null; + public void executeCustomAction(CustomActionType customActionType) { + } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java index 31cb635fec..d293dab80c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java @@ -476,9 +476,10 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte return null; } + @Override - public PumpEnactResult executeCustomAction(CustomActionType customActionType) { - return null; + public void executeCustomAction(CustomActionType customActionType) { + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index 9610a07e75..76adba94d8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -816,8 +816,8 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte } @Override - public PumpEnactResult executeCustomAction(CustomActionType customActionType) { - return null; + public void executeCustomAction(CustomActionType customActionType) { + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java index b1ac8a065b..387b66791d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java @@ -940,8 +940,8 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai } @Override - public PumpEnactResult executeCustomAction(CustomActionType customActionType) { - return null; + public void executeCustomAction(CustomActionType customActionType) { + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java index b40c40acca..0d9260837c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java @@ -249,8 +249,8 @@ public class MDIPlugin extends PluginBase implements PumpInterface { } @Override - public PumpEnactResult executeCustomAction(CustomActionType customActionType) { - return null; + public void executeCustomAction(CustomActionType customActionType) { + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index 670ee2397b..9eabfd0cac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -150,8 +150,8 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { } @Override - public PumpEnactResult executeCustomAction(CustomActionType customActionType) { - return null; + public void executeCustomAction(CustomActionType customActionType) { + } @Override From 605601bcc643ce7da3b39ec09411d4a0aca8c0c8 Mon Sep 17 00:00:00 2001 From: harisp Date: Wed, 6 Mar 2019 12:10:28 +0100 Subject: [PATCH 4/8] Run loop when TemporyTarget is changed --- .../androidaps/plugins/aps/loop/LoopPlugin.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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..3296d3d9d5 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(() -> LoopPlugin.getPlugin().invoke("EventTempTargetChange", true)).start(); + FabricPrivacy.getInstance().logCustom(new CustomEvent("TT_Loop_Run")); + } + + + public void suspendTo(long endTime) { loopSuspendedTill = endTime; isSuperBolus = false; From 286be1e78f6a3428b748c30ffc20f9d05771033a Mon Sep 17 00:00:00 2001 From: Tebbe Ubben Date: Thu, 7 Mar 2019 15:22:51 +0100 Subject: [PATCH 5/8] Insight: Enforce using first profile --- .../pump/insight/LocalInsightPlugin.java | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) 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..113d14e943 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,8 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; +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 +71,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 +94,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 +136,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 +330,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 +424,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 +465,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]; From 9524818c4d3baa17855e297a4eee330a757cbb6a Mon Sep 17 00:00:00 2001 From: Tebbe Ubben Date: Thu, 7 Mar 2019 15:25:29 +0100 Subject: [PATCH 6/8] Headline for Insight related settings --- app/src/main/res/xml/pref_insight_local.xml | 93 +++++++++++---------- 1 file changed, 48 insertions(+), 45 deletions(-) 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 @@ - - - + - + + + - + - + - + - + - + - + - + - + + + + From 537c241e76180e4a40f5f50cf52382c27812e5bc Mon Sep 17 00:00:00 2001 From: harispoljo <34479922+harispoljo@users.noreply.github.com> Date: Thu, 7 Mar 2019 16:33:36 +0100 Subject: [PATCH 7/8] Made the intent easier to read. --- .../info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3296d3d9d5..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 @@ -178,7 +178,7 @@ public class LoopPlugin extends PluginBase { @Subscribe public void onStatusEvent(final EventTempTargetChange ev) { - new Thread(() -> LoopPlugin.getPlugin().invoke("EventTempTargetChange", true)).start(); + new Thread(() -> invoke("EventTempTargetChange", true)).start(); FabricPrivacy.getInstance().logCustom(new CustomEvent("TT_Loop_Run")); } From f6d85bdd961c448083c06af5301f56dc46554fbd Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 12 Mar 2019 11:31:21 +0100 Subject: [PATCH 8/8] correct wakelock in iob calculation --- .../iob/iobCobCalculator/IobCobOref1Thread.java | 14 +++++++++----- .../plugins/iob/iobCobCalculator/IobCobThread.java | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) 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);