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">