- 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)
This commit is contained in:
Andy Rozman 2018-09-20 17:23:36 +01:00
parent 53389fea3b
commit 48e4a041f8
11 changed files with 266 additions and 0 deletions

View file

@ -2,9 +2,13 @@ package info.nightscout.androidaps.interfaces;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.List;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; 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. * Created by mike on 04.06.2016.
@ -57,4 +61,9 @@ public interface PumpInterface {
PumpEnactResult loadTDDs(); PumpEnactResult loadTDDs();
List<CustomAction> getCustomActions();
PumpEnactResult executeCustomAction(CustomActionType customActionType);
} }

View file

@ -9,10 +9,16 @@ import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.crashlytics.android.answers.CustomEvent; import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe; 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.Config;
import info.nightscout.androidaps.activities.HistoryBrowseActivity; import info.nightscout.androidaps.activities.HistoryBrowseActivity;
import info.nightscout.androidaps.MainApp; 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.EventRefreshOverview;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.PumpInterface; 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.FillDialog;
import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog; import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog;
import info.nightscout.androidaps.plugins.Actions.dialogs.NewTempBasalDialog; import info.nightscout.androidaps.plugins.Actions.dialogs.NewTempBasalDialog;
@ -49,6 +57,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
return actionsPlugin; return actionsPlugin;
} }
View actionsFragmentView;
SingleClickButton profileSwitch; SingleClickButton profileSwitch;
SingleClickButton tempTarget; SingleClickButton tempTarget;
SingleClickButton extendedBolus; SingleClickButton extendedBolus;
@ -90,6 +99,8 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
history.setOnClickListener(this); history.setOnClickListener(this);
tddStats.setOnClickListener(this); tddStats.setOnClickListener(this);
actionsFragmentView = view;
updateGUI(); updateGUI();
return view; return view;
} catch (Exception e) { } catch (Exception e) {
@ -194,11 +205,121 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().supportsTDDs) tddStats.setVisibility(View.GONE); if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().supportsTDDs) tddStats.setVisibility(View.GONE);
else tddStats.setVisibility(View.VISIBLE); else tddStats.setVisibility(View.VISIBLE);
checkCustomActions();
} }
}); });
} }
private String activePumpName;
private Map<String,CustomAction> currentCustomActions = new HashMap<>();
private List<SingleClickButton> 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<CustomAction> 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
// <info.nightscout.utils.SingleClickButton
// android:id="@+id/actions_profileswitch"
// style="?android:attr/buttonStyle"
// android:layout_width="fill_parent"
// android:layout_height="wrap_content"
// android:layout_marginBottom="3dp"
// android:layout_marginLeft="10dp"
// android:layout_marginRight="10dp"
// android:layout_marginTop="3dp"
// android:layout_weight="0.5"
// android:drawableTop="@drawable/icon_actions_profileswitch"
// android:text="@string/careportal_profileswitch" />
}
}
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 @Override
public void onClick(View view) { public void onClick(View view) {
FragmentManager manager = getFragmentManager(); FragmentManager manager = getFragmentManager();

View file

@ -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;
}
}

View file

@ -0,0 +1,11 @@
package info.nightscout.androidaps.plugins.Actions.defs;
/**
* Created by andy on 9/20/18.
*/
public interface CustomActionType {
String getKey();
}

View file

@ -39,6 +39,8 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; 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.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; 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); maxIob.setIfSmaller(0d, String.format(MainApp.gs(R.string.limitingmaxiob), 0d, MainApp.gs(R.string.unsafeusage)), this);
return maxIob; return maxIob;
} }
@Override
public List<CustomAction> getCustomActions() {
return null;
}
@Override
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
return null;
}
} }

View file

@ -8,6 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date; import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp; 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.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; 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.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
@ -467,4 +470,15 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
} }
// TODO: daily total constraint // TODO: daily total constraint
@Override
public List<CustomAction> getCustomActions() {
return null;
}
@Override
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
return null;
}
} }

View file

@ -16,6 +16,8 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; 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.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; 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.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; 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); return loadHistory(RecordTypes.RECORD_TYPE_DAILY);
} }
@Override
public List<CustomAction> getCustomActions() {
return null;
}
@Override
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
return null;
}
} }

View file

@ -32,6 +32,8 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; 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.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
@ -932,4 +934,14 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
return insulin; return insulin;
} }
@Override
public List<CustomAction> getCustomActions() {
return null;
}
@Override
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
return null;
}
} }

View file

@ -5,6 +5,8 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; 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.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; 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.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
@ -239,4 +243,14 @@ public class MDIPlugin extends PluginBase implements PumpInterface {
return deviceID(); return deviceID();
} }
@Override
public List<CustomAction> getCustomActions() {
return null;
}
@Override
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
return null;
}
} }

View file

@ -9,6 +9,8 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; 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.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; 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.ConfigBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
@ -140,6 +144,16 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
return new PumpEnactResult(); return new PumpEnactResult();
} }
@Override
public List<CustomAction> getCustomActions() {
return null;
}
@Override
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
return null;
}
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
return true; return true;

View file

@ -9,6 +9,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<LinearLayout <LinearLayout
android:id="@+id/action_buttons_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">