- 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:
parent
53389fea3b
commit
48e4a041f8
11 changed files with 266 additions and 0 deletions
|
@ -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<CustomAction> getCustomActions();
|
||||
|
||||
PumpEnactResult executeCustomAction(CustomActionType customActionType);
|
||||
|
||||
}
|
||||
|
|
|
@ -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<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
|
||||
public void onClick(View view) {
|
||||
FragmentManager manager = getFragmentManager();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package info.nightscout.androidaps.plugins.Actions.defs;
|
||||
|
||||
/**
|
||||
* Created by andy on 9/20/18.
|
||||
*/
|
||||
|
||||
public interface CustomActionType {
|
||||
|
||||
String getKey();
|
||||
|
||||
}
|
|
@ -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<CustomAction> getCustomActions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<CustomAction> getCustomActions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<CustomAction> getCustomActions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<CustomAction> getCustomActions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<CustomAction> getCustomActions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<CustomAction> getCustomActions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult executeCustomAction(CustomActionType customActionType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return true;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/action_buttons_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
|
Loading…
Reference in a new issue