AutomationPlugin:processActions and some tweaking
This commit is contained in:
parent
350e23647e
commit
5a555cdfba
|
@ -20,6 +20,8 @@ import android.widget.RelativeLayout;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -33,6 +35,7 @@ import info.nightscout.androidaps.plugins.general.automation.actions.Action;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseTriggerDialog;
|
import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseTriggerDialog;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditActionDialog;
|
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditActionDialog;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog;
|
import info.nightscout.androidaps.plugins.general.automation.dialogs.EditEventDialog;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
|
import info.nightscout.androidaps.plugins.general.automation.triggers.Trigger;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
|
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
|
||||||
|
|
||||||
|
@ -40,6 +43,8 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
|
|
||||||
@BindView(R.id.eventListView)
|
@BindView(R.id.eventListView)
|
||||||
RecyclerView mEventListView;
|
RecyclerView mEventListView;
|
||||||
|
@BindView(R.id.logView)
|
||||||
|
TextView mLogView;
|
||||||
|
|
||||||
private EventListAdapter mEventListAdapter;
|
private EventListAdapter mEventListAdapter;
|
||||||
|
|
||||||
|
@ -62,11 +67,24 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onEvent(EventAutomationUpdateGui unused) {
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateGUI() {
|
public void updateGUI() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null)
|
if (activity != null)
|
||||||
activity.runOnUiThread(() -> mEventListAdapter.notifyDataSetChanged());
|
activity.runOnUiThread(() -> {
|
||||||
|
mEventListAdapter.notifyDataSetChanged();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (String l : AutomationPlugin.getPlugin().executionLog) {
|
||||||
|
sb.append(l);
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
|
mLogView.setText(sb.toString());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.fabAddEvent)
|
@OnClick(R.id.fabAddEvent)
|
||||||
|
@ -78,7 +96,7 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
/**
|
/**
|
||||||
* RecyclerViewAdapter to display event lists.
|
* RecyclerViewAdapter to display event lists.
|
||||||
*/
|
*/
|
||||||
public static class EventListAdapter extends RecyclerView.Adapter<EventListAdapter.ViewHolder> {
|
public static class EventListAdapter extends RecyclerView.Adapter<EventListAdapter.ViewHolder> {
|
||||||
private final List<AutomationEvent> mEventList;
|
private final List<AutomationEvent> mEventList;
|
||||||
private final FragmentManager mFragmentManager;
|
private final FragmentManager mFragmentManager;
|
||||||
|
|
||||||
|
@ -97,7 +115,7 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
private void addImage(@DrawableRes int res, Context context, LinearLayout layout) {
|
private void addImage(@DrawableRes int res, Context context, LinearLayout layout) {
|
||||||
ImageView iv = new ImageView(context);
|
ImageView iv = new ImageView(context);
|
||||||
iv.setImageResource(res);
|
iv.setImageResource(res);
|
||||||
iv.setLayoutParams(new LinearLayout.LayoutParams(MainApp.dpToPx(24),MainApp.dpToPx(24)));
|
iv.setLayoutParams(new LinearLayout.LayoutParams(MainApp.dpToPx(24), MainApp.dpToPx(24)));
|
||||||
layout.addView(iv);
|
layout.addView(iv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,25 +127,25 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
|
|
||||||
// trigger icons
|
// trigger icons
|
||||||
HashSet<Integer> triggerIcons = new HashSet<>();
|
HashSet<Integer> triggerIcons = new HashSet<>();
|
||||||
TriggerConnector.fillIconSet((TriggerConnector)event.getTrigger(), triggerIcons);
|
TriggerConnector.fillIconSet((TriggerConnector) event.getTrigger(), triggerIcons);
|
||||||
for(int res : triggerIcons) {
|
for (int res : triggerIcons) {
|
||||||
addImage(res, holder.context, holder.iconLayout);
|
addImage(res, holder.context, holder.iconLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// arrow icon
|
// arrow icon
|
||||||
ImageView iv = new ImageView(holder.context);
|
ImageView iv = new ImageView(holder.context);
|
||||||
iv.setImageResource(R.drawable.ic_arrow_forward_white_24dp);
|
iv.setImageResource(R.drawable.ic_arrow_forward_white_24dp);
|
||||||
iv.setLayoutParams(new LinearLayout.LayoutParams(MainApp.dpToPx(24),MainApp.dpToPx(24)));
|
iv.setLayoutParams(new LinearLayout.LayoutParams(MainApp.dpToPx(24), MainApp.dpToPx(24)));
|
||||||
iv.setPadding(MainApp.dpToPx(4), 0, MainApp.dpToPx(4), 0);
|
iv.setPadding(MainApp.dpToPx(4), 0, MainApp.dpToPx(4), 0);
|
||||||
holder.iconLayout.addView(iv);
|
holder.iconLayout.addView(iv);
|
||||||
|
|
||||||
// action icons
|
// action icons
|
||||||
HashSet<Integer> actionIcons = new HashSet<>();
|
HashSet<Integer> actionIcons = new HashSet<>();
|
||||||
for(Action action : event.getActions()) {
|
for (Action action : event.getActions()) {
|
||||||
if (action.icon().isPresent())
|
if (action.icon().isPresent())
|
||||||
actionIcons.add(action.icon().get());
|
actionIcons.add(action.icon().get());
|
||||||
}
|
}
|
||||||
for(int res : actionIcons) {
|
for (int res : actionIcons) {
|
||||||
addImage(res, holder.context, holder.iconLayout);
|
addImage(res, holder.context, holder.iconLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +180,7 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
eventTitle = view.findViewById(R.id.viewEventTitle);
|
eventTitle = view.findViewById(R.id.viewEventTitle);
|
||||||
rootLayout = view.findViewById(R.id.rootLayout);
|
rootLayout = view.findViewById(R.id.rootLayout);
|
||||||
iconLayout = view.findViewById(R.id.iconLayout);
|
iconLayout = view.findViewById(R.id.iconLayout);
|
||||||
iconTrash = view.findViewById(R.id.iconTrash);
|
iconTrash = view.findViewById(R.id.iconTrash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +188,7 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
/**
|
/**
|
||||||
* RecyclerViewAdapter to display action lists.
|
* RecyclerViewAdapter to display action lists.
|
||||||
*/
|
*/
|
||||||
public static class ActionListAdapter extends RecyclerView.Adapter<ActionListAdapter.ViewHolder> {
|
public static class ActionListAdapter extends RecyclerView.Adapter<ActionListAdapter.ViewHolder> {
|
||||||
private final List<Action> mActionList;
|
private final List<Action> mActionList;
|
||||||
private final FragmentManager mFragmentManager;
|
private final FragmentManager mFragmentManager;
|
||||||
|
|
||||||
|
@ -257,7 +275,7 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void build() {
|
private void build() {
|
||||||
for(int i = 0; i < mRootConnector.size(); ++i) {
|
for (int i = 0; i < mRootConnector.size(); ++i) {
|
||||||
final Trigger trigger = mRootConnector.get(i);
|
final Trigger trigger = mRootConnector.get(i);
|
||||||
|
|
||||||
// spinner
|
// spinner
|
||||||
|
@ -317,7 +335,8 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNothingSelected(AdapterView<?> parent) { }
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
|
}
|
||||||
});
|
});
|
||||||
mRootLayout.addView(spinner);
|
mRootLayout.addView(spinner);
|
||||||
}
|
}
|
||||||
|
@ -352,7 +371,7 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
dialog.show(mFragmentManager, "ChooseTriggerDialog");
|
dialog.show(mFragmentManager, "ChooseTriggerDialog");
|
||||||
dialog.setOnClickListener(newTriggerObject -> {
|
dialog.setOnClickListener(newTriggerObject -> {
|
||||||
TriggerConnector connector = trigger.getConnector();
|
TriggerConnector connector = trigger.getConnector();
|
||||||
connector.add(connector.pos(trigger)+1, newTriggerObject);
|
connector.add(connector.pos(trigger) + 1, newTriggerObject);
|
||||||
connector.simplify().rebuildView();
|
connector.simplify().rebuildView();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -363,7 +382,7 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
buttonCopy.setText("copy");
|
buttonCopy.setText("copy");
|
||||||
buttonCopy.setOnClickListener(v -> {
|
buttonCopy.setOnClickListener(v -> {
|
||||||
TriggerConnector connector = trigger.getConnector();
|
TriggerConnector connector = trigger.getConnector();
|
||||||
connector.add(connector.pos(trigger)+1, trigger.duplicate());
|
connector.add(connector.pos(trigger) + 1, trigger.duplicate());
|
||||||
connector.simplify().rebuildView();
|
connector.simplify().rebuildView();
|
||||||
});
|
});
|
||||||
buttonLayout.addView(buttonCopy);
|
buttonLayout.addView(buttonCopy);
|
||||||
|
@ -377,7 +396,7 @@ public class AutomationFragment extends SubscriberFragment {
|
||||||
TriggerConnector newConnector = new TriggerConnector(newConnectorType);
|
TriggerConnector newConnector = new TriggerConnector(newConnectorType);
|
||||||
|
|
||||||
// move trigger from pos and pos+1 into new connector
|
// move trigger from pos and pos+1 into new connector
|
||||||
for(int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
Trigger t = connector.get(pos);
|
Trigger t = connector.get(pos);
|
||||||
newConnector.add(t);
|
newConnector.add(t);
|
||||||
connector.remove(t);
|
connector.remove(t);
|
||||||
|
|
|
@ -2,10 +2,16 @@ package info.nightscout.androidaps.plugins.general.automation;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.location.Location;
|
import android.os.Handler;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -18,11 +24,21 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.actions.Action;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.services.LocationService;
|
import info.nightscout.androidaps.services.LocationService;
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
import info.nightscout.androidaps.utils.T;
|
||||||
|
|
||||||
public class AutomationPlugin extends PluginBase {
|
public class AutomationPlugin extends PluginBase {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
||||||
|
|
||||||
|
private final String key_AUTOMATION_EVENTS = "AUTOMATION_EVENTS";
|
||||||
static AutomationPlugin plugin = null;
|
static AutomationPlugin plugin = null;
|
||||||
|
|
||||||
public static AutomationPlugin getPlugin() {
|
public static AutomationPlugin getPlugin() {
|
||||||
|
@ -35,6 +51,16 @@ public class AutomationPlugin extends PluginBase {
|
||||||
private EventLocationChange eventLocationChange;
|
private EventLocationChange eventLocationChange;
|
||||||
private EventChargingState eventChargingState;
|
private EventChargingState eventChargingState;
|
||||||
private EventNetworkChange eventNetworkChange;
|
private EventNetworkChange eventNetworkChange;
|
||||||
|
List<String> executionLog = new ArrayList<>();
|
||||||
|
|
||||||
|
private Handler loopHandler = new Handler();
|
||||||
|
private Runnable refreshLoop = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
processActions();
|
||||||
|
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private AutomationPlugin() {
|
private AutomationPlugin() {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
|
@ -54,10 +80,13 @@ public class AutomationPlugin extends PluginBase {
|
||||||
|
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
loadFromSP();
|
||||||
|
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
|
loopHandler.removeCallbacks(refreshLoop);
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
context.stopService(new Intent(context, LocationService.class));
|
context.stopService(new Intent(context, LocationService.class));
|
||||||
|
|
||||||
|
@ -80,6 +109,36 @@ public class AutomationPlugin extends PluginBase {
|
||||||
return eventNetworkChange;
|
return eventNetworkChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void storeToSP() {
|
||||||
|
JSONArray array = new JSONArray();
|
||||||
|
try {
|
||||||
|
for (AutomationEvent event : getAutomationEvents()) {
|
||||||
|
array.put(new JSONObject(event.toJSON()));
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
SP.putString(key_AUTOMATION_EVENTS, array.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadFromSP() {
|
||||||
|
automationEvents.clear();
|
||||||
|
String data = SP.getString(key_AUTOMATION_EVENTS, "");
|
||||||
|
if (!data.equals("")) {
|
||||||
|
try {
|
||||||
|
JSONArray array = new JSONArray(data);
|
||||||
|
for (int i = 0; i < array.length(); i++) {
|
||||||
|
JSONObject o = array.getJSONObject(i);
|
||||||
|
AutomationEvent event = new AutomationEvent().fromJSON(o.toString());
|
||||||
|
automationEvents.add(event);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEventPreferenceChange(EventPreferenceChange e) {
|
public void onEventPreferenceChange(EventPreferenceChange e) {
|
||||||
if (e.isChanged(R.string.key_location)) {
|
if (e.isChanged(R.string.key_location)) {
|
||||||
|
@ -89,6 +148,11 @@ public class AutomationPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onEvent(EventAutomationDataChanged e) {
|
||||||
|
storeToSP();
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEventLocationChange(EventLocationChange e) {
|
public void onEventLocationChange(EventLocationChange e) {
|
||||||
eventLocationChange = e;
|
eventLocationChange = e;
|
||||||
|
@ -112,9 +176,33 @@ public class AutomationPlugin extends PluginBase {
|
||||||
processActions();
|
processActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO keepalive
|
synchronized void processActions() {
|
||||||
|
log.debug("processActions");
|
||||||
void processActions() {
|
for (AutomationEvent event : getAutomationEvents()) {
|
||||||
|
if (event.getTrigger().shouldRun()) {
|
||||||
|
List<Action> actions = event.getActions();
|
||||||
|
for (Action action : actions) {
|
||||||
|
action.doAction(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(DateUtil.timeString(DateUtil.now()));
|
||||||
|
sb.append(" ");
|
||||||
|
sb.append(result.success ? "☺" : "X");
|
||||||
|
sb.append(" ");
|
||||||
|
sb.append(event.getTitle());
|
||||||
|
sb.append(": ");
|
||||||
|
sb.append(action.shortDescription());
|
||||||
|
sb.append(": ");
|
||||||
|
sb.append(result.comment);
|
||||||
|
executionLog.add(sb.toString());
|
||||||
|
log.debug(sb.toString());
|
||||||
|
MainApp.bus().post(new EventAutomationUpdateGui());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,43 @@ import org.json.JSONObject;
|
||||||
|
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Action ideas:
|
||||||
|
|
||||||
|
* cancel temp target
|
||||||
|
* change preference setting
|
||||||
|
* enable/disable plugin
|
||||||
|
* create notification
|
||||||
|
* create ugly alarm
|
||||||
|
* create profile switch
|
||||||
|
* set/cancel tbr
|
||||||
|
* set/cancel extended bolus
|
||||||
|
* run bolus wizard
|
||||||
|
|
||||||
|
Trigger ideas:
|
||||||
|
|
||||||
|
* location (close to)
|
||||||
|
* connected to specific wifi
|
||||||
|
* internet available/not available
|
||||||
|
* nsclient connected/disconnected
|
||||||
|
* iob
|
||||||
|
* cob
|
||||||
|
* autosens value
|
||||||
|
* delta, short delta, long delta
|
||||||
|
* last bolus ago
|
||||||
|
* is tbr running
|
||||||
|
* bolus wizard result
|
||||||
|
* loop is enabled, disabled, suspended, running
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
public abstract class Action {
|
public abstract class Action {
|
||||||
|
|
||||||
public abstract int friendlyName();
|
public abstract int friendlyName();
|
||||||
|
public abstract String shortDescription();
|
||||||
|
|
||||||
abstract void doAction(Callback callback);
|
public abstract void doAction(Callback callback);
|
||||||
|
|
||||||
public void generateDialog(LinearLayout root) { }
|
public void generateDialog(LinearLayout root) { }
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,12 @@ public class ActionLoopDisable extends Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void doAction(Callback callback) {
|
public String shortDescription() {
|
||||||
|
return MainApp.gs(R.string.disableloop);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doAction(Callback callback) {
|
||||||
if (LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) {
|
if (LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) {
|
||||||
LoopPlugin.getPlugin().setPluginEnabled(PluginType.LOOP, false);
|
LoopPlugin.getPlugin().setPluginEnabled(PluginType.LOOP, false);
|
||||||
ConfigBuilderPlugin.getPlugin().storeSettings("ActionLoopDisable");
|
ConfigBuilderPlugin.getPlugin().storeSettings("ActionLoopDisable");
|
||||||
|
|
|
@ -18,7 +18,12 @@ public class ActionLoopEnable extends Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void doAction(Callback callback) {
|
public String shortDescription() {
|
||||||
|
return MainApp.gs(R.string.enableloop);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doAction(Callback callback) {
|
||||||
if (!LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) {
|
if (!LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) {
|
||||||
LoopPlugin.getPlugin().setPluginEnabled(PluginType.LOOP, true);
|
LoopPlugin.getPlugin().setPluginEnabled(PluginType.LOOP, true);
|
||||||
ConfigBuilderPlugin.getPlugin().storeSettings("ActionLoopEnable");
|
ConfigBuilderPlugin.getPlugin().storeSettings("ActionLoopEnable");
|
||||||
|
|
|
@ -18,7 +18,12 @@ public class ActionLoopResume extends Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void doAction(Callback callback) {
|
public String shortDescription() {
|
||||||
|
return MainApp.gs(R.string.resumeloop);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doAction(Callback callback) {
|
||||||
if (LoopPlugin.getPlugin().isSuspended()) {
|
if (LoopPlugin.getPlugin().isSuspended()) {
|
||||||
LoopPlugin.getPlugin().suspendTo(0);
|
LoopPlugin.getPlugin().suspendTo(0);
|
||||||
ConfigBuilderPlugin.getPlugin().storeSettings("ActionLoopResume");
|
ConfigBuilderPlugin.getPlugin().storeSettings("ActionLoopResume");
|
||||||
|
|
|
@ -21,7 +21,12 @@ public class ActionLoopSuspend extends Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void doAction(Callback callback) {
|
public String shortDescription() {
|
||||||
|
return MainApp.gs(R.string.suspendloop);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doAction(Callback callback) {
|
||||||
if (!LoopPlugin.getPlugin().isSuspended()) {
|
if (!LoopPlugin.getPlugin().isSuspended()) {
|
||||||
LoopPlugin.getPlugin().suspendLoop(minutes);
|
LoopPlugin.getPlugin().suspendLoop(minutes);
|
||||||
MainApp.bus().post(new EventRefreshOverview("ActionLoopSuspend"));
|
MainApp.bus().post(new EventRefreshOverview("ActionLoopSuspend"));
|
||||||
|
|
|
@ -26,6 +26,7 @@ public class ActionStartTempTarget extends Action {
|
||||||
String reason = "";
|
String reason = "";
|
||||||
InputBg value;
|
InputBg value;
|
||||||
InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
InputDuration duration = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
||||||
|
TempTarget tempTarget;
|
||||||
|
|
||||||
public ActionStartTempTarget() {
|
public ActionStartTempTarget() {
|
||||||
value = new InputBg(Constants.MGDL);
|
value = new InputBg(Constants.MGDL);
|
||||||
|
@ -41,8 +42,13 @@ public class ActionStartTempTarget extends Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void doAction(Callback callback) {
|
public String shortDescription() {
|
||||||
TempTarget tempTarget = new TempTarget().date(DateUtil.now()).duration((int)duration.getMinutes()).reason(reason).source(Source.USER).low(value.getMgdl()).high(value.getMgdl());
|
return MainApp.gs(R.string.resumeloop) + ": " + tempTarget.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doAction(Callback callback) {
|
||||||
|
tempTarget = new TempTarget().date(DateUtil.now()).duration((int)duration.getMinutes()).reason(reason).source(Source.USER).low(value.getMgdl()).high(value.getMgdl());
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.result(new PumpEnactResult().success(true).comment(R.string.ok)).run();
|
callback.result(new PumpEnactResult().success(true).comment(R.string.ok)).run();
|
||||||
|
|
|
@ -16,10 +16,12 @@ import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import butterknife.Unbinder;
|
import butterknife.Unbinder;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.AutomationEvent;
|
import info.nightscout.androidaps.plugins.general.automation.AutomationEvent;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.AutomationFragment;
|
import info.nightscout.androidaps.plugins.general.automation.AutomationFragment;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin;
|
import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
|
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector;
|
||||||
|
|
||||||
public class EditEventDialog extends DialogFragment {
|
public class EditEventDialog extends DialogFragment {
|
||||||
|
@ -82,6 +84,7 @@ public class EditEventDialog extends DialogFragment {
|
||||||
mAddNew = savedInstanceState.getBoolean("addNew");
|
mAddNew = savedInstanceState.getBoolean("addNew");
|
||||||
} else if (mAddNew) {
|
} else if (mAddNew) {
|
||||||
mEvent.setTrigger(new TriggerConnector(TriggerConnector.Type.OR));
|
mEvent.setTrigger(new TriggerConnector(TriggerConnector.Type.OR));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// event title
|
// event title
|
||||||
|
@ -159,6 +162,7 @@ public class EditEventDialog extends DialogFragment {
|
||||||
|
|
||||||
if (mClickListener != null) mClickListener.onClick(mEvent);
|
if (mClickListener != null) mClickListener.onClick(mEvent);
|
||||||
dismiss();
|
dismiss();
|
||||||
|
MainApp.bus().post(new EventAutomationDataChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.cancel)
|
@OnClick(R.id.cancel)
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
|
public class EventAutomationDataChanged extends Event {
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
|
public class EventAutomationUpdateGui extends Event {
|
||||||
|
}
|
|
@ -106,11 +106,19 @@ public class DateUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String timeString(Date date) {
|
public static String timeString(Date date) {
|
||||||
return new DateTime(date).toString(DateTimeFormat.shortTime());
|
String format = "hh:mma";
|
||||||
|
if (android.text.format.DateFormat.is24HourFormat(MainApp.instance())) {
|
||||||
|
format = "HH:mm";
|
||||||
|
}
|
||||||
|
return new DateTime(date).toString(DateTimeFormat.forPattern(format));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String timeString(long mills) {
|
public static String timeString(long mills) {
|
||||||
return new DateTime(mills).toString(DateTimeFormat.shortTime());
|
String format = "hh:mma";
|
||||||
|
if (android.text.format.DateFormat.is24HourFormat(MainApp.instance())) {
|
||||||
|
format = "HH:mm";
|
||||||
|
}
|
||||||
|
return new DateTime(mills).toString(DateTimeFormat.forPattern(format));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String timeFullString(long mills) {
|
public static String timeFullString(long mills) {
|
||||||
|
|
|
@ -28,6 +28,13 @@
|
||||||
android:src="@drawable/ic_add_black_24dp"
|
android:src="@drawable/ic_add_black_24dp"
|
||||||
android:backgroundTint="@color/defaulttext"/>
|
android:backgroundTint="@color/defaulttext"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/logView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:text="Log" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
|
@ -33,6 +33,11 @@ public class ActionLoopDisableTest {
|
||||||
Assert.assertEquals(R.string.disableloop, actionLoopDisable.friendlyName());
|
Assert.assertEquals(R.string.disableloop, actionLoopDisable.friendlyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shortDescriptionTest() {
|
||||||
|
Assert.assertEquals(R.string.disableloop, actionLoopDisable.friendlyName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void iconTest() {
|
public void iconTest() {
|
||||||
Assert.assertEquals(Optional.of(R.drawable.ic_stop_24dp), actionLoopDisable.icon());
|
Assert.assertEquals(Optional.of(R.drawable.ic_stop_24dp), actionLoopDisable.icon());
|
||||||
|
|
|
@ -33,6 +33,11 @@ public class ActionLoopEnableTest {
|
||||||
Assert.assertEquals(R.string.enableloop, actionLoopEnable.friendlyName());
|
Assert.assertEquals(R.string.enableloop, actionLoopEnable.friendlyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shortDescriptionTest() {
|
||||||
|
Assert.assertEquals(R.string.enableloop, actionLoopEnable.friendlyName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void iconTest() {
|
public void iconTest() {
|
||||||
Assert.assertEquals(Optional.of(R.drawable.ic_play_circle_outline_24dp), actionLoopEnable.icon());
|
Assert.assertEquals(Optional.of(R.drawable.ic_play_circle_outline_24dp), actionLoopEnable.icon());
|
||||||
|
|
|
@ -30,6 +30,11 @@ public class ActionLoopResumeTest {
|
||||||
Assert.assertEquals(R.string.resumeloop, actionLoopResume.friendlyName());
|
Assert.assertEquals(R.string.resumeloop, actionLoopResume.friendlyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shortDescriptionTest() {
|
||||||
|
Assert.assertEquals(R.string.resumeloop, actionLoopResume.friendlyName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void iconTest() {
|
public void iconTest() {
|
||||||
Assert.assertEquals(Optional.of(R.drawable.ic_replay_24dp), actionLoopResume.icon());
|
Assert.assertEquals(Optional.of(R.drawable.ic_replay_24dp), actionLoopResume.icon());
|
||||||
|
|
|
@ -34,6 +34,11 @@ public class ActionLoopSuspendTest {
|
||||||
Assert.assertEquals(R.string.suspendloop, actionLoopSuspend.friendlyName());
|
Assert.assertEquals(R.string.suspendloop, actionLoopSuspend.friendlyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shortDescriptionTest() {
|
||||||
|
Assert.assertEquals(R.string.suspendloop, actionLoopSuspend.friendlyName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void iconTest() {
|
public void iconTest() {
|
||||||
Assert.assertEquals(Optional.of(R.drawable.ic_pause_circle_outline_24dp), actionLoopSuspend.icon());
|
Assert.assertEquals(Optional.of(R.drawable.ic_pause_circle_outline_24dp), actionLoopSuspend.icon());
|
||||||
|
|
|
@ -41,6 +41,11 @@ public class ActionStartTempTargetTest {
|
||||||
Assert.assertEquals(R.string.starttemptarget, actionStartTempTarget.friendlyName());
|
Assert.assertEquals(R.string.starttemptarget, actionStartTempTarget.friendlyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shortDescriptionTest() {
|
||||||
|
Assert.assertEquals(R.string.starttemptarget, actionStartTempTarget.friendlyName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void iconTest() {
|
public void iconTest() {
|
||||||
Assert.assertEquals(Optional.of(R.drawable.icon_cp_cgm_target), actionStartTempTarget.icon());
|
Assert.assertEquals(Optional.of(R.drawable.icon_cp_cgm_target), actionStartTempTarget.icon());
|
||||||
|
|
|
@ -22,7 +22,12 @@ public class ActionTest extends Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void doAction(Callback callback) {
|
public String shortDescription() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doAction(Callback callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue